Browse Source

changed protocol to New

master
jkpete 7 months ago
parent
commit
568370b762
  1. 2
      README.md
  2. 6
      Src/OLED_SSD1306.lua
  3. 82
      Src/UDPService.lua

2
README.md

@ -140,3 +140,5 @@ ESP8266+数据线与PC进行链接。 @@ -140,3 +140,5 @@ ESP8266+数据线与PC进行链接。
# 4.通讯协议📡
该设备使用UDP作为通讯协议,UDP地址为上面配置的ip地址,端口号默认为6000。
https://www.processon.com/view/link/67407595a1c0ad5bcd730768?cid=6740188e59efb87d34212ad8 访问密码:6KYl

6
Src/OLED_SSD1306.lua

@ -24,7 +24,7 @@ end @@ -24,7 +24,7 @@ end
function PageLoading(progress)
Disp:clearBuffer();
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(40,10,"DYTech");
Disp:drawStr(40,10,"BYTech");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(16,32,"Check for update");
Disp:drawFrame(12,42,104,10);
@ -35,10 +35,10 @@ end @@ -35,10 +35,10 @@ end
function DrawMainScene(wifiName,ipAddress,version)
--Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:setFont(u8g2.font_unifont_t_symbols);
Disp:drawStr(40,10,"DYTech");
Disp:drawStr(40,10,"BYTech");
Disp:setFont(u8g2.font_6x10_tf);
Disp:drawStr(0,26,"Wifi:"..wifiName);
Disp:drawStr(0,36,"Light Ctrl-UDP"..version);
Disp:drawStr(0,36,"Car Ctrl-UDP"..version);
Disp:drawStr(0,46,"S:"..ipAddress..":5000");
end

82
Src/UDPService.lua

@ -2,11 +2,11 @@ require("GPIO"); @@ -2,11 +2,11 @@ require("GPIO");
function StartUDPService()
if UDPSocket == nil then
UDPSocket = net.createUDPSocket();
UDPSocket:listen(5000);
UDPSocket:listen(6000);
UDPSocket:on("receive", UDPService);
UDPPort, UDPIP = UDPSocket:getaddr();
else
UDPSocket:listen(5000);
UDPSocket:listen(6000);
UDPSocket:on("receive", UDPService);
UDPPort, UDPIP = UDPSocket:getaddr();
end
@ -19,19 +19,75 @@ function UDPService(s, data, port, ip) @@ -19,19 +19,75 @@ function UDPService(s, data, port, ip)
table.insert(commandSet,word);
end
print("get data count" .. #commandSet);
if string.match(data,"^Light") then
if #commandSet==3 then
print(tonumber(commandSet[2]).."-"..commandSet[3])
if commandSet[3]=="On" and tonumber(commandSet[2])~=nil then
GPIOOn(tonumber(commandSet[2]));
s:send(port, ip, "Light "..commandSet[2].." "..commandSet[3]);
elseif commandSet[3]=="Off" and tonumber(commandSet[2])~=nil then
GPIOOff(tonumber(commandSet[2]));
s:send(port, ip, "Light "..commandSet[2].." "..commandSet[3]);
else
s:send(port, ip, "CommandFaild");
-- if string.match(data,"^Light") then
-- if #commandSet==3 then
-- print(tonumber(commandSet[2]).."-"..commandSet[3])
-- if commandSet[3]=="On" and tonumber(commandSet[2])~=nil then
-- GPIOOn(tonumber(commandSet[2]));
-- s:send(port, ip, "Light "..commandSet[2].." "..commandSet[3]);
-- elseif commandSet[3]=="Off" and tonumber(commandSet[2])~=nil then
-- GPIOOff(tonumber(commandSet[2]));
-- s:send(port, ip, "Light "..commandSet[2].." "..commandSet[3]);
-- else
-- s:send(port, ip, "CommandFaild");
-- end
-- end
-- end
if string.match(data,"^Go") then
if #commandSet==2 then
print(tonumber(commandSet[2]))
Is_AutoClose = false;
GPIOOn(0);
GPIOOn(1);
GPIOOn(2);
s:send(port, ip, "1-1-1");
end
end
if string.match(data,"^Back") then
if #commandSet==2 then
print(tonumber(commandSet[2]))
Is_AutoClose = false;
GPIOOn(0);
GPIOOff(1);
GPIOOn(2);
s:send(port, ip, "1-0-1");
end
end
if string.match(data,"^Stop") then
Is_AutoClose = false;
GPIOOff(0);
GPIOOn(1);
GPIOOff(2);
s:send(port, ip, "0-1-0");
end
if string.match(data,"^Ready") then
Is_AutoClose = false;
GPIOOff(0);
GPIOOn(1);
GPIOOn(2);
s:send(port, ip, "0-1-1");
end
if string.match(data,"^Status") then
local result = "";
if(LightArr[0] == true){
result = "1-"
}else{
result = "0-"
}
if(LightArr[1] == true){
result = result .. "1-"
}else{
result = result .. "0-"
}
if(LightArr[2] == true){
result = result .. "1"
}else{
result = result .. "0"
}
s:send(port, ip, result);
end
if string.match(data,"^Addr") then
s:send(port, ip, "Addr-"IpCfg.ip);
end
end

Loading…
Cancel
Save