Skip to content

Commit 3ec892e

Browse files
committed
prevent wedged device if AWS IoT outage
1 parent 32f497f commit 3ec892e

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/lfs/aws_iot.lua

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ local topics = settings.aws.topics
88

99
local sendTimer = tmr.create()
1010
local timeout = tmr.create()
11+
local mqttTimeout = tmr.create()
1112
local heartbeat = tmr.create()
1213

1314
timeout:register(3000, tmr.ALARM_SEMI, function()
@@ -49,6 +50,11 @@ heartbeat:register(200, tmr.ALARM_AUTO, function(t)
4950
t:interval(300000) -- 5 minutes
5051
end)
5152

53+
mqttTimeout:register(10000, tmr.ALARM_SEMI, function(t)
54+
print("Heap:", node.heap(), 'Couldn\'t connect to AWS IoT! Restarting.')
55+
node.restart()
56+
end)
57+
5258
local function startLoop()
5359
print("Heap:", node.heap(), 'Connecting to AWS IoT Endpoint:', settings.endpoint)
5460

@@ -65,6 +71,7 @@ local function startLoop()
6571
end
6672
end)
6773

74+
mqttTimeout:start()
6875
c:connect(settings.endpoint)
6976
end
7077

@@ -101,6 +108,7 @@ c:on('message', function(_, topic, message)
101108
end)
102109

103110
c:on('connect', function()
111+
mqttTimeout:stop()
104112
print("Heap:", node.heap(), "mqtt: connected")
105113
print("Heap:", node.heap(), "Subscribing to topic:", topics.switch)
106114
c:subscribe(topics.switch)

src/lfs/device.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local me = {
22
id = "uuid:8f655392-a778-4fee-97b9-4825918" .. string.format("%x", node.chipid()),
33
name = "Konnected",
44
hwVersion = "2.3.0",
5-
swVersion = "2.3.5",
5+
swVersion = "2.3.6",
66
http_port = math.floor(node.chipid()/1000) + 8000,
77
urn = "urn:schemas-konnected-io:device:Security:1"
88
}

src/lfs/mqtt_ws.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ local function Client(aws_settings)
7070
client:emit('message', parsed.topic, parsed.payload)
7171
elseif parsed.cmd == 2 then
7272
client:emit('connect')
73+
else
74+
print(parsed)
7375
end
76+
7477
end)
7578

7679
ws:on('close', function(_, status)

0 commit comments

Comments
 (0)