#!/opt/lnxall_app/bin/lua local bit32 = require 'bit32' local posix = require 'posix' local cjson = require 'cjson' local invoker = require 'invoker' local g_tty = { [1] = '/dev/ttyACM1', [2] = '/dev/ttyACM2', [3] = '/dev/ttyACM0', [4] = '/dev/ttyS7', [5] = '/dev/ttyS5', [6] = '/dev/ttyS4', [7] = '/dev/ttyS8', [8] = '/dev/ttyS0', } local lan2selfip = '192.168.5.101' local lan2pingip = '192.168.5.100' local function netdev_hasipv4(ndev) local okay, output = invoker.invoke(invoker.OUTPUT, "ip", "addr", "show", "dev", ndev) if okay ~= 0 or type(output) ~= "string" then return false end local ipaddr = string.match(output, "inet%s+([%d%.]+)/") if not ipaddr then io.stderr:write(string.format("Error, no ipv4 found for '%s'\n", ndev)) io.stderr:flush() return false end io.stdout:write(string.format("IPv4 address found for '%s': %s\n", ndev, ipaddr)) io.stdout:flush() return true end local function test_dido() local errv0,errv1 -- set XL9555/0x23 as output invoker.invoke(0, 'i2cset', '-y', '4', '0x23', '0x6', '0x0') invoker.invoke(0, 'i2cset', '-y', '4', '0x23', '0x7', '0x0') local rval = true -- output all ones invoker.invoke(0, 'i2cset', '-y', '4', '0x23', '0x2', '0xff') invoker.invoke(0, 'i2cset', '-y', '4', '0x23', '0x3', '0xff') invoker.msleep(200) -- read input local ok0, in0 = invoker.invoke(invoker.OUTPUT + invoker.TRIMEND, 'i2cget', '-y', '4', '0x21', '0x0', 'w') if ok0 ~= 0 or in0 ~= "0x000f" then rval = false errv0 = tonumber(in0) if type(ok0) ~= "number" then ok0 = -1 end if type(in0) ~= "string" then in0 = "wtf0" end io.stderr:write(string.format("Error, DI/DO test1 has failed: %d, %s\n", ok0, in0)) io.stderr:flush() else errv0 = 0x000f end -- output all zeros invoker.invoke(0, 'i2cset', '-y', '4', '0x23', '0x2', '0x0') invoker.invoke(0, 'i2cset', '-y', '4', '0x23', '0x3', '0x0') invoker.msleep(200) -- read input local ok1, in1 = invoker.invoke(invoker.OUTPUT + invoker.TRIMEND, 'i2cget', '-y', '4', '0x21', '0x0', 'w') if ok1 ~= 0 or in1 ~= "0xfff0" then rval = false errv1 = tonumber(in1) --errv1 = bit32.bxor(errv1, 0xfff0) --local hex1 = string.format("0x%x", errv1) if type(ok1) ~= "number" then ok1 = -1 end if type(in1) ~= "string" then in1 = "wtf1" end io.stderr:write(string.format("Error, DI/DO test2 has failed: %d, %s\n", ok1, in1)) io.stderr:flush() else errv1 = 0xfff0 end if rval then io.stdout:write("Test DI/DO OKAY!!!\n") io.stdout:flush() else local errv3 local error_note = "" local n = 1 local binary = "" if type(errv0) ~= "number" or type(errv1) ~= "number" then io.stdout:write(string.format("Error,DI/DO read empty\n")) io.stdout:flush() error_note = "all error" return rval,err_note else errv3 = bit32.bxor(errv0, errv1) end if errv3 == 0 then binary = "0" error_note = "all error" io.stdout:write(string.format("DI/DO is all error\n")) io.stdout:flush() else while errv3 > 0 do local remainder = errv3 % 2 if remainder == 0 then error_note = error_note .. n .. "," io.stdout:write(string.format("DI%d is error\n", n)) io.stdout:flush() end n = n + 1 binary = remainder .. binary errv3 = math.floor(errv3 / 2) end while n < 17 do error_note = error_note .. n .. "," io.stdout:write(string.format("DI%d is error\n", n)) io.stdout:flush() n = n + 1 end end io.stdout:write(string.format("D1/DO error is %s\n", binary)) io.stdout:flush() return rval,error_note end return rval,nil end local function test_rs485(p0, p1) local wtf = posix.stat(p0) if type(wtf) ~= "table" or wtf['type'] ~= 'character device' then io.stderr:write(string.format("Error, invalid RS485 device: %s\n", p0)) io.stderr:flush() return false end wtf = posix.stat(p1) if type(wtf) ~= "table" or wtf['type'] ~= 'character device' then io.stderr:write(string.format("Error, invalid RS485 device: %s\n", p1)) io.stderr:flush() return false end -- for debian based system, we have a very strong `stty invoker.invoke(0, 'stty', '-F', p0, "raw", "9600", "cs8", "-hupcl", "-onlcr", "-iexten", "-echo", "-echoe", "-echok", "-echoctl", "-echoke", "-parenb") invoker.invoke(0, 'stty', '-F', p1, "raw", "9600", "cs8", "-hupcl", "-onlcr", "-iexten", "-echo", "-echoe", "-echok", "-echoctl", "-echoke", "-parenb") local rawstr = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' local rstr = invoker.randstr(0x8, rawstr) local tmpfile = "/tmp/tmp-" .. rstr local catpid = invoker.invoke(invoker.NOWAIT, "/bin/sh", "-c", string.format("TTY_READ=1 exec tty_rw %s > %s", p0, tmpfile)) if type(catpid) ~= "number" then io.stderr:write(string.format("Error, failed to execute 'cat %s'\n", p0)) io.stderr:flush() posix.unlink(tmpfile) return false end invoker.msleep(10) invoker.invoke(0, 'tty_rw', p1, string.format('=%s=%s=\n', rstr, rstr)) invoker.msleep(50) invoker.kill(catpid, posix.SIGKILL) invoker.kill(catpid, posix.SIGTERM) invoker.waitpid(catpid, false) local output = invoker.readfile(tmpfile, invoker.TRIMEND) posix.unlink(tmpfile) if type(output) ~= "string" or not string.find(output, rstr, 1, true) then io.stderr:write(string.format("Error, test RS485 port has failed: %s => %s\n", p1, p0)) if type(output) == "string" then io.stderr:write(string.format("\tExpected: %s, output: %s\n", rstr, output)) end io.stderr:flush() return false end io.stdout:write(string.format("INFO: test RS485 port OKAY: %s => %s\n", p1, p0)) if type(output) == "string" then io.stdout:write(string.format("\tExpected: %s, output: %s\n", rstr, output)) end io.stdout:flush() return true end local function can_get() local cans = { "can0", "can1", "lnxcan1", "lnxcan2" } local can_dev = {} for _, can in ipairs(cans) do local okay, output = invoker.invoke(invoker.OUTPUT, "ip", "addr", "show", can) if okay and type(output) == "string" then local dev = string.match(output, ":%s(.-):") if dev then can_dev[#can_dev+1] = dev end end if #can_dev == 2 then return can_dev end end return can_dev end local function setup_can(candev) invoker.invoke(0, 'ip', 'link', 'set', 'dev', candev, 'down') invoker.msleep(100) invoker.invoke(0, 'ip', 'link', 'set', 'dev', candev, 'type', 'can', 'bitrate', '500000', 'triple-sampling', 'on') invoker.msleep(100) invoker.invoke(0, 'ip', 'link', 'set', 'dev', candev, 'up') invoker.msleep(100) end local function can_test(p0, p1) setup_can(p0) setup_can(p1) local cdata = invoker.randstr(16, "12345678ABCDEF") local tmpfile = "/tmp/candump.txt" posix.unlink(tmpfile) local cpid = invoker.invoke(invoker.NOWAIT, "/bin/sh", "-c", string.format("exec candump -L -T 4000 %s > %s 2>/dev/null", p0, tmpfile)) invoker.msleep(50) invoker.invoke(0, "cangen", "-x", "-n", "3", "-I", "0x124", "-D", cdata, p1) invoker.waitpid(cpid, false) local output = invoker.readfile(tmpfile) posix.unlink(tmpfile) if type(output) ~= "string" or not string.find(output, cdata, 1, true) then io.stderr:write(string.format("Error, CAN test has failed: %s => %s\n", p1, p0)) io.stderr:flush() return false end io.stdout:write(string.format("CAN test OKAY: %s => %s\n", p1, p0)) io.stdout:flush() return true end local function update_resolv() local res = invoker.readfile('/etc/resolv.conf') local myres = "nameserver 114.114.114.114\nnameserver 8.8.8.8\n" if res ~= myres then io.stdout:write("Updating /etc/resolv.conf...\n") io.stdout:flush() local filp = io.open('/etc/resolv.conf', 'wb') if filp then filp:write(myres) filp:close() filp = nil end end return true end local function ping_with(ifname, host) if not host then host = 'mqtt.lnxall.com' end if not netdev_hasipv4(ifname) then return false end io.stdout:write(string.format("Ping '%s' with interface '%s'...\n", host, ifname)) io.stdout:flush() local cmds = { "ping", "-c10", "-I", ifname, host } local _, output = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) if type(output) == "string" and string.find(output, "packet loss", 1, true) then if string.find(output, "100% packet loss", 1, true) then return false end return true end return false end local function get_lan_host() local ipaddr = {} local arpfile = io.open("/proc/net/arp", "rb") if not arpfile then io.stderr:write("Error, failed to open arp file.\n") io.stderr:flush() return ipaddr end for line in arpfile:lines() do if string.find(line, "br-lan", 1, true) then local ip = string.match(line, "^([%d%.]+)") if invoker.isipv4(ip) then ipaddr[#ipaddr + 1] = ip end end end if #ipaddr == 0 then io.stderr:write("Error, no device connected to LAN\n") io.stderr:flush() end return ipaddr end local function findtype(text,info) local start = string.find(text,info) if start then start_quote = string.find(text, '"', start) end_quote = string.find(text, '"', start_quote + 1) if start_quote and end_quote then final_type = string.sub(text, start_quote + 1, end_quote - 1) end return final_type else return "can't get info" end end local function findnumber(text,info) local start = string.find(text,info) if start then start = start + string.len(info) + 1 end_n = string.find(text, "\n", start) if end_n then final_number = string.sub(text, start, end_n - 1) end return final_number else return "can't get info" end end local function get_moudle_info(datj) print("MOUDLE INFO SETTINGS TEST START!") local eval,finfo = invoker.invoke(invoker.OUTPUT,"/opt/lnxall_app/platspec/moudleinfo") if eval and type(finfo) == "string" then Producer = findtype(finfo,"Producer:") if Producer == "no_modem" then datj["MOUDLE_INFO"] = nil else IMEI = findnumber(finfo,"imei info:") ICCID = findnumber(finfo,"iccid info:") SIGNAL = findnumber(finfo,"signal info:") if #ICCID < 20 then ICCID = "no sim card" sim_SP = "no sim card" else sim_SP_number = findnumber(finfo,"+COPS:") if #sim_SP_number > 10 then sim_SP = findtype(finfo,"+COPS:") else sim_SP = "sim card locked " end end if Producer == "Quectel" then _,_,moudle_4G_type = string.find(finfo,'Revision: (%w+)') end if Producer == "AirM2M" then moudle_4G_type = findtype(finfo,"+CGMM:") end end datj["MOUDLE_INFO"] = { ["IMEI"] = IMEI, ["moudle_4G_sp"] = Producer, ["moudle_4G_type"] = moudle_4G_type, ["iccid"] = ICCID, ["sim_sp"] = sim_SP, ["signal"] = SIGNAL } else print("MOUDLE INFO SETTINGS TEST FAILED!!") return false end print(datj["MOUDLE_INFO"]["IMEI"]) print(datj["MOUDLE_INFO"]["moudle_4G_sp"]) print(datj["MOUDLE_INFO"]["moudle_4G_type"]) print(datj["MOUDLE_INFO"]["iccid"]) print(datj["MOUDLE_INFO"]["sim_sp"]) print(datj["MOUDLE_INFO"]["signal"]) print("MOUDLE INFO SETTINGS TEST OK") return true end local function test_led() local result = {} local leds = { "net", "run", "wifi" } for idx = 1, 8 do local wval = string.format("%d\n", bit32.band(idx, 0x1)) for _, led in ipairs(leds) do local okay = false local ledp = string.format("/sys/class/leds/%s/brightness", led) if posix.access(ledp) == 0 then local lfile = io.open(ledp, "wb") if lfile then okay = true lfile:write(wval) lfile:close() lfile = nil end end if okay then result[led] = { interfaces = led, error_code = 0, error_msg = "success" } else result[led] = { interfaces = led, error_code = 1, error_msg = string.format("led_%s not found", led) } end end invoker.msleep(250) end local result_led = {} result_led[1] = result["net"] result_led[2] = result["run"] result_led[3] = result["wifi"] return result_led end local function find4g(text,info) local start = string.find(text,info) if start then start = start + string.len(info) + 1 end_n = string.find(text, "\n", start) if end_n then final = string.sub(text, start, end_n - 1) end return final else return "can't get info" end io.stdout:write(string.format("final = %s\n", final)) io.stdout:flush() end local function get_4g_test() local result local cmds = { "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh", "get"} local result2, output = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) io.stdout:write(string.format("output = %s\n", output)) io.stdout:flush() local key = find4g(output, "+QDSIM:") local note_ready = find4g(output, "+CPIN:") local note_error= find4g(output, "+CME") io.stdout:write(string.format("note_ready = %s\n", note_ready)) io.stdout:write(string.format("key = %s\n", key)) io.stdout:write(string.format("note_error = %s\n", note_error)) io.stdout:flush() if type(output) == "string" and string.match(note_error, "ERROR: 10") then io.stdout:write(string.format("Error, failed to find card %s\n", key)) io.stdout:flush() result = false return result,key elseif type(output) == "string" and string.match(note_ready,"READY") then result = true return result,key else io.stdout:write("Error, failed to get 4g\n") io.stdout:flush() resule = false return result,key end end local function change_4g_test(key) local i = 1 local cmds = {} if string.match(key,"1") then cmds = { "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh", "0" } elseif string.match(key,"0") then cmds = { "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh", "1" } end local _, output = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) invoker.msleep(300) local result, key2 = get_4g_test() while(key2 == key) do i = i+1 if result == false then return result end _, output = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds) invoker.msleep(300) result, key2 = get_4g_test() io.stdout:write(string.format("value2 = %s\n", key2)) io.stdout:flush() if i > 5 then io.stdout:write("Error, failed to change 4G-NET\n") io.stdout:flush() return false end end return result end local function ssd_format() local str = nil invoker.invoke(0,'systemctl', 'stop', 'emsd') io.stdout:write(string.format("systemctl stop emsd\n")) local file = io.open("/app/config/system_cfg.json","r") if file then str = file:read("*all") file:close() end if string.find(str,"en_lc: 1") then io.stdout:write(string.format("systemctl stop emud\n")) io.stdout:flush() invoker.invoke(0,'systemctl', 'stop', 'emud') invoker.msleep(1000) end okay, output = invoker.invoke(invoker.OUTPUT, "lsof", "/mnt/ssd/") if okay and type(output) == "string" then if string.find(output,"/mnt/ssd/database") then io.stdout:write("systemctl stop linit\n") invoker.invoke(0,'systemctl', 'stop', 'linit') invoker.msleep(1000) end if string.find(output,"/mnt/ssd/taos") then io.stdout:write("systemctl stop taosd\n") io.stdout:flush() invoker.invoke(0,'systemctl', 'stop', 'taosd') invoker.msleep(1000) end end local res, result = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, "ssd_format.sh", "-f", "-f") if type(result) == "string" then io.stdout:write(string.format("%s\n",result)) io.stdout:flush() end if res ~= 0 or type(result) ~= "string" or string.find(result,"Error") then io.stdout:write("Error,ssd_format faild.\n") io.stdout:flush() os.exit(1) end end local function i2c_test() local okay, result = invoker.invoke(invoker.OUTPUT, "cat", "/var/log/Xorg.0.log", "|", "grep", "-e", "goodix-ts") if okay ~= 0 or type(result) ~= "string" then io.stderr:write("Error, '' has failed.\n") io.stderr:flush() return false end return true end local function maindiag(arg1) local summary = {} local finalsummary = {} finalsummary["MOUDLE_INFO"] = {} local sim0_info = {} sim0_info["MOUDLE_INFO"] = {} local sim1_info = {} sim1_info["MOUDLE_INFO"] = {} local okay, facini = invoker.invoke(invoker.OUTPUT, "factory", "get") if okay ~= 0 or type(facini) ~= "string" then io.stderr:write("Error, 'factory get' has failed.\n") io.stderr:flush() return 1 end local gwsn = string.match(facini, "SN=([^\r\n]+)") local hwver = string.match(facini, "HWVER=([^\r\n]+)") or "" local macaddr = string.match(facini, "MAC=([^\r\n]+)") or "" local gwpro = string.match(facini, "PRODUCT=([^\r\n]+)") if not gwsn or not gwpro then io.stderr:write("Error, gateway SN or PRODUCT not found.\n") io.stderr:flush() return 2 end local softver = invoker.readfile("/lib/dyiot/issue", invoker.TRIMEND) if type(softver) ~= "string" or #softver == 0 then softver = invoker.readfile("/etc/issue", invoker.TRIMEND) if type(softver) ~= "string" or #softver == 0 then softver = "unknown" end end invoker.invoke(0, "ifconfig", "br-lan:0", lan2selfip, "netmask", "255.255.255.0", "up") finalsummary["sn"] = gwsn finalsummary["timestamp"] = os.time() finalsummary["MAC"] = macaddr finalsummary["HWVER"] = hwver finalsummary["SWVER"] = softver summary["ioDetect"] = test_led() local ports = {} if test_rs485(g_tty[1], g_tty[2]) then ports[#ports + 1] = { interfaces = "RS485_1", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_1", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[2], g_tty[1]) then ports[#ports + 1] = { interfaces = "RS485_2", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_2", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[3], g_tty[4]) then ports[#ports + 1] = { interfaces = "RS485_3", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_3", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[4], g_tty[3]) then ports[#ports + 1] = { interfaces = "RS485_4", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_4", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[5], g_tty[6]) then ports[#ports + 1] = { interfaces = "RS485_5", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_5", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[6], g_tty[5]) then ports[#ports + 1] = { interfaces = "RS485_6", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_6", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[7], g_tty[8]) then ports[#ports + 1] = { interfaces = "RS485_7", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_7", error_msg = "CANNOT WORK", error_code = 1 } end if test_rs485(g_tty[8], g_tty[7]) then ports[#ports + 1] = { interfaces = "RS485_8", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RS485_8", error_msg = "CANNOT WORK", error_code = 1 } end local can_dev = can_get() if not can_dev[1] or not can_dev[2] then ports[#ports + 1] = { interfaces = "CAN0", error_msg = "CANNOT WORK", error_code = 1 } ports[#ports + 1] = { interfaces = "CAN1", error_msg = "CANNOT WORK", error_code = 1 } else if can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2]) or can_test(can_dev[1], can_dev[2])then ports[#ports + 1] = { interfaces = "CAN0", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "CAN0", error_msg = "CANNOT WORK", error_code = 1 } end if can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) or can_test(can_dev[2], can_dev[1]) then ports[#ports + 1] = { interfaces = "CAN1", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "CAN1", error_msg = "CANNOT WORK", error_code = 1 } end end if posix.access('/dev/rtc0') == 0 then ports[#ports + 1] = { interfaces = "RTC", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "RTC", error_msg = "RTC0 NOT FOUND", error_code = 1 } end local rval, binary = test_dido() if rval then ports[#ports + 1] = { interfaces = "DI_TEST", error_code = 0, error_msg = "success" } ports[#ports + 1] = { interfaces = "DO_TEST", error_code = 0, error_msg = "success" } else ports[#ports + 1] = { interfaces = "DI_TEST", error_code = 1, error_msg = binary } ports[#ports + 1] = { interfaces = "DO_TEST", error_code = 1, error_msg = binary } end if invoker.mountpoint('/mnt/ssd') then ports[#ports + 1] = { interfaces = "SSD", error_msg = "success", error_code = 0 } else ports[#ports + 1] = { interfaces = "SSD", error_msg = "Solid State Drive Error", error_code = 1 } end summary["OnBoardPort"] = ports local netw = {} update_resolv() if ping_with('eth4') or ping_with('eth4', '114.114.114.114') then netw[#netw + 1] = { interfaces = "WAN2", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "WAN2", error_msg = "NOT OKAY", error_code = 1 } end os.execute("nmcli con down wan2") update_resolv() if ping_with('eth3') or ping_with('eth3', '114.114.114.114') then netw[#netw + 1] = { interfaces = "WAN1", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "WAN1", error_msg = "NOT OKAY", error_code = 1 } end os.execute("nmcli con down wan1") update_resolv() if ping_with('eth2') or ping_with('eth2', '114.114.114.114') then netw[#netw + 1] = { interfaces = "WAN", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "WAN", error_msg = "NOT OKAY", error_code = 1 } end os.execute("nmcli con down wan") io.stdout:write(string.format("Upload simcard: %s\n",arg1)) io.stdout:flush() invoker.msleep(1000) invoker.invoke(0, "/lib/dyiot/init.d/deb4gnet", "stop") invoker.msleep(1000) invoker.invoke(0, "systemctl", "stop", "linit.service") local command = "ps aux | grep -e deb4gnet | grep -v -e grep | gawk '{print $2}'" local file = io.popen(command) local output0 = file:read("*a") file:close() if output0 ~= nil and output0 ~= "" then for pid in string.gmatch(output0,"%S+") do invoker.kill(pid,9) invoker.msleep(100) io.stderr:write("killed.\n") io.stderr:flush() end end update_resolv() local cmds1 = { "chmod", "+x", "/opt/lnxall_app/platspec/ec800g-switch-simcard.sh"} local _, output1 = invoker.invoke(invoker.OUTPUT + invoker.NOSTDIO, cmds1) local result, value = get_4g_test() value = string.gsub(value,"\r","") if string.match(value,"1") then value2 = "0" get_moudle_info(sim1_info) invoker.msleep(2000) elseif string.match(value,"0") then value2 = "1" if arg1 == "2" then get_moudle_info(sim0_info) invoker.msleep(2000) end else _, value = get_4g_test() value = string.gsub(value,"\r","") if string.match(value,"1") then value2 = "0" get_moudle_info(sim1_info) invoker.msleep(2000) elseif string.match(value,"0") then value2 = "1" if arg1 == "2" then get_moudle_info(sim0_info) invoker.msleep(2000) end else value2 = " " end end if ping_with('usb0') or ping_with('usb0', '114.114.114.114') and result then netw[#netw + 1] = { interfaces = "4G-Net" .. value, error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "4G-Net" .. value, error_msg = "NOT OKAY", error_code = 1 } end local result2 = change_4g_test(value) if ping_with('usb0') or ping_with('usb0', '114.114.114.114') and result2 then netw[#netw + 1] = { interfaces = "4G-Net" .. value2, error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "4G-Net" .. value2, error_msg = "NOT OKAY", error_code = 1 } end if string.match(value2,"1") then get_moudle_info(sim1_info) invoker.msleep(2000) elseif string.match(value2,"0") and arg1 == "2" then get_moudle_info(sim0_info) invoker.msleep(2000) end os.execute("nmcli con up wan") os.execute("nmcli con up wan1") os.execute("nmcli con up wan2") local landevs, lanokay = get_lan_host(), false for _, ip in pairs(landevs) do if ping_with('br-lan', ip) then lanokay = true break end end if lanokay then netw[#netw + 1] = { interfaces = "LAN", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "LAN", error_msg = "NOT OKAY", error_code = 1 } end if ping_with('br-lan', lan2pingip) then netw[#netw + 1] = { interfaces = "LAN2", error_msg = "success", error_code = 0 } else netw[#netw + 1] = { interfaces = "LAN2", error_msg = "NOT OKAY", error_code = 1 } end if invoker.invoke(invoker.OUTPUT,"ip", "link", "show", "dev", "wlan0") == 0 then netw[#netw + 1] = { interfaces = "wlan0", error_msg = "success", error_code = 0} else netw[#netw + 1] = { interfaces = "wlan0", error_msg = "NOT OKAY", error_code = 1} end summary["NetWork"] = netw finalsummary["data"] = summary finalsummary["MOUDLE_INFO"]["moudle_4G_sp"] = sim1_info["MOUDLE_INFO"]["moudle_4G_sp"] finalsummary["MOUDLE_INFO"]["moudle_4G_type"] = sim1_info["MOUDLE_INFO"]["moudle_4G_type"] finalsummary["MOUDLE_INFO"]["addid"] = sim1_info["MOUDLE_INFO"]["iccid"] finalsummary["MOUDLE_INFO"]["addsp"] = sim1_info["MOUDLE_INFO"]["sim_sp"] finalsummary["MOUDLE_INFO"]["IMEI"] = sim1_info["MOUDLE_INFO"]["IMEI"] if arg1 == "2" then finalsummary["MOUDLE_INFO"]["iccid"] = sim0_info["MOUDLE_INFO"]["iccid"] finalsummary["MOUDLE_INFO"]["sim_sp"] = sim0_info["MOUDLE_INFO"]["sim_sp"] end io.stdout:write("\n---TEST SUMMARY---\ntest_result:") io.stdout:write(cjson.encode(finalsummary)) io.stdout:write("\n") io.stdout:flush() invoker.invoke(0, "ifconfig", "br-lan:0", lan2selfip, "netmask", "255.255.255.0", "down") end posix.setenv("PATH", "/opt/lnxall_app/bin:/usr/bin:/usr/sbin:/bin:/sbin", true) maindiag(arg[1]) os.exit(0)