MQTT

MQTT

This connector enable communication via MQTT Protocol.

Allows to send data to the OpenGate platform and receive operations from it.

Dependencies

This module requires the following modules:

  • Core commons: Provides many interfaces that this module will use
  • Mqtt Communications Module: Needed to create the MQTT client that will connects to the MQTT broker of the third system.
  • Dispatcher: Needed to process the payloads and de/serialize its content.
  • Device Info Provider: Needed to know the Device Id of the device that are running the Agent, and the API Key to access to OpenGate. Both data are required to achieve a connection with OpenGate and transferred data will have the deviceId in its metadata.

Configuration

To configure MQTT connector, a file named es.amplia.oda.connector.mqtt.cfg must be created with the next parameters:

  • host: Required parameter. Specify the direction of the third system the connector have to send the data. ’localhost’ is a good host to do tests with.

  • port: 1883 by default. Port though the connector have to connect to the host.

  • securePort: 8883 by default. Alternative port to connect securely.

  • secure: false by default. True to connect to the secure port, false to connect to common port.

  • skipVerify: false by default. True to connect without secure certificate verification (if secure = true).

  • mqttVersion: MQTT_3_1_1 by default. Available options are MQTT_3_1, MQTT_3_1_1. MQTT version that connector has to use.

  • keepAliveInterval: 60 by default. Interval defined by MQTT client to communicate a keep alive message before to disconnect.

  • maxInFlight: 10 by default. Maximum messages that can be queued to be transmitted simultaneously.

  • cleanSession: true by default. To specify if the connection is persistent (false) or not (true). If clean session is true, the broker doesn’t store information or messages.

  • connectionTimeout: 30 by default. Time that client will wait to achieve the connection.

  • automaticReconnect: true by default. If the connection fails and this option is true, enable the option to reconnect with the broker.

  • lwt.topic: null if not specified. Topic where the client will receive all Last Will messages from another clients. Last Will messages are a pre-agreed message between the client, and the broker to send to the other clients in case of an unexpected disconnection.

  • lwt.payload: null if not specified. LWT Payload is the data that the client will agree with the broker to send to another clients in case of connector’s client be disconnected unexpectedly.

  • lwt.qos: 1 by default, if topic and payload are specified, will be 1 by default. Specify the qos of the LWT.

  • lwt.retained: null if not specified, if topic and payload are specified, will be false by default. Specifies if the broker will send to the another clients the LW messages even when that clients connect to the broker after the connector’s client disconnect unexpectedly.

  • keyStore.path: null if not specified. Directory where the file of keys will be stored.

  • keyStore.type: null if not specified, if keyStore and trustStore path and password are specified, is JKS by default. The available options are: JKS, JCEKS, PKCS12, PKCS11, DKS, WINDOWS_MY, BKS. Is the type of the KeyStore that the connector will use.

  • keyStore.password: null if not specified. Password to access to the KeyStore.

  • keyManager.algorithm: null if not specified, *if keyStore and trustStore path and password are specified, is SunX509 by default. Available options are PKIX, SUN_X509, SUN_JSSE. Specify the algorithm used to handle the keys.

  • trustStore.path: null if not specified. Directory where the file of trust keys will be stored.

  • trustStore.type: null if not specified, if keyStore and trustStore path and password are specified, is JKS by default. The available options are: JKS, JCEKS, PKCS12, PKCS11, DKS, WINDOWS_MY, BKS. Is the type of the TrustStore that the connector will use.

  • trustStore.password: null if not specified. Password to access to the TrustStore.

  • trustManager.algorithm: null if not specified, *if keyStore and trustStore path and password are specified, is SunX509 by default. Available options are PKIX, SUN_X509, SUN_JSSE. Specify the algorithm used to handle the keys.

  • topic.iot: Required parameter. The topic to which the data transferred will be sent to the third-system (e.g. OpenGate).

  • topic.request: Required parameter. The topic to which the operations will be sent from the third-system to the ODA for processing.

  • topic.response: Required parameter. The topic to which the operations responses will be sent from the ODA to the third-system.

  • message.qos: 1 by default. This parameter can be 0, 1 or 2. QOS that will have the messages sent by connector’s client. QOS is the level agreed between client and broker to ensure the delivery of the message.

    • qos = 0 - at most once - Message is delivered at most once. Its delivery is not acknowledged. It may not be delivered at all. Fastest method.
    • qos = 1 - at least once - Message is always delivered at least once. It might be delivered multiple times.
    • qos = 2 - exactly once - Message is always delivered exactly once. Safest method but slowest.
  • message.retained: false by default. If is true, the last message sent to broker will be sent to another clients even if those clients connects after the message was sent.

  • connection.initialDelay: 0 by default. Time wait by the connector’s client to try the initial connection to the broker.

  • connection.retryDelay: 300 by default. If first try fails, time that the connector’s client will wait before the next try to connect.

The file es.amplia.oda.connector.mqtt.cfg could have a lot of parameters, but it can works correctly with the next parameters:

host=localhost
topic.request=odm/request
topic.response=odm/response
topic.iot=odm/iot
message.qos=1

Source Code

You can check the source code here