[Solved] Conditionally render LuCI page

#1

I have a LuCI app which is supposed to display some signal values from a modem. Depending on whether it is LTE or 3G, I want to display the relevant metrics. For a reason I do not understand, the if access_tech == "anything" test always fails, no matter if the value is "LTE" or anything else. Even though the type of access_tech is confirmed to be a string, and the value to be "LTE", it still fails. I am not the most experienced Lua user at the moment, but I'm thinking that not all of the code is being executed. Is there some documentation on the flow of control in a LuCI app so I can debug it?

	if access_tech == "LTE" then
	        signal_info = signal_header ..  msg_rssi .. msg_rsrq .. msg_rsrp .. msg_snr .. msg_percent
	    else
	        signal_info = signal_header ..  msg_rssi .. msg_rscp .. msg_ecio .. msg_percent
	end

Here is where those values in the signal_info are coming from:

        -- dump ModemManager mmcli output into RAM
        local modemsignal = luci.sys.exec("mmcli -m 0 --signal-get > /tmp/modemsignal")
        
        -- extract signal metrics from ModemManager output using grep and sed
        local access_tech   = string.upper(luci.sys.exec("cat /tmp/modemstatus | grep access | sed 's/.*: //' | tr -d \"'\""))
        local mobile_rssi = luci.sys.exec("cat /tmp/modemsignal | grep 'RSSI' | sed 's/.*: //' | tr -d \"'\"")
        local mobile_rsrq = luci.sys.exec("cat /tmp/modemsignal | grep 'RSRQ' | sed 's/.*: //' | tr -d \"'\"")
        local mobile_rsrp = luci.sys.exec("cat /tmp/modemsignal | grep 'RSRP' | sed 's/.*: //' | tr -d \"'\"")
        local mobile_snr = luci.sys.exec("cat /tmp/modemsignal | grep 'S/N' | sed 's/.*: //' | tr -d \"'\"")
        local mobile_rscp = luci.sys.exec("cat /tmp/modemsignal | grep 'RSCP' | sed 's/.*: //' | tr -d \"'\"")
        local mobile_ecio = luci.sys.exec("cat /tmp/modemsignal | grep 'EC/IO' | sed 's/.*: //' | tr -d \"'\"")

        -- put signal information into HTML
        local msg_percent = translate("Percentage") mobile_percentage .."%" .. br
        local msg_rssi = translate("RSSI") .. mobile_rssi .. br
        local msg_rsrq = translate("RSRQ") .. mobile_rsrq .. br
        local msg_rsrp = translate("RSRP") .. mobile_rsrp .. br
        local msg_snr = translate("SNR") .. mobile_snr .. br
        local msg_rscp = translate("RSCP") .. mobile_rscp .. br
        local msg_ecio = translate("EC/IO") .. mobile_ecio .. br
0 Likes

#2

There was a space in the string. Switching to string.match(access_tech, "LTE") worked.

1 Like

#3

I’ve been caught by the similar sh problem of
[ -x $filename ] instead of [ -x "$filename" ] and the like.

1 Like