[Luci] Display a custom field

Hello,
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.

https://github.com/4IceG/Personal_data/raw/master/mysn.zip

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 http://192.168.1.1/cgi-bin/luci/admin/status/realtime/usersn 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
	luci.http.prepare_content("application/json")
	luci.http.write_json(snslot)
end

Errors

local snum = tostring(uci:get("mysection", "SerialNumber"))
luci.http.write_json(sim)
`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.

#!/bin/sh
. /lib/functions.sh

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

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

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

command line:

uci get mysection.SerialNumber
NK2E_018_2017

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

https://github.com/4IceG/Personal_data/raw/master/mysn_new.zip

3 Likes

Nice, it works.
Thanks for your help

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