Data collection
MQTT data collection
This section shows how to use OpenGate MQTT connector for data collection.
Using MQTT, your devices only need one TCP connection to exchange messages with the platform: publish collected data, receive operation requests, send operation responses, ask for pending operations, etc.
How to connect to OpenGate MQTT connector
These are the parameters to establish a MQTT connection with OpenGate:
- Host:
api.opengate.es
- Port:
1883
- User:
your-device-id
- Password:
your-api-key
Obtaining your API key
- Login onto the OpenGate web interface
- Click on the cogs that are at the top-right of the OpenGate home page
- Click on the User option
- Click on the “Click to show” link
Collecting data using mosquitto
CLI tool
mosquitto
is an open source MQTT client and server. The following example shows how to connect and publish data using OpenGate MQTT connector:
mosquitto_pub \
-h api.opengate.es -p 1883 \
-t odm/iot/your-device-id \
-u your-device-id -P you-api-key \
-m 'your-datastreams-as-json'
OpenGate default MQTT topics
- To publish collected data:
odm/iot/your-device-id
- To subscribe to incoming operations from OpenGate:
odm/request/your-device-id
- To publish operation responses:
odm/response/your-device-id
You have to replace your-device-id
with the OpenGate unique identifier of your device.
Data collection payload
The payload definition in the section HTTP integration to collect data is entirely valid. You only have to add a "device": "your-device-id"
field, filled with your OpenGate device unique identifier, at the top level of the JSON document with the collected values.
See the following example:
Publish to odm/iot/your-device-id
topic this JSON:
{
"version": "1.0.0",
"device": "your-device-id",
"datastreams": [
{
"id": "temperature",
"datapoints": [{ "value": 24.1 }]
}
]
}