forked from db4linq/lua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuart.lua
More file actions
33 lines (33 loc) · 862 Bytes
/
uart.lua
File metadata and controls
33 lines (33 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
server = "192.168.1.49"
port = 5683
node_name = "Test"
uart.setup( 0, 9600, 8, 0, 1, 0 )
conn=net.createConnection(net.TCP, 0)
function print_ip()
uart.write(0,0x02)
uart.write(0,"I"..wifi.sta.getip())
uart.write(0,0x03)
end
conn:on("receive", function(conn, payload)
uart.write(0,0x02)
uart.write(0,payload)
uart.write(0,0x03)
end)
conn:on("disconnection", function()
uart.write(0,0x02)
uart.write(0,"C")
uart.write(0,0x03)
end)
conn:on("connection", function()
print_ip()
function s_output(str)
if (str.find(str, "GETIP")~=nil) then
print_ip()
else
if(c~=nil) then c:send(str) end
end
end
uart.on("data",s_output, 0)
conn:send('{ "type": 1, "data": "'.. node.chipid() .. '", "name": "'..node_name..'"}')
end)
conn:connect(port, server)