# OpenGate MQTT quick guide

This guide shows how to use OpenGate MQTT connector.

Using MQTT, your devices only need one TCP conection to exchange messages with the platform: publish collected data, receive operation requests, send operation responses, ask for on pending operations, etc.

# How to connect to OpenGate MQTT connector

These are the paratemers to stablish a MQTT connection with OpenGate:

  • Host: api.opengate.es
  • Port: 1883
  • User: your-device-id
  • Password: your-api-key
Click here to know how to obtain your API key
  1. Login onto the OpenGate web interface
  2. Click on the cogs that are at the top-right of the OpenGate home page
  3. Click on the User option
  4. Click on "Click to show" link

# Using mosquitto

mosquitto is an open source MQTT client and server. The following example show how to connect to OpenGate MQTT connector as publisher:

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.

# Payload

The payload definition in the section South HTTP OpenGate API to publish data is completely 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.



 








{
  "version": "1.0.0",
  "device": "your-device-id",
  "datastreams": [
    {
      "id": "temperature",
      "datapoints": [{ "value": 24.1 }]
    }
  ]
}