-1
하나의 Esp8266을 사용하여 lua로 서버 클라이언트 응용 프로그램을 만들었습니다. 두 개의 Esp8266으로이 작업을 수행하고 싶습니다. 나는이 Esp8266 중 하나를 사용하고 싶습니다. 다른 하나는 클라이언트입니다. 첫 번째 코드는 하나의 AP에서 RSSI를 가져 오는 데 사용하고 두 번째 코드는이 RSSI를 서버에 쓰는 데 사용합니다. 어떻게이 두 코드를 두개의 Esp8266에 넣을 수 있습니까?하나의 Esp8266 클라이언트 하나의 Esp8266 서버
i=5
tmr.alarm(1,10000,1, function()
print(wifi.sta.getap(scan_cfg, 1, listap))
if i>1 then
print(i)
i=i-1
else
tmr.stop(1)
print("Timer Durdu")
end
end
)
function listap(t)
for bssid,v in pairs(t) do
local ssid = string.match(v, "([^,]+)")
l=string.format("%-10s",ssid)
stringtoarray = {}
index = 1
for value in string.gmatch(v,"%w+") do
stringtoarray [index] = value
index = index + 1
end
print(l)
print(stringtoarray[2])
end
end
scan_cfg = {}
scan_cfg.ssid = "VSP250s"
scan_cfg.bssid = "00:09:df:8e:03:b4"
scan_cfg.channel = 0
scan_cfg.show_hidden = 1
두 번째 코드 :
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
conn:on("receive", function(client,request)
local buf = "";
local _, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP");
if(method == nil)then
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP");
end
local _GET = {}
if (vars ~= nil)then
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
_GET[k] = v
end
end
buf = buf.."<!DOCTYPE html><html><div id='container'><font size='5'>"
buf = buf..'<style>body{width:auto;height:auto;background-color:#ffffff;}'
buf = buf..'.button {font-size: 20px;}</style>'
buf = buf.."<head> <meta http-equiv='refresh' content=3> "
buf = buf.."<p><h1>RSSI meter<br> ESP8266</h1>";
--buf = buf.."<p>Refresh : <a href=\"?pin=REFRESH1\"><button class='button'>ON</button></a> </p>";
--buf = buf.."<p>Relay Switch : <a href=\"?pin=ON1\"><button class='button'>ON</button></a>  "
--buf = buf.."<a href=\"?pin=OFF1\"><button class='button'>OFF</button></a><br>"
buf = buf..'<B>Voltage :<font color=red>'..string.format('%s',l)..' V</font></b><br>'
buf = buf..'<B>Current :<B><font color=blue>'..string.format('%g',stringtoarray[2])..' A</font></b><br>'
--buf = buf..'<B>Power Consumption :<B><font color=DeepSkyBlue>'..'Not Available'..'</font></b><br><BR>'
-- buf = buf..'<p>Function Button :<B><font color=BlueViolet>'..button_status..'</font></b><br></p>';
buf = buf..'</head>'
buf = buf..'<br><br><details><summary><font color=red>BURAK IPEK</font><p>'
buf = buf..'<summary><p>Vestel Electronics </p></details>'
buf = buf.."</body></font></div></html>"
client:send(buf);
client:close();
collectgarbage();
end)
end)
micropython fireware를 사용해 볼 수 있습니다. 그것은 webrepl (read-eval-print 루프)을 가지고 있으며, webrepl을 통해 esp8266으로부터 데이터를 보내고받을 수 있습니다. –
두 개의 esp8266이 있으며 각각에 다른 프로그램을 실행하려고합니다. 이것은 사소한 일입니다, 맞죠? 각 프로그램을 각각의 esp8266에 업로드하면됩니다. 그렇게하지 못하게하는 장애물이나 코드를 읽어야하는 이유를 쓰지 마십시오. –