MQTT Client Example¶
Description¶
This example demonstrates the use of the Wi-Fi module with the Pitaya Go board to implement an MQTT client using the MQTT protocol.
For more about MQTT, see the MQTT Version 3.1.1 Specification.
This example also implements the Command Line Interface over BLE NUS and USB CDC ACM. Both consoles can be opened and used independently.
Tip
Before you start building, remember to set up the nRF5 SDK development environment first. See Setup the nRF5 SDK for details.
Building the example¶
You can find the source code and the project file of the example in the following folder: pitaya-go/examples/wifi/mqtt_client_example.
Open terminal and navigate to the directory with the example Makefile:
cd ./pitaya-go/examples/wifi/mqtt_client_example/armgcc
Run make
to build the example:
make
Programming the firmware¶
If compiled successfully, the firmware is located in mqtt_client_example/armgcc/_build
with the name nrf52840_xxaa.hex
.
While pushing the USER button, press the RESET button to enter the DFU mode. Then program the firmware using the nRF Connect for Desktop tool.
If the SoftDevice is not programmed before, remember to add the SoftDevice. The SoftDevice is located in <nRF5 SDK>/components/softdevice/s140/hex/s140_nrf52_6.1.0_softdevice.hex
.
Tip
See Programming section for details about how to program your Pitaya Go.
Testing¶
The application is now programmed and running. Perform the following steps to test the MQTT client:
-
Run a terminal application like PuTTY or screen:
screen /dev/cu.usbmodemD2E39D222D781 115200
-
Press Enter in the terminal. A console prompt is displayed.
-
Use the Tab key to print the available commands.
-
Use command
wifi connect {SSID} {PSK}
to connect to your AP. The parameters stand for the following:{SSID}
: The name of AP. If not specified, the device will attempt to reconnect to the last-associated AP.{PSK}
: The passphrase of AP. MUST be 8 characters or more. If it's an Open network, it can be left blank.
-
Observe that BLUE LED is lit, that is, the Wi-Fi is connected.
-
Use command
mqtt connect iot.eclipse.org
to connect the MQTT broker. -
Use command
mqtt sub pitayago
to subscribe the topicpitayago
. -
Use command
mqtt pub pitayago "Hello World!"
to publishHello World!
to the topicpitayago
. Observe that the message should be received. -
Head to https://www.eclipse.org/paho/clients/js/utility/, connect the same broker and publish a message to the same topic above. Observe that Pitaya Go will receive the message.
-
You can also use the Web Device CLI application to test this example.
Reference¶
Create an Issue¶
Interested in contributing to this project? Want to report a bug? Feel free to click here: