-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpoll.lua
More file actions
32 lines (29 loc) · 770 Bytes
/
Copy pathpoll.lua
File metadata and controls
32 lines (29 loc) · 770 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
--poll.lua
m = mqtt.Client(id, 180, buser, bpass)
--last will and testament topic
m:lwt(lwt, "offline", 0, 0)
m:on("offline", function(conn)
--do the subscription business
print("MQTT reconnecting")
tmr.stop(0)
dofile("offline.lua")
end)
-- on publish message receive event
m:on("message", function(conn, topic, data)
if (data == "1") then
print("Kick door")
else
print("Invalid, ignoring")
end
end)
--do the subscription business
tmr.alarm(0, 1000, 1, function()
--check ip status and subscribe
if wifi.sta.status() == 5 and wifi.sta.getip() ~= nil then
tmr.stop(0)
--for secure use m:connect(broker url/ip, 8883, 1, function(conn)
m:connect(broker, 1883, 0, function(conn)
tmr.stop(4)
end)
end
end)