LuCI auto refresh


I am working a custom page for the LuCI webinterface. With the code below, some simple information are displayed on the page. The information are fetched from a uci call. But if the information in the UCI is changed, the page are not automaticly updated, which i would like it to be.

Is there are way for the page to be auto refresh, so it pulls the new UCI information with a specific interval?

There may come some ubus call for fetching information for the page further on in the development.


-- File: /usr/lib/lua/luci/controller/modem.lua

module("luci.controller.modem", package.seeall)

function index()
    if not nixio.fs.access("/etc/config/modem") then

    entry({"admin", "modem"}, alias("admin", "modem", "general"), translate("5G Modem Status"), 70).index = true
    entry({"admin", "modem", "general"}, cbi("modem"), translate("General Settings"), 10).leaf = true


-- File: /usr/lib/lua/luci/model/cbi/modem.lua

local fs = require "nixio.fs"
local uci = require "luci.model.uci".cursor()

local m, s, o

m = Map("modem", translate("5G Modem Status"), translate("Here you can view the status of your 5G modem."))
m.apply_on_parse = true

s = m:section(NamedSection, "general", "modem", translate("General Settings"))
s.anonymous = true

-- Read values from /tmp/modem.txt
local modem_values = {}
local modem_file = "/tmp/modem.txt"
if fs.access(modem_file) then
    for line in io.lines(modem_file) do
        local key, value = line:match("([^=]+)=([^=]+)")
        if key and value then
            modem_values[key] = value

-- Display Carrier value
o = s:option(Value, "carrier", translate("Carrier"))
o.default = modem_values["Carrier"] or "Unknown"
o.inputstyle = "width: 100%; border: none; box-shadow: none; padding: 0;"

-- Display RSSI value
o = s:option(Value, "rssi", translate("RSSI"))
o.default = modem_values["RSSI"] or "Unknown"
o.inputstyle = "width: 100%; border: none; box-shadow: none; padding: 0;"

-- Display SNR value
o = s:option(Value, "snr", translate("SNR"))
o.default = modem_values["SNR"] or "Unknown"
o.inputstyle = "width: 100%; border: none; box-shadow: none; padding: 0;"

-- Add Reconnect button
o = s:option(Button, "_reconnect", translate("Reconnect"))
o.inputstyle = "width: 100%; border: none; box-shadow: none; padding: 0;"
o.write = function()

return m

  1. Lua in Luci is deprecated, use JavaScript instead. It should be not so difficult to migrate.
  2. Who is going to change UCI config if a user sees the page?
  3. You may need ubus notify and monitor
  4. In JS app the refresh is made by a poll function, check luci-app-minidlna or other apps that do the polling.

1 - I dont know JavaScript, and i has hoping that i didnt have to swtich over to it. But if that is the right way to go, i may have too.

2 - We have some custom lua script running in the background, which can update some UCI values. But i will say that the main way of getting data is from Ubus call.

4 - Could you point out there in the luci-app-minidlna the poll function is being used?

Thanks for the help.

Sorry, not minidlna but luci-app-upnp
Here is how it's used:

You need to do 'require poll'; at top of the file.
But this is for the JS based apps, I don't know how to use it with Lua.
Maybe you can just add some setInterval() call or use widnow.location.refresh().
Sounds like not a trivial thing.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.