StationCfg = {} IpCfg = {} WifiSaved = {} --Load Config.lua and get value from Config_Table function AutoLink() --get key from eus_params.lua if Files["eus_params.lua"] then WifiSaved = dofile("eus_params.lua"); else AutoLinkByMobile(); PageAPNet(); return nil; end --SampleLink ManualLink(WifiSaved.wifi_ssid,WifiSaved.wifi_password) end function ManualLink(ssid,passwd) wifi.setmode(wifi.STATION) StationCfg.ssid=ssid StationCfg.pwd=passwd StationCfg.save=false wifi.sta.config(StationCfg) wifi.sta.connect() if wifi.sta.getip() == nil then SetIPFromFile(); end PageMainScene(ssid,wifi.sta.getip(),Config_Table["Version"]); local lightArr = {[1]=false,[2]=false,[3]=false,[4]=false} PageLight(lightArr) --Service Open StartUDPService(); print(wifi.sta.status()); end --mobile setting ap and passwd function AutoLinkByMobile() wifi.setmode(wifi.STATIONAP) wifi.ap.config({ssid="DY-Light-Controller", auth=wifi.OPEN}) enduser_setup.manual(true) enduser_setup.start( "DY-Light-Controller", function() print("Connected to WiFi!") end, function(err, str) print("enduser_setup: Err #" .. err .. ": " .. str) end ) print("init endUserServer") end --GetAPList -- function Listap(t) -- for k,v in pairs(t) do -- print(k.." : "..v) -- end -- end -- wifi.sta.getap(Listap) function SetIP(ipAddress,netmask,gateway) IpCfg = { ip = ipAddress, netmask = netmask, gateway = gateway } wifi.sta.setip(IpCfg) end --SetIP("192.168.1.115","255.255.255.0","192.168.1.1") function SaveIP(ipAddress,netmask,gateway) SaveData("IpAddress",ipAddress); SaveData("Netmask",netmask); SaveData("Gateway",gateway); end function SetSoftVersion(version) SaveData("Version",version); end function SetIPFromFile() if Config_Table["IpAddress"]~=nil and Config_Table["Netmask"]~=nil and Config_Table["Gateway"]~=nil then IpCfg = { ip = Config_Table["IpAddress"], netmask = Config_Table["Netmask"], gateway = Config_Table["Gateway"] } wifi.sta.setip(IpCfg); else SetIP("192.168.1.210","255.255.255.0","192.168.1.1") print("No Ip get,default to 192.168.1.210!"); end end