2016-06-21 4 views
-1

1つのEsp8266を使用してluaでサーバークライアントアプリケーションを実行しました。私は2つのEsp8266でこれをやりたい私はこれらのEsp8266の1つをServerと使い、もう1つはClientです。 1つのAPからRSSIを取得する場合は最初のコードを、2番目のコードではこれらのRSSIを1つのサーバーに書き込む場合に使用します。この2つのコードを2つのEsp8266にどのように置くことができますか?1つのEsp8266クライアント1つの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>&nbsp</p>"; 
    --buf = buf.."<p>Relay Switch  : <a href=\"?pin=ON1\"><button class='button'>ON</button></a>&emsp;&emsp;" 
    --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) 
+0

micropython firewareを試すことができます。それはwebrepl(read-eval-printループ)を持ち、webreplを介してesp8266からデータを送受信できます。 –

+0

2つのesp8266があり、それぞれに異なるプログラムを実行する必要があります。これは簡単ではないでしょうか?各プログラムをそれぞれのesp8266にアップロードするだけです。あなたがそうすることを妨げるどんな障害に直面しているのか、誰があなたのコードを読んでいるのかを書いてはいけません。 –

答えて

0

のluaファイルに各コードを入れてください。 init.luaと入力の両方を含む

dofile("client.lua"); 
dofile("server.lua"); 

もっと簡単にするには、メソッドを記述します。

幸運。