As the title says... Chat on...

User avatar
By LEDAero
#20010 I have a script that handles not being able to connect to an SSID if it no-longer exists, but what it doesn't do is handle an existing SSID that I have given an invalid password.

I get a message:

ua: init.lua:14: pwd:0,8~64

and the script stops.

Is there a way of handling an invalid password?

(I'm a complete novice on Lua)
User avatar
By LEDAero
#20011 The code: config.lc holds the existing ssid credentials.

Code: Select alliWifiTries = 0 -- Counter of tries to connect to wifi
iMaxTries = 10 -- Maximum number of tries while waiting for connection
--setup baudrate
--uart.setup(0,115200,8,0,1)
--3s delay before starting with the program, sufficient break execution if needed
--tmr.alarm(0,3000,0,function() dofile("init2.lua") end)

--check for config.lc
if pcall(function ()
dofile("config.lc")
end) then
print("Connecting to SSID("..ssid..")")
wifi.setmode(wifi.STATION)
wifi.sta.config(ssid,password)
wifi.sta.connect()
tmr.alarm(1, 1000, 1, function()
if wifi.sta.getip() == nil then
print("SSID("..ssid..")["..iWifiTries.."]")
iWifiTries = iWifiTries + 1
if ( iWifiTries > iMaxTries ) then
print("Not able to connect to predefined WIFI so deleting config.lc file")
file.remove("config.lc")
node.restart()
end
else
tmr.stop(1)
print("Connected, IP is "..wifi.sta.getip())
dofile("run_program.lc")
end
end)
else
print("Enter configuration mode")
dofile('run_config.lc')
end