Browse Source

fall back to SOFTAP if failed connect to AP

moononournation 7 years ago
parent
commit
ad2c768ef6
1 changed files with 5 additions and 3 deletions
  1. 5 3
      bin/init.lua

+ 5 - 3
bin/init.lua

@@ -25,8 +25,6 @@ if (conf.wifi.mode == wifi.STATION) or (conf.wifi.mode == wifi.STATIONAP) then
     wifi.sta.sethostname(conf.hostname)
     wifi.sta.config(conf.wifi.stassid, conf.wifi.stapwd, 1)
 end
-
-conf.wifi = nil
 collectgarbage()
 
 -- show system info
@@ -87,10 +85,14 @@ if (wifi.getmode() == wifi.STATION) or (wifi.getmode() == wifi.STATIONAP) then
        local ip = wifi.sta.getip()
        if ip == nil and joinCounter < joinMaxAttempts then
           print('Connecting to WiFi Access Point ...')
-          joinCounter = joinCounter +1
+          joinCounter = joinCounter + 1
        else
           if joinCounter == joinMaxAttempts then
              print('Failed to connect to WiFi Access Point.')
+             print('Fall back to SOFTAP.')
+             wifi.setmode(wifi.SOFTAP)
+             wifi.ap.config(conf.wifi.ap)
+             wifi.ap.setip(conf.wifi.apip)
           else
              print('IP: ',ip)
              mdns.register(conf.hostname, { description="NodeMCU WebIDE", service="http", port=80, location='In your ESP board' })