N.B.: this feature is not included in opensource version
Global information
The MQTTS protocol binding feature includes several elements:
- MQTTS client
- Request primitive buffer
For more information on the specificities of MQTT protocol binding with oneM2M standard, cf.
- MQTT protocol binding specifications (TS-0010): oneM2M specifications
- For some examples with Eclipse OM2M: Wiki Eclipse OM2M
How to use the MQTTS binding
- Configure the binding to connect to the MQTTS broker:
- configure the broker endpoint using the ENV VAR 'LOM2M_MQTTS_ENDPOINT'
- add the required Certificate, CA and private key in the 'keys.cpp'.
TBD: possibility to add dynamically the certificates and keys using ENV vars and/or dynamic provisioning.
- Enable the MQTTS binding
- check if the binding is enabled in the 'configuration.h'
- if you use LOM2M in UNIX target, set the 'LOM2M_MQTTS_BINDING' var to 1.
- OPTIONAL: if you want the MQTTS protocol to be the default one
- UNIX: set the ENV VAR 'LOM2M_DEFAULT_PROTOCOL' to 'mqtts' if needed
- ESP: set the 'HTTP_BINDING_ENABLED_DEFAULT' to 0 in the 'configuration.h' file before build
Dependencies used by the binding
The required dependencies have been integrated in install-dependencies script.
- MQTTS client: Arduino PubSubLib (Arduino PubSubClient GitHub)
- NTPClient used for connection establishment (NTPClient GitHub)
- Bear SSL (sometimes need to be built on the target) (BearSSL GitHub)
MQTTS Client
The MQTTS client is configured to connect to a secure MQTT broker (AWS IoT Core). The MQTTS client is based on the Arduino PubSubLib. (Arduino PubSubClient GitHub) At launch, if the MQTTS protocol binding feature is enabled, the MQTTS client will try to connect to the secure AWS MQTT broker. This setup phase is necessary before receiving any messages through MQTT. Once the connection is established, the client will subscribe to the relevant oneM2M topics in order to receive any requests or answers targeting the CSE.
Once the setup phase is successful, LOM2M enters the loop phase where the MQTTS client is actualized regularly to check if any messages is available on the broker. If a request is received, it is processed immediately. If this request implies a redirection or any request to be sent over (mqtt), the MQTTS client will keep looping and any other request received from the broker is stored in the request buffer.
Global behavior
The global behavior is described below. You can also find two activity diagrams describing the initialization phase and the general phase.
Activity Diagram - Initialization phase
Activity Diagram - General loop
- Setup phase / initialization: connection to the secure MQTT broker (AWS IOT CORE)
- Subscribe: subscribe to the relevant MQTT topics to receive any requests and any responses
- Loop phase: retrieving any available messages on the broker
- When a message is received it is added to the buffer.
- The first request in the buffer is treated.
- OPTIONAL: In case there is any request to send or forward, the new request is sent and LOM2M awaits for an answer. During this period, the MQTT client keeps being updated and any received request is stored in buffer.
- OPTIONAL: If a response is received, LOM2M processes the response
- Send response
- Back to initial phase