Search code examples
google-cloud-platformmqttgoogle-cloud-iot

How often does the Google IOT backend update Device State?


I am performing a GET every minute on the below URL to obtain Device State for all Devices in my IOT Registry

GET https://cloudiot.googleapis.com/v1/{name=projects/*/locations/*/registries/*/devices/*}

Once I obtain a Device, I am interested in determining if the following fields are within the last minute of the current timestamp:

  "lastHeartbeatTime": string
  "lastStateTime": string
  "lastEventTime": string

My devices are frequently pinging the remote broker, with a MQTT Keep Alive time of 10s, so I assume that's 6 heartbeats in a minute at most.

The idea is that I'd like to gather per Device statistics for Availability and Uptime metrics as well as Alerting.

All of this works, but I have a suspicion that the Google backend doesn't update the heartbeat, event and state timestamps frequently enough, sometimes leading the above setup to record stats that my devices are not up, when in fact they are.

My questions are:

  • How quickly are my device heartbeat times updated in the Device state? Is a minute too short?

  • Would you recommend a better way to achieve the above? What does that entail?


Solution

  • On closer look at the API Docs for the Device, it seems that the state can be 'stale by a few minutes'. Is there any hint of what this maximum value can be?:

    lastHeartbeatTime string (Timestamp format)

    The last time an MQTT PINGREQ was received. This field applies only to devices connecting through MQTT. MQTT clients usually only send PINGREQ messages if the connection is idle, and no other messages have been sent. Timestamps are periodically collected and written to storage; they may be stale by a few minutes.

    A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".

    lastEventTime string (Timestamp format)

    The last time a telemetry event was received. Timestamps are periodically collected and written to storage; they may be stale by a few minutes.

    A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".

    lastStateTime string (Timestamp format)

    The last time a state event was received. Timestamps are periodically collected and written to storage; they may be stale by a few minutes.

    A timestamp in RFC3339 UTC "Zulu" format, accurate to nanoseconds. Example: "2014-10-02T15:01:23.045123456Z".