nRF5 IoT SDK
v0.9.0
|
The MQTT subscriber example is an MQTT client that connects to the broker identified by the broker address configured in the example at compile time. If the connection succeeds, it is ready to subscribe to the LED state information under the topic "led/state".
The example allows the user to unsubscribe from the topic, disconnect the MQTT client from the broker and then reconnect.
An overview of how the examples could be used are shown in the scenarios below. Scenario 1 is a complex, but possibly a real-time scenario where there are one or more publishers and subscribers. In this scenario not all MQTT clients (publishers/subscribers) have to be BLE enabled IPv6 devices; they could be computer applications and/or embedded devices, wired or wireless, that use MQTT as application protocol over the IP stack. This scenario is seen as a super-set of possible scenarios.
Scenario 2 shows a possible use case where the nRF5x SoC MQTT subscriber is used to receive messages that come from not BLE MQTT clients, such as computer applications. This scenario is realized when the mosquitto publisher application is used to test the subscriber application on the nRF5x SoC.
Scenario 3 shows a possible use case where all the MQTT clients are nRF5x devices running MQTT clients, either publisher or subscriber. This scenario is realized when the subscriber and publisher applications included in the IoT SDK are used to connect to the MQTT broker.
This section summarizes the usage of the nRF5x SoC resources and common modules in the examples apart from the IoT 6LoWPAN and lwIP stack library.
Module | Inclusion/Usage | Description |
---|---|---|
Timer | 3 | Timer for lwIP, leds and the button module. |
Button | 3 | Buttons are used to control the application. See the Overview section. |
LEDs | 4 | LEDs are used to indicate the application states. See LED assignments. |
Adv Data Encoder | Yes | The device name used is 'MQTTPublisher', IPSP Service UUID is included in the UUID list. |
Scheduler | No | Scheduler is used for processing stack events. |
UART Trace | Yes | Tracing used to help mointor state of application. |
<InstallFolder>external/lwip/license.txt
You can find the source code and project file of the example in the following folder: <InstallFolder>/examples/iot/mqtt/subscriber
LED 1 | LED 2 | Description |
---|---|---|
Blinking | Off | Device advertising as BLE peripheral. |
Off | Blinking | BLE link established, IPv6 interface down. |
On | Off | BLE link established, IPv6 interface up. |
Off | On | MQTT connection is established. |
On | On | Assertion failure in the application. |
LED 3 | LED 4 |
---|---|
On, if successfully subscribed to the LED state messages. | Toggles based on the LED state messages from the broker. |
Button | Mapped Action |
---|---|
1 | MQTT Connection Request |
2 | Subscribe/Unsubscribe from a Topic |
3 | MQTT Disconnection |
The example by default requests a secure connection on MQTT Secure port 8883. In order to disable security for MQTT clients, please follow the following setps.
Please refer to Setting up the Mosquitto MQTT broker for detailed description of setting up mostquitto in various configurations.
Since the example uses security by default, the broker shall be setup to use TLS.
This section describes how mosquitto can be used as a publisher application to test this example.
See Connecting devices to the router for a list of relevant Linux commands.