|
@@ -1,10 +1,17 @@
|
|
--- Tell the chip to connect to the access point
|
|
|
|
|
|
+-- Tel--l the chip to connect to the access point
|
|
|
|
+--wifi.setmode(wifi.STATIONAP)
|
|
wifi.setmode(wifi.STATION)
|
|
wifi.setmode(wifi.STATION)
|
|
-print('set mode=STATION (mode='..wifi.getmode()..')')
|
|
|
|
|
|
+print('set (mode='..wifi.getmode()..')')
|
|
print('MAC: ',wifi.sta.getmac())
|
|
print('MAC: ',wifi.sta.getmac())
|
|
print('chip: ',node.chipid())
|
|
print('chip: ',node.chipid())
|
|
print('heap: ',node.heap())
|
|
print('heap: ',node.heap())
|
|
-wifi.sta.config("Internet","")
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+local cfg={}
|
|
|
|
+cfg.ssid="ESP-"..node.chipid()
|
|
|
|
+cfg.pwd="ESP-"..node.chipid()
|
|
|
|
+wifi.ap.config(cfg)
|
|
|
|
+cfg = nil
|
|
|
|
|
|
-- Compile server code and remove original .lua files.
|
|
-- Compile server code and remove original .lua files.
|
|
-- This only happens the first time afer the .lua files are uploaded.
|
|
-- This only happens the first time afer the .lua files are uploaded.
|
|
@@ -12,6 +19,7 @@ wifi.sta.config("Internet","")
|
|
local compileAndRemoveIfNeeded = function(f)
|
|
local compileAndRemoveIfNeeded = function(f)
|
|
if file.open(f) then
|
|
if file.open(f) then
|
|
file.close()
|
|
file.close()
|
|
|
|
+ print(f)
|
|
node.compile(f)
|
|
node.compile(f)
|
|
file.remove(f)
|
|
file.remove(f)
|
|
end
|
|
end
|
|
@@ -25,14 +33,22 @@ serverFiles = nil
|
|
|
|
|
|
-- Connect to the WiFi access point. Once the device is connected,
|
|
-- Connect to the WiFi access point. Once the device is connected,
|
|
-- you may start the HTTP server.
|
|
-- you may start the HTTP server.
|
|
|
|
+
|
|
|
|
+local joincounter = 0
|
|
|
|
+
|
|
tmr.alarm(0, 3000, 1, function()
|
|
tmr.alarm(0, 3000, 1, function()
|
|
- if wifi.sta.getip() == nil then
|
|
|
|
|
|
+
|
|
|
|
+ if wifi.sta.getip() == nil and joincounter < 5 then
|
|
print("Connecting to AP...")
|
|
print("Connecting to AP...")
|
|
- else
|
|
|
|
|
|
+ joincounter = joincounter +1
|
|
|
|
+ else
|
|
tmr.stop(0)
|
|
tmr.stop(0)
|
|
- print('IP: ',wifi.sta.getip())
|
|
|
|
|
|
+ -- print('IP: ',wifi.sta.getip())
|
|
-- Uncomment to automatically start the server in port 80
|
|
-- Uncomment to automatically start the server in port 80
|
|
- -- dofile("httpserver.lc")(80)
|
|
|
|
|
|
+ joincounter = nil
|
|
|
|
+ collectgarbage()
|
|
|
|
+ dofile("httpserver.lc")(80)
|
|
end
|
|
end
|
|
|
|
+
|
|
end)
|
|
end)
|
|
|
|
|