Subscribing to Device Measurement Messages

In some cases, you would like to get a single or multi device measurement messages.
For example, you would like to analyze the device measurements in real time, or you would like to create a screen that shows the latest measurements from a list of selected 20 devices.
In both cases, you'll need to subscribe to MQTT measurement topics and act upon the messages that you receive.

BioT allows you to so by following these steps:

  1. Get temporary AWS credentials
  2. Connect to AWS MQTT broker
  3. Subscribe to an MQTT topic

Get temporary AWS credentials

Make the following API call:

GET https://your-biot-domain.com/device/v2/credentials/organization

You will get the following response:

{
  "endpoint": "string",
  "credentials": {
    "accessKeyId": "string",
    "secretAccessKey": "string",
    "sessionToken": "string",
    "expiration": "2022-09-06T07:22:56.106Z"
  },
  "topic": "string"
}

Connect to AWS MQTT broker

Using the credentials acquired in step 1 connect to AWS MQTT broker.
BioT recommend using the official AWS IoT SDK for this purpose.

Subscribe to an MQTT topic

In step 1 the topic is a topic that will be formatted:
'[ownerOrganizationId]/+/+

The following table describes the topic structure and how it can be modified:

Parameter

Description

ownerOrganizationId

The unique organization ID.
This value should be changed and is based on the organization of the user that made the actual "get credentials" API call.

First +

The first + represents the deviceId and can be changed to any deviceId in the organization, this topic will include only messages from that device. Keeping the+ can be used to listen to all devices in the organization.

Second +

The second + represents notification type and can be changed, this topic will include only messages from that notification type.
This is an internal parameter, and you should keep it as +when subscribing to a topic.

For example, the topic d5399edb-cc47-4485-b3c8-4bcede9538b2/myDevice/+
Will listen to all type of events that myDevice will produce under the organization with IDd5399edb-cc47-4485-b3c8-4bcede9538b2


Did this page help you?