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. 7
      SaveData/Config.lua
  4. 83
      WifiMgr.lua

63
OLED_SSD1306.lua

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

7
SaveData/Config.lua

@ -1,3 +1,6 @@ @@ -1,3 +1,6 @@
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 @@ @@ -1,19 +1,15 @@
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");
if GetData("SSID") ~= nil or GetData("Password") ~= nil then
--WifiSaved = dofile("eus_params.lua");
ManualLink(GetData("SSID"),GetData("Password"));
else
AutoLinkByMobile();
PageAPNet();
PageSerialNet();
return nil;
end
--SampleLink
ManualLink(WifiSaved.wifi_ssid,WifiSaved.wifi_password)
end
function ManualLink(ssid,passwd)
@ -26,40 +22,18 @@ function ManualLink(ssid,passwd) @@ -26,40 +22,18 @@ function ManualLink(ssid,passwd)
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();
PageConnecting();
--OnLinkSucess();
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
--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,
@ -68,18 +42,32 @@ function SetIP(ipAddress,netmask,gateway) @@ -68,18 +42,32 @@ function SetIP(ipAddress,netmask,gateway)
}
wifi.sta.setip(IpCfg)
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);
SetIP(ipAddress,netmask,gateway);
RefeshIP(ipAddress);
end
function SetSoftVersion(version)
function SaveSoftVersion(version)
SaveData("Version",version);
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()
if Config_Table["IpAddress"]~=nil and Config_Table["Netmask"]~=nil and Config_Table["Gateway"]~=nil then
IpCfg = {
@ -93,3 +81,16 @@ function SetIPFromFile() @@ -93,3 +81,16 @@ function SetIPFromFile()
print("No Ip get,default to 192.168.1.210!");
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