Browse Source

add save version and ip msg

master
DESKTOP-B25GA9E\W35 1 year ago
parent
commit
2cdd93340a
  1. 8
      EasySave.lua
  2. 29
      WifiMgr.lua

8
EasySave.lua

@ -12,12 +12,12 @@ end
--Save data to config files --Save data to config files
function SaveData(key,value) function SaveData(key,value)
file.open("Config.lua", "w+") file.open("Config.lua", "w+");
Config_Table[key] = value; Config_Table[key] = value;
local tableStr = TableToStr(Config_Table); local tableStr = TableToStr(Config_Table);
file.write(tableStr); file.write(tableStr);
file.close() file.close();
--print(key.."-"..value.."has been Saved");
end end
function TableToStr(table) function TableToStr(table)
@ -29,7 +29,7 @@ function TableToStr(table)
end end
stringData = stringData:sub(1, #stringData - 2) .. "\n}\n" stringData = stringData:sub(1, #stringData - 2) .. "\n}\n"
stringData = "Config_Table = "..stringData; stringData = "Config_Table = "..stringData;
print(stringData) --print(stringData)
return stringData return stringData
end end

29
WifiMgr.lua

@ -24,10 +24,9 @@ function ManualLink(ssid,passwd)
wifi.sta.config(StationCfg) wifi.sta.config(StationCfg)
wifi.sta.connect() wifi.sta.connect()
if wifi.sta.getip() == nil then if wifi.sta.getip() == nil then
SetIP("192.168.1.115","255.255.255.0","192.168.1.1") SetIPFromFile();
print("No Ip get,default to 192.168.1.115!");
end end
PageMainScene(ssid,wifi.sta.getip(),"V1.0"); PageMainScene(ssid,wifi.sta.getip(),Config_Table["Version"]);
local lightArr = {[1]=false,[2]=false,[3]=false,[4]=false} local lightArr = {[1]=false,[2]=false,[3]=false,[4]=false}
PageLight(lightArr) PageLight(lightArr)
--Service Open --Service Open
@ -70,3 +69,27 @@ function SetIP(ipAddress,netmask,gateway)
wifi.sta.setip(IpCfg) wifi.sta.setip(IpCfg)
end end
--SetIP("192.168.1.115","255.255.255.0","192.168.1.1") --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

Loading…
Cancel
Save