2016-10-10 16 views
1

ESP8266 12E NODE MCU開発キットのシリアルポートを介してarduinoシリアルポートにデータを送信しようとしています。LUAプログラミング、ESP8266 NODEMCUシリアル通信

使用している構文の例を見つけようとしていて、arduino経由でserial.print()を使ってデータを送信しようとしましたが、動作していますが、これをLuaで達成する方法がわかりません。すべてのヘルプは

を高く評価され

私はSSIDとパスワードのフォームarduinoの

INIT.luaを得ることができます

SSID = "XXXX" 
Password = "XXXX" 
wifi.setmode(wifi.STATION) 
wifi.sta.config(SSID,Password) -- Replace with your AP Name and security key. 
wifi.sta.connect() 
tmr.alarm(1, 1000, 1, function() 
if wifi.sta.getip()== nil then 
print("Obtaining IP...") 
else 
tmr.stop(1) 
print("Got IP. "..wifi.sta.getip()) 
dofile("LED_on_off.lua") 

end 

end) 

LED_ON_OFFのLUA

print(wifi.sta.getip()) 

led2 = 4 
gpio.mode(led1, gpio.OUTPUT) 
gpio.mode(led2, gpio.OUTPUT) 
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.."<h1> ESP8266 Web Server</h1>"; 

     buf = buf.."<p>GPIO2 <a href=\"?pin=ON2\"><button>ON</button></a>&nbsp;<a href=\"?pin=OFF2\"><button>OFF</button></a></p>"; 
     local _on,_off = "","" 
     if(_GET.pin == "OFF2")then 
       gpio.write(led2, gpio.HIGH); 
     elseif(_GET.pin == "ON2")then 

**********Here i would like to send data ot arduini that pin is swithced oN ************ 

       gpio.write(led2, gpio.LOW); 
     end 
     client:send(buf); 
     client:close(); 
     collectgarbage(); 
    end) 
end) 

答えて

2

NodeMCUのドキュメントをお読みください。

https://nodemcu.readthedocs.io/en/master/

特に

https://nodemcu.readthedocs.io/en/master/en/modules/uart/

それはすべてあります。あなたは例を見つける必要はありません。あなたは文書を読んで理解することを学ばなければなりません。ドキュメントを読むことなく、適切なプログラミングはありません。

arduinoには、デジタル出力を使用してarduino入力に接続することもできますが、1つのことが起こったことだけを伝えたい場合は、それは簡単で愚かなままにしておきます。

+0

ありがとう –