Subscribing to Device Measurement Messages
In some cases, you want to get single or multi device measurement messages.
For example, if you want to analyze the device measurements in real time, or you want to create a screen that shows the latest measurements from a list of 20 selected devices.
In both cases, you need to subscribe to MQTT measurement topics and act upon the messages you receive.
BioT allows you to so by following these steps:
- Get temporary AWS credentials
- Connect to AWS MQTT broker
- 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 the AWS MQTT broker.
BioT recommends 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
produces under the organization with IDd5399edb-cc47-4485-b3c8-4bcede9538b2
Updated 11 months ago