From 2cdd93340a09917b618d647b695ed3813463d27e Mon Sep 17 00:00:00 2001 From: "DESKTOP-B25GA9E\\W35" <1733709035@qq.com> Date: Wed, 20 Sep 2023 09:14:10 +0800 Subject: [PATCH] add save version and ip msg --- EasySave.lua | 8 ++++---- WifiMgr.lua | 29 ++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/EasySave.lua b/EasySave.lua index bbc6de8..b5921b1 100644 --- a/EasySave.lua +++ b/EasySave.lua @@ -12,12 +12,12 @@ end --Save data to config files function SaveData(key,value) - file.open("Config.lua", "w+") - + file.open("Config.lua", "w+"); Config_Table[key] = value; local tableStr = TableToStr(Config_Table); file.write(tableStr); - file.close() + file.close(); + --print(key.."-"..value.."has been Saved"); end function TableToStr(table) @@ -29,7 +29,7 @@ function TableToStr(table) end stringData = stringData:sub(1, #stringData - 2) .. "\n}\n" stringData = "Config_Table = "..stringData; - print(stringData) + --print(stringData) return stringData end diff --git a/WifiMgr.lua b/WifiMgr.lua index 9cfed5f..48a3e02 100644 --- a/WifiMgr.lua +++ b/WifiMgr.lua @@ -24,10 +24,9 @@ function ManualLink(ssid,passwd) wifi.sta.config(StationCfg) wifi.sta.connect() if wifi.sta.getip() == nil then - SetIP("192.168.1.115","255.255.255.0","192.168.1.1") - print("No Ip get,default to 192.168.1.115!"); + SetIPFromFile(); 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} PageLight(lightArr) --Service Open @@ -70,3 +69,27 @@ function SetIP(ipAddress,netmask,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