Wednesday 17 October 2018

Query MQTT?

I have a process question as I am starting to go cross eyed on this. I have a MERN app and a IOT enabled device that publishes a heartbeat message back to a device specific MQTT channel. I want to show in my Node UI whether a device is online or offline based on this heartbeat message. How would one do this?Option 1 - Create a socket.io / MQTT Subscription to the Device channel in the UI, for each heartbeat update the status to online. If I get a Offline payload, turn it to offline. The issue is I will not always get an offline unless they shut down the IOT device gracefully. Alternatives?Option 2: Add a lastknown timestamp for my Device. Force the IOT device to call a API bypassing MQTT all together (which I am using for everything else) which updates the lastknown timestamp associated to the device.. This method seems the most concrete but it's not using MQTT which is already in place and working fine.Option 3: Add a lastknown timestamp for my Device model then build a background service that will constantly monitor a MQTT subscription and on each heartbeat update the lastknown timestamp. For the UI, if the timestamp is within a minute of now then mark the device as online otherwise mark it as offline.

Submitted October 18, 2018 at 01:01AM by fender21

No comments:

Post a Comment