-- wifi init
cfg_wifi_ssid,cfg_wifi_key = "CCCP","wifi681818"
wifi.setmode(wifi.STATION)
wifi.sta.config(cfg_wifi_ssid,cfg_wifi_key)
wifi.sta.autoconnect(1)
-- tmr connect establish
tmr_count = 0
tmr.alarm(0, 1000, 1, function()
if(wifi.sta.getip() == nil)then
-- wifi connect try
print("Conn to AP (ssid="..cfg_wifi_ssid.."/key="..cfg_wifi_key..") try:"..tmr_count)
tmr_count = tmr_count+1
if(tmr_count > 60)then
-- set ESP to alarm wifi AP mode
wifi.sta.disconnect();
wifi.setmode(wifi.SOFTAP)
--wifi.setmode(wifi.STATIONAP)
wifi.ap.config({ssid="ERROR",pwd="147852369"})
-- print wifi status
print("WiFi AP (ssid=ERROR/key=147852369)")
print('IP:',wifi.ap.getip())
print('Mode=AP')
print('MAC:',wifi.ap.getmac())
tmr.stop(0)
end
else
--print wifi status
print('IP: ',wifi.sta.getip())
print('Mode=Client')
print('MAC:',wifi.sta.getmac())
dofile("switch.lua")
tmr.stop(0)
end
end)