Lua script stops?

hello guys
I have no idea why my lua script for Web UI stops sometimes.

here are the summary codes.

-- httpSettings.lua

local code = 0
loacl result = {}
local LuciHttp = require("luci.http")
local wifiSetup = require(luci.model.api.wifiFunctions)
local ssid2G = LuciHttp.formvalue(ssid2G)
local ssid5G = LuciHttp.formvalue(ssid5G)
~~~ -- codes that gets other values(encryption, channel, etc.) from html

os.execute("echo \"#########################################\" > /dev/console")
os.execute("echo \"got values, and calling wifiSetup\" > /dev/console")
wifiSetup.setWifi(ssid, ~~~ , ~~~, ~~~, ...)
os.execute("echo \"wifiSetup complete\" > /dev/console")
os.execute("usr/bin/configSetup") -- this sets uci settings to a MT7621's setting
os.execute("echo \"configSetup complete\" > /dev/console")
os.execute("env -i /sbin/wifi reload;sleep 1; 2>/dev/null 2>/dev/null")
os.execute("echo \"wifi reload complete\" > /dev/console")
os.execute("usr/bin/interfaceUpDown") -- this checks interfaces' status, enables(Up) or disables(Down) interfaces.
os.execute("echo \"interfaceUpDown complete\" > /dev/console")
os.execute("echo \"#########################################\" > /dev/console")
result["code"] = code
luci.http.prepare_content("application/json")
luci.http.write_json(result) -- after all configurations, sends "result(0)" to html and html page reloads.
os.execute("echo \"done\" > /dev/console")
os.execute("echo \"#########################################\" > /dev/console")
-- wifiFunctions.lua

function setWifi(ssid, ~~~, ~~~, ~~~ ...)   

-- codes that JUST set to UCI settings.
    os.execute("echo \"    setWifi is called\" > /dev/console")
    os.execute("uci set wireless.wifi_iface.ssid="..ssid)
    os.execute("uci set wireless.wifi_iface.encryption="..encryption)
    os.execute("uci set wireless.wifi_iface.channel="..channel)
    ~~~
    os.execute("uci commit wireless")
    os.execute("echo \"    wireless is committed via uci\" > /dev/console")
    return 0
end

In conclusion, if i set ssid and other things like PW, encryption, channel, etc.,

  1. sends those values to httpSettings.lua, and waits untill it gets result(0)
  2. httpSettings.lua sends those valuse again to setWifi function, wifiFunctions.lua.
  3. setWifi function set those values via uci settings.
  4. httpSettungs.lua executes a file that set MT7621's config file, reload wifi, set interfaces' status, and return a result(0) value
  5. page reloads

What i expect from my terminal console is...

got values, and calling wifiSetup
    setWifi is called
    wireless is committed via uci
wifiSetup complete
configSetup complete
wifi reload complete
interfaceUpDown complete
#########################################
done
#########################################

after that "done", page reloads.

However, SOMETIMES, those scripts doesn't work properlly.
if i set that wifi settings at html 100 times,
around 2~30 times script stops after executing "usr/bin/configSetup", not reloading the page, log stops at consigSetup complete
around 5 times, script stops after executung "usr/bin/interfaceUpDown" also not reloading the page. log stops at interfaceUpDown complete

my html uses ajax to call those functions and wait for the result, so it doesn't need a time values to wait.
I really have no idea why this script stops.
if that script stops all the time, that's 100% my problem, but it stops sometimes, so i have no idea for that.

Any ideas for this?

90% of your script logic is calling external processes, so the fault most likely lies there. Since neither wifiSetup nor configSetup are part of standard OpenWrt, we can't really help there.

1 Like