Help us understand the problem. What is going on with this article?

ESP8266のNodeMcuでiFttt

More than 3 years have passed since last update.

ここをなぞって手入力でiFtttできたので、
luatool.pyでluaファイルをアップロードして実行してみる。

★pyserialをいれておく必要がある
参考

wget https://bootstrap.pypa.io/get-pip.py -O /tmp/get-pip.py
sudo python get-pip.py
sudo pip install pyserial

まずはifttt.luaファイルを作る

conn=net.createConnection(net.TCP, 0)
conn:on("receive", function(conn, payload)
print(payload) 
end) 
conn:on("connection", function(c) 
print("connected")
conn:send("GET /trigger/test/with/key/YOURKEY HTTP/1.1\r\n") 
conn:send("Host: maker.ifttt.com\r\n")
conn:send("Accept: /\r\n") 
conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.)\r\n") 
conn:send("\r\n")
end)
conn:connect(80,'maker.ifttt.com') 

luatoolでアップロードする
$ luatool.py --port /dev/ttyUSB0 --src ifttt.lua ---dest ifttt.lua --virbose

以下でもいい
luatool.py -f ifttt.lua -v

シリアルコンソールから実行
> dofile("ifttt.lua")

iPhoneに通知が来ました!

ついでに、
telnet.luaをアップロードする

telnet.lua

-- a simple telnet server
print("start simple telnet server at port 2323")
s=net.createServer(net.TCP)
s:listen(2323,function(c)
print("connected")
con_std = c
function s_output(str)
if(con_std~=nil)
then con_std:send(str)
end
end
node.output(s_output, 0) -- re-direct output to function s_ouput.
c:on("receive",function(c,l)
node.input(l) -- works like pcall(loadstring(l)) but support multiple separate line
end)
c:on("disconnection",function(c)
print("disconnected")
con_std = nil
node.output(nil) -- un-regist the redirect output function, output goes to serial
end)
end)

シリアルコンソールから実行して、
telnetで繋げてみる(netcatでもいい)

ifttt.luaを実行
サーバーとクライアントを同時にできました!

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした