Browse Source

change net type

master
DESKTOP-B25GA9E\W35 1 year ago
parent
commit
46518c5d9f
  1. 63
      OLED_SSD1306.lua
  2. 30
      OldCode/AutoWifi.lua
  3. 5
      SaveData/Config.lua
  4. 83
      WifiMgr.lua

63
OLED_SSD1306.lua

@ -9,24 +9,20 @@ print("Oled Init Success!");
Screen_WIFINAME = ""; Screen_WIFINAME = "";
Screen_IPADDRESS = ""; Screen_IPADDRESS = "";
Screen_VERSION = ""; Screen_VERSION = "";
--tips to user link-AP Screen_LightArr = {}
function PageAPNet() --tips user use pc tools to link-AP
function PageSerialNet()
Disp:clearBuffer() Disp:clearBuffer()
--Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:setFont(u8g2.font_unifont_t_symbols); Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(0,10,"AP-LinkMode"); Disp:drawStr(0,10,"Serial-LinkMode");
Disp:setFont(u8g2.font_6x10_tf); Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,"Please use your"); Disp:drawStr(0,26,"Open NetTools.exe ");
Disp:drawStr(0,36,"mobile phone search"); Disp:drawStr(0,36,"input ssid and pwd.");
Disp:drawStr(0,46,"and link ap-point");
Disp:drawStr(0,56,"DY-Light-Controller");
Disp:updateDisplay(); Disp:updateDisplay();
end end
--progress:1-100,tips loading and update from server --progress:1-100,tips loading and update from server
function PageLoading(progress) function PageLoading(progress)
Disp:clearBuffer(); Disp:clearBuffer();
--Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:setFont(u8g2.font_unifont_t_symbols); Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(40,10,"DYTech"); Disp:drawStr(40,10,"DYTech");
Disp:setFont(u8g2.font_6x10_tf); Disp:setFont(u8g2.font_6x10_tf);
@ -36,14 +32,13 @@ function PageLoading(progress)
Disp:updateDisplay(); Disp:updateDisplay();
end end
--
function PageMainScene(wifiName,ipAddress,version) function PageMainScene(wifiName,ipAddress,version)
Disp:clearBuffer();
DrawMainScene(wifiName,ipAddress,version)
Disp:updateDisplay();
Screen_WIFINAME = wifiName; Screen_WIFINAME = wifiName;
Screen_IPADDRESS = ipAddress; Screen_IPADDRESS = ipAddress;
Screen_VERSION = version; Screen_VERSION = version;
Disp:clearBuffer();
DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION)
Disp:updateDisplay();
--Disp:sendBuffer(); --Disp:sendBuffer();
end end
@ -57,23 +52,47 @@ function DrawMainScene(wifiName,ipAddress,version)
Disp:drawStr(0,46,"S:"..ipAddress..":5000"); Disp:drawStr(0,46,"S:"..ipAddress..":5000");
end end
function PageLight(lightArr) function DrawLight(lightArr)
Disp:clearBuffer();
DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION);
Disp:drawCircle(16,56,4,u8g2.U8G2_DRAW_ALL); Disp:drawCircle(16,56,4,u8g2.U8G2_DRAW_ALL);
Disp:drawCircle(32,56,4,u8g2.U8G2_DRAW_ALL); Disp:drawCircle(32,56,4,u8g2.U8G2_DRAW_ALL);
Disp:drawCircle(48,56,4,u8g2.U8G2_DRAW_ALL); Disp:drawCircle(48,56,4,u8g2.U8G2_DRAW_ALL);
Disp:drawCircle(64,56,4,u8g2.U8G2_DRAW_ALL); Disp:drawCircle(64,56,4,u8g2.U8G2_DRAW_ALL);
Screen_LightArr = lightArr;
for index, value in ipairs(lightArr) do for index, value in ipairs(lightArr) do
if value then if value then
Disp:drawDisc(16*index,56,4,u8g2.U8G2_DRAW_ALL); Disp:drawDisc(16*index,56,4,u8g2.U8G2_DRAW_ALL);
end end
end end
end
function PageLight(lightArr)
Disp:clearBuffer();
DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION);
DrawLight(lightArr);
Disp:sendBuffer(); Disp:sendBuffer();
--Disp:updateDisplayArea(0,0,64,64);
end end
--PageMainScene("DF2","192.168.1.115","V1.0") function RefeshIP(ipAddress)
--local lightArr = {[1]=true,[2]=false,[3]=true,[4]=true} Screen_IPADDRESS = ipAddress;
--PageLight(lightArr) Disp:clearBuffer();
--PageAPNet() DrawMainScene(Screen_WIFINAME,Screen_IPADDRESS,Screen_VERSION);
DrawLight(Screen_LightArr);
Disp:sendBuffer();
end
function PageConnecting()
Disp:clearBuffer()
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,10,"Connecting to internet");
Disp:drawStr(0,36,"Waiting...");
Disp:updateDisplay();
end
function PageConnectFaild(reason)
Disp:clearBuffer()
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(0,10,"Connect Failed");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,reason);
Disp:updateDisplay();
end

