0
0
mirror of https://github.com/Doodle3D/doodle3d-firmware.git synced 2024-11-04 21:53:24 +01:00

Check a few times if associating to network succeeded, otherwise fail

This commit is contained in:
peteruithoven 2014-02-24 16:33:51 +01:00
parent 19892f0917
commit d5f2ec85d3

View File

@ -371,15 +371,30 @@ function M.associateSsid(ssid, passphrase, recreate, boot)
--M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" } --M.switchConfiguration{ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm", wireless="reload" }
M.switchConfiguration({ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm" },boot) M.switchConfiguration({ wifiiface="add", staticaddr="rm", dhcppool="rm", wwwredir="rm", dnsredir="rm" },boot)
-- check if we are actually associated -- we check if we get a ssid and ip in max 5 seconds
local status = wifi.getDeviceState() -- if not there is probably a issue
if not status.ssid or status.ssid ~= ssid then local attemptInterval = 1
local maxAttempts = 5
local attempt = 0
local nextAttemptTime = os.time()
while true do
if os.time() > nextAttemptTime then
log:debug("associated check "..utils.dump(attempt).."/"..utils.dump(maxAttempts))
if wifi.getLocalIP() ~= nil and wifi.getDeviceState().ssid == ssid then
break
else
attempt = attempt+1
if attempt >= maxAttempts then
-- still no correct ssid; fail
local msg = "Could not associate with network (incorrect password?)" local msg = "Could not associate with network (incorrect password?)"
M.setStatus(M.CONNECTING_FAILED,msg); M.setStatus(M.CONNECTING_FAILED,msg);
return nil,msg return false, msg
else
nextAttemptTime = os.time() + attemptInterval
end
end
end
end end
M.setStatus(M.CONNECTED,"Connected");
-- signin to connect.doodle3d.com -- signin to connect.doodle3d.com
local success, output = signin.signin() local success, output = signin.signin()
@ -389,6 +404,9 @@ function M.associateSsid(ssid, passphrase, recreate, boot)
log:info("Signing in failed") log:info("Signing in failed")
end end
-- report we are connected after signin attempt
M.setStatus(M.CONNECTED,"Connected");
return true return true
end end
--- Disassociate wlan device as client from all SSID's. --- Disassociate wlan device as client from all SSID's.