You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.4 KiB
97 lines
2.4 KiB
1 year ago
|
StationCfg = {}
|
||
|
IpCfg = {}
|
||
|
|
||
1 year ago
|
--Load Config.lua and get value from Config_Table
|
||
1 year ago
|
function AutoLink()
|
||
1 year ago
|
if GetData("SSID") ~= nil or GetData("Password") ~= nil then
|
||
|
--WifiSaved = dofile("eus_params.lua");
|
||
|
ManualLink(GetData("SSID"),GetData("Password"));
|
||
1 year ago
|
else
|
||
1 year ago
|
PageSerialNet();
|
||
1 year ago
|
return nil;
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function ManualLink(ssid,passwd)
|
||
1 year ago
|
wifi.setmode(wifi.STATION)
|
||
1 year ago
|
StationCfg.ssid=ssid
|
||
|
StationCfg.pwd=passwd
|
||
1 year ago
|
StationCfg.save=false
|
||
1 year ago
|
wifi.sta.config(StationCfg)
|
||
|
wifi.sta.connect()
|
||
1 year ago
|
if wifi.sta.getip() == nil then
|
||
1 year ago
|
SetIPFromFile();
|
||
1 year ago
|
end
|
||
1 year ago
|
PageConnecting();
|
||
|
--OnLinkSucess();
|
||
1 year ago
|
print(wifi.sta.status());
|
||
1 year ago
|
--regist
|
||
|
wifi.eventmon.register(wifi.eventmon.STA_CONNECTED, function(T)
|
||
|
OnLinkSucess();
|
||
|
end)
|
||
|
wifi.eventmon.register(wifi.eventmon.STA_DISCONNECTED, function(T)
|
||
|
OnLinkFailed(T.reason);
|
||
|
end)
|
||
1 year ago
|
end
|
||
|
|
||
|
function SetIP(ipAddress,netmask,gateway)
|
||
|
IpCfg = {
|
||
|
ip = ipAddress,
|
||
|
netmask = netmask,
|
||
|
gateway = gateway
|
||
|
}
|
||
|
wifi.sta.setip(IpCfg)
|
||
|
end
|
||
1 year ago
|
|
||
1 year ago
|
--SetIP("192.168.1.115","255.255.255.0","192.168.1.1")
|
||
1 year ago
|
function SaveIP(ipAddress,netmask,gateway)
|
||
|
SaveData("IpAddress",ipAddress);
|
||
|
SaveData("Netmask",netmask);
|
||
|
SaveData("Gateway",gateway);
|
||
1 year ago
|
SetIP(ipAddress,netmask,gateway);
|
||
|
RefeshIP(ipAddress);
|
||
1 year ago
|
end
|
||
|
|
||
1 year ago
|
function SaveSoftVersion(version)
|
||
1 year ago
|
SaveData("Version",version);
|
||
|
end
|
||
|
|
||
1 year ago
|
function SaveWifiInfo(ssid,passwd)
|
||
|
if GetData("SSID") == nil or GetData("Password") == nil then
|
||
|
SaveData("SSID",ssid);
|
||
|
SaveData("Password",passwd);
|
||
|
AutoLink();
|
||
|
else
|
||
|
SaveData("SSID",ssid);
|
||
|
SaveData("Password",passwd);
|
||
|
end
|
||
|
|
||
|
end
|
||
|
|
||
1 year ago
|
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
|
||
1 year ago
|
|
||
|
|
||
|
function OnLinkSucess()
|
||
|
PageMainScene(StationCfg.ssid,wifi.sta.getip(),Config_Table["Version"]);
|
||
|
local lightArr = {[1]=false,[2]=false,[3]=false,[4]=false}
|
||
|
PageLight(lightArr)
|
||
|
--Service Open
|
||
|
StartUDPService();
|
||
|
end
|
||
|
|
||
|
function OnLinkFailed(reason)
|
||
|
PageConnectFaild(reason);
|
||
|
end
|