#!/opt/lnxall_app/bin/lua -- Created by jiaqiang.ye@lnxall.com -- Blink LED when no gateway SN found local bit32 = require 'bit32' local posix = require 'posix' local invoker = require 'invoker' local function find_gwsn() local okay, output = invoker.invoke(invoker.OUTPUT, "factory", "get") if okay ~= 0 or type(output) ~= "string" then return nil end return string.match(output, "SN=([^\r\n]+)") end local function get_leds() -- LEDs for RK3568 local leds = { [1] = "/sys/class/leds/run/brightness", [2] = "/sys/class/leds/net/brightness" } return leds, 1 end local function blink_leds(leds, val) local wval = string.format("%d\n", val) for _, led in ipairs(leds) do local lp = io.open(led, "wb") if lp then lp:write(wval) lp:close() end end end local function mainfunc() local gwsn = nil local leds, maxval = get_leds() local bcount = 0 while true do gwsn = find_gwsn() if gwsn then io.stdout:write(string.format("Gateway SN found: %s, Exiting\n", gwsn)) io.stdout:flush() break end if bit32.band(bcount, 0x1) == 0 then blink_leds(leds, 0) else blink_leds(leds, maxval) end bcount = bcount + 1 invoker.waitsec(2) end end invoker.waitsec(60) -- delay 1 minutes posix.setenv("PATH", "/opt/lnxall_app/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin", 1) mainfunc()