[Luci] Display a custom field

I'm trying to display the serial number of my device on the status/overview page.
On the console, I can display the SN with:

  • i2cdump, piped with a grep and a awk
  • cat /etc/config/myfile, piped with a grep and a awk
  • uci get mysection.SerialNumber
  • ubus call uci get '{"config": "mysection"}', piped with a grep and a awk

For the display I choose to duplicate the file modules/luci-mod-status/htdocs/luci-static/resources/view/status/include/10_system.js on my router and rename it 80_myfile.js

I tried to mimic the existing method of the other fields but my limited skills in JS prevent me from displaying my SN.
I tried to read the file /etc/config/myfile, fs.lines('/etc/config/myfile') nothing is displaid.
With fs.exec('/usr/sbin/i2cdump') or fs.exec_direct('/usr/sbin/i2cdump') the whole section is skipped
with L.resolveDefault(callSeriaNumberInfo(), 'Error reading SN'), and

var callSeriaNumberInfo= rpc.declare({
	object: 'mysection'

I always get Error reading SN

Can anyone guide me on how to display this SN on the status page?

I don't now if this works, I wrote on fast. You must try.


thanks for the help. The new section is displaid but the field stay empty. Is there not a link missing between the lua script and the js?
when looking at I have this answer:

/usr/lib/lua/luci/controller/usersn.lua:13: attempt to index global 'uci' (a nil value)
stack traceback:
	/usr/lib/lua/luci/controller/usersn.lua:13: in function </usr/lib/lua/luci/controller/usersn.lua:11>

Lua shows where the error is in the function (lua/luci/controller/usersn.lua)

function sndisplay()
	local snslot = { }
	local snum = tostring(uci:get("mysection", "SerialNumber"))
	snslot["sn"] = snum


local snum = tostring(uci:get("mysection", "SerialNumber"))
`uci get mysection.SerialNumber`

The command return any value?
I fixed the old function, but it won't help much if don't know the file, the data you need to read.

I applied the modification at line 13 but still the same error.
The command return the rigth value in the console.
To set the SN in the UCI base, I have created the file /etc/config/mysection, then in the file /etc/uci-default/83_SetSerialNumber I set the SN once at installation/factory reset.

. /lib/functions.sh

reg=`i2cdump -y -r 0x0-0xc 0 0x50|grep NK|awk '{print $15}'`

SERIALNUMBER=`echo -e $SERIALNUMBER | awk '{printf "%s\n", $_}'`

if [ -n "$SERIALNUMBER" ];
    uci set mysection.SerialNumber=$SERIALNUMBER
    uci commit mysection

command line:

uci get mysection.SerialNumber

Ok I did it differently, as easy as I could.



Nice, it works.
Thanks for your help

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