Help connectng to WiFi
Posted: Wed Jan 21, 2015 8:50 pm
First, I am completely new to Lua, but not to programming in general. This seems like it should be very simple from the examples in the forum but it has me completely stumped.
What I find is if I run the commands below (after defining the listAP function) the wifi.sta.getap() never sees my AP - I always wind up in the "No AP in range" branch. BUT! if I run them separately by hand (using lualoader) it picks up the AP withing a few seconds (that's why I put the tmr.delay(3000000) in and will allow me to connect. Why doesn't the delay work? Eventually I want the ESP to start up on it's own and communicate via http but on it's own I can't get it to reliably connect to the network. I've been beating on this for hours and hours and tried three different ESP-01 chips to no avail.
What I find is if I run the commands below (after defining the listAP function) the wifi.sta.getap() never sees my AP - I always wind up in the "No AP in range" branch. BUT! if I run them separately by hand (using lualoader) it picks up the AP withing a few seconds (that's why I put the tmr.delay(3000000) in and will allow me to connect. Why doesn't the delay work? Eventually I want the ESP to start up on it's own and communicate via http but on it's own I can't get it to reliably connect to the network. I've been beating on this for hours and hours and tried three different ESP-01 chips to no avail.
Code: Select all
-- declare function listAP
print("declaring listAP")
function listAP(tbl)
print("begin listAP")
local k
local v
if tbl then
-- do I recognize the network?
for k, v in pairs(tbl) do
print(k .. " : " .. v)
if k == "home" then
ssid = k
pswd = "password b"
elseif k == "work" then
ssid = k
pswd = "password y"
end
end
else
print("No AP in range")
end
end
wifi.sta.setmode(wifi.STATION)
wifi.sta.getap(listAP)
tmr.delay(3000000)
wifi.sta.config(ssid, pswd)
wifi.sta.connect()
print(wifi.sta.status())