app.wifi={}
app.wifi.stat=false

--设置wifi为STATION/STATIONAP模式
--wifi.setmode(wifi.STATION)
wifi.setmode(wifi.STATIONAP)

local ct={}
ct.ssid=app.config.staSsid
ct.pwd=app.config.staPwd
ct.auto=false
wifi.sta.clearconfig()
wifi.sta.config(ct)

local apcfg={}
if(app.config.apSsid == nil)then
    apcfg.ssid='smart_'..node.chipid()
else
    apcfg.ssid=app.config.apSsid..'_'..app.config.name..'_'..node.chipid()
end
apcfg.pwd=app.config.apPwd
wifi.ap.config(apcfg)

print('[notice] ap is '..wifi.ap.getip())

wifi.eventmon.register(wifi.eventmon.AP_STACONNECTED, function(T)
    if(app.config.wifiAllowMac==nil) then
        local gu={}
        gu.wifiAllowMac=T.MAC
        app.global.update(gu)
        return
    elseif(T.MAC==app.config.wifiAllowMac) then
        return 
    end
    wifi.ap.deauth(T.MAC)
end)

app.wifi.con=function()
    --连接热点
    if(app.config.staSsid ~= nil and app.config.staPwd ~= nil) then
        if(wifi.sta.getip()==nil)then
            app.wifi.stat=false
            wifi.sta.connect(ct) 
            print('[notice] wifi info',app.config.staSsid,app.config.staPwd)  
            print('[notice] wait connect ap')
        else
            app.wifi.stat=true
            print('[notice] station ip is '..wifi.sta.getip())
        end
    end
end



