nRF9160: Simple MQTT¶
The Simple MQTT sample demonstrates how to easily connect an nRF9160 SiP to an MQTT broker and send and receive data.
The sample connects to an MQTT broker and publishes whatever data it receives on the configured subscribe topic to the configured publish topic.
- The following development board:
- nRF9160 DK board (PCA10090)
- The sample is configured to compile and run as a non-secure application on nRF91’s Cortex-M33. Therefore, it automatically includes the nRF9160: Secure Partition Manager that prepares the required peripherals to be available for the application.
Building and running¶
This sample can be found under
samples/nrf9160/mqtt_simple in the nRF Connect SDK folder structure.
The sample is built as a non-secure firmware image for the nrf9160_pca10090ns board. Because of this, it automatically includes the nRF9160: Secure Partition Manager.
See Building and programming a sample application for information about how to build and program the application.
After programming the sample and all prerequisites to the board, test it by performing the following steps:
Connect the USB cable and power on or reset your nRF9160 DK.
Open a terminal emulator and observe that the kit prints the following information:
The MQTT simple sample started
Observe that the kit connects to the configured MQTT broker (
MQTT_BROKER_HOSTNAME) after it gets LTE connection. Now the kit is ready to echo whatever data is sent to it on the configured subscribe topic (
Use an MQTT client like mosquitto to subscribe to and publish data to the broker. Observe that the kit publishes all data that you publish to
Public MQTT brokers might be unstable.
If you experience problems connecting to the MQTT broker, try switching to another broker by changing the value of the
MQTT_BROKER_HOSTNAME configuration option.