30
OldCode/AutoWifi.lua

@ -0,0 +1,30 @@
--tips to user link-AP
function PageAPNet()
Disp:clearBuffer()
--Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(0,10,"AP-LinkMode");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,"Please use your");
Disp:drawStr(0,36,"mobile phone search");
Disp:drawStr(0,46,"and link ap-point");
Disp:drawStr(0,56,"DY-Light-Controller");
Disp:updateDisplay();
end
--mobile setting ap and passwd
function AutoLinkByMobile()
wifi.sta.clearconfig();
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

5
SaveData/Config.lua

@ -1,3 +1,6 @@
Config_Table = { Config_Table = {
["Version"]="V0.1" ["IpAddress"]="192.168.1.210",
["Gateway"]="192.168.1.1",
["Version"]="V0.1",
["Netmask"]="255.255.255.0"
} }

83
WifiMgr.lua

@ -1,19 +1,15 @@
StationCfg = {} StationCfg = {}
IpCfg = {} IpCfg = {}
WifiSaved = {}
--Load Config.lua and get value from Config_Table --Load Config.lua and get value from Config_Table
function AutoLink() function AutoLink()
--get key from eus_params.lua if GetData("SSID") ~= nil or GetData("Password") ~= nil then
if Files["eus_params.lua"] then --WifiSaved = dofile("eus_params.lua");
WifiSaved = dofile("eus_params.lua"); ManualLink(GetData("SSID"),GetData("Password"));
else else
AutoLinkByMobile(); PageSerialNet();
PageAPNet();
return nil; return nil;
end end
--SampleLink
ManualLink(WifiSaved.wifi_ssid,WifiSaved.wifi_password)
end end
function ManualLink(ssid,passwd) function ManualLink(ssid,passwd)
@ -26,40 +22,18 @@ function ManualLink(ssid,passwd)
if wifi.sta.getip() == nil then if wifi.sta.getip() == nil then
SetIPFromFile(); SetIPFromFile();
end end
PageMainScene(ssid,wifi.sta.getip(),Config_Table["Version"]); PageConnecting();
local lightArr = {[1]=false,[2]=false,[3]=false,[4]=false} --OnLinkSucess();
PageLight(lightArr)
--Service Open
StartUDPService();
print(wifi.sta.status()); print(wifi.sta.status());
--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)
end 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) function SetIP(ipAddress,netmask,gateway)
IpCfg = { IpCfg = {
ip = ipAddress, ip = ipAddress,
@ -68,18 +42,32 @@ 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) function SaveIP(ipAddress,netmask,gateway)
SaveData("IpAddress",ipAddress); SaveData("IpAddress",ipAddress);
SaveData("Netmask",netmask); SaveData("Netmask",netmask);
SaveData("Gateway",gateway); SaveData("Gateway",gateway);
SetIP(ipAddress,netmask,gateway);
RefeshIP(ipAddress);
end end
function SetSoftVersion(version) function SaveSoftVersion(version)
SaveData("Version",version); SaveData("Version",version);
end end
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
function SetIPFromFile() function SetIPFromFile()
if Config_Table["IpAddress"]~=nil and Config_Table["Netmask"]~=nil and Config_Table["Gateway"]~=nil then if Config_Table["IpAddress"]~=nil and Config_Table["Netmask"]~=nil and Config_Table["Gateway"]~=nil then
IpCfg = { IpCfg = {
@ -93,3 +81,16 @@ function SetIPFromFile()
print("No Ip get,default to 192.168.1.210!"); print("No Ip get,default to 192.168.1.210!");
end end
end end
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

Loading…
Cancel
Save