MQTT

MQTT

This datastreams corresponds to the enabling/disabling, writing and reading of datastreams allocated into another application that communicates with the ODA through MQTT protocol.

Unlike the other datastreams, this doesn’t register the datastreams handled by configuration. This datastream configuration contains various topics in which the mqtt communication is made and where the module will subscribe when connection is achieved, having a topic for each function. To register a datastream, a message have to be sent to the enable datastream topic with the device id and the datastream id, i.e. to enable a datastream with id myDatastreamId of the device with id myDeviceId, we have to send a message to the topic oda/enable/myDeviceId/myDatastreamId.

The explained format is common in all the topics for all the functions. To operate on a datastream, we use the next topic format:

expectedTopic/deviceId/datastreamId

To access source code click here.

Dependencies

This module requires the following modules:

  • MQTT Comms: Provide an implementation of MQTT Client Factory that the datastream module need to connect to the MQTT broker to provide information of each datastream and allow the operations.
  • CBOR Serializer: Needed to transform the incoming messages to be readables by the modules and to serialize the outgoing payloads.
  • Event Publisher: Used to handle the incoming events and send it.

Configuration

To configure I2C Datastream module, a file named es.amplia.oda.datastreams.mqtt.cfg must be created with the next parameters:

  • brokerURI: Required parameter. Direction where the MQTT client have to connect.
  • clientId: selected at random by default. Identifier that the module client will have to connect to the broker
  • enableDatastreamTopic: Required parameter. Topic where ODA expects the enables messages to be sent.
  • disableDatastreamTopic: Required parameter. Topic where ODA expects the disables messages to be sent.
  • eventTopic: Required parameter. Topic where ODA expects the events messages to be sent.
  • readRequestTopic: Required parameter. Topic where ODA will send the request of reading operations.
  • readResponseTopic: Required parameter. Topic where ODA expects the responses of read operations to be sent.
  • writeRequestTopic: Required parameter. Topic where ODA will send the request of writing operations.
  • writeResponseTopic: Required parameter. Topic where ODA expects the responses of write operations to be sent.
  • lwtTopic: Required parameter. Topic where ODA expects the Last Will messages of another devices clients to be sent.

es.amplia.oda.datastreams.mqtt.cfg. will have a similar format to:

brokerURI=tcp://localhost:1883
clientId=oda
enableDatastreamTopic=oda/enable
disableDatastreamTopic=oda/disable
eventTopic=oda/event
readRequestTopic=oda/operation/read/request
readResponseTopic=oda/operation/read/response
writeRequestTopic=oda/operation/write/request
writeResponseTopic=oda/operation/write/response
lwtTopic=oda/lwt

Using the previous configuration example, ODA will use the next topics for the datastream “tempInCelsius” of the device “thermoDev”:

Function Topic used by oda
enable oda/enable/thermoDev/tempInCelsius
disable oda/disable/thermoDev/tempInCelsius
event oda/event/thermoDev/tempInCelsius
readRequest oda/operation/read/request/thermoDev/tempInCelsius
readResponse oda/operation/read/response/thermoDev/tempInCelsius
writeRequest oda/operation/write/request/thermoDev/tempInCelsius
writeResponse oda/operation/write/response/thermoDev/tempInCelsius
lwt oda/lwt/thermoDev/tempInCelsius