Search code examples
mqttiotgoogle-cloud-pubsubgoogle-cloud-iot

Google iot core connection status


I am using Google IOT core with mongoose os. I wanted to update device connection status to firestore. But i am unable to find event which reports mqtt connection status to pub/sub like when device disconnects or reconnect i.e if device is offline or not.

I am stuck on this problem for days.Any help will be appreciated


Solution

  • Update

    As @devunwired mentioned in this response it is now possible to monitor Stackdriver logs for disconnect events. You must have at a minimum enabled INFO level logging on your project in IoT Core > Registries > [your registry] > Edit Registry > Select "Info" log level > Click save.

    Original Response

    There are a few values you can look at that are tracked in device configuration metadata that you could use to know when a device last was online:

    1. Last Configuration Send time - sent anytime your device connects / configuration is posted
    2. Last Event Time - Last time an event was sent from the device
    3. Last State Time - Last time state was sent from the device
    4. Last Heartbeat time - Last time MQTT heartbeat was sent

    To get you started, here is an example using API explorer that you can fill-in with your project ID, region, registry, and device to query for a specific device's metadata.

    For 1...3 you have control over these through device manager and by publishing data. MQTT heartbeat is updated if your device sends an MQTT_PINGREQ message during the "ping period" without other messages getting sent.

    At any rate, you could use any of these update time values to see the last time a device was online / functioning. You could query the states of your devices after listing the devices in a registry and could update a Firebase RTDB periodically if that's how you want to report (e.g. using AppEngine TaskQueue). Note that you also just can get these "last connected" values from the Google Cloud Console.

    It was said before but we don't have an event for disconnect, just configuration ack, which generally is the connection event. If you want to share state between a device and the device manager, use state messages.