2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ESP8266のNodeMcuでiFttt

Last updated at Posted at 2015-09-16

ここをなぞって手入力で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を実行
サーバーとクライアントを同時にできました!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?