How to get the last state of a registered device?

Getting device telemetry via REST API and in the flespi panel.

In some tasks, you don’t need to continuously receive messages from your device — you just need its state and the last value of all parameters to answer the questions like:

  1. What was the last position of my device?

  2. When was the device online last time?

  3. What was the last value of the given sensor and when was it updated?

Telemetry is a structure that analyses each new message received by the registered device and stores the last value of each parameter and the time when it was received. Following is the principle of device telemetry operation.

device telemetry scheme in flespi device

You can get telemetry via the appropriate REST API call (GET /gw/devices/{device-selector}/telemetry/{telemetry-selector}). Telemetry will be returned as an object where the key is a parameter name, value is an object with fields value, and ts is a timestamp when the value was updated, e.g. 

     "telemetry": {
        "channel_id": {
          "ts": 1540982367,
          "value": 3300
        "chat_id": {
          "ts": 1540982367,
          "value": 168488620

It is a good practice to obtain telemetry over MQTT API:

  • Subscribe to the topic flespi/state/gw/devices/{device-id}/telemetry/+
  • Receive current Telemetry as a retain message.
  • Receive updated value for every parameter each time it changes (with MQTT 5.0 the timestamp of the parameter being updated is sent in MQTT message user properties).

Telemetry can be viewed in TrackIt:

trackit telemetry

or in the Telemetry device tab:

telemetry device tab

With the telemetry feature, you don’t need to recall the latest messages to get the device’s last state.

Please note that device telemetry values are stored for 370 days and limited by 1024 recently updated parameters. It means that if the device does not update some parameters in 370 days, these parameters will disappear from telemetry automatically. The length of parameter value (string, object or array) to be stored in telemetry is limited by 4Kb.

You can also remove certain parameters from telemetry at any time using the special REST API request (DELETE gw/devices/{device-selector}/telemetry/{telemetry-selector}) or by clicking the red cross button next to the respective parameter in the Telemetry tab.

Also, check the telemetry article on our blog.

See also
Options for viewing and exporting raw traffic data.
Options to retrieve the devices list in an account or assigned to a group, channel, plugin or stream.