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:

  1. Connect the USB cable and power on or reset your nRF9160 DK.

  2. Open a terminal emulator and observe that the kit prints the following information:

    The MQTT simple sample started
  3. 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 (MQTT_SUB_TOPIC).

  4. 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 MQTT_SUB_TOPIC on MQTT_PUB_TOPIC.


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.


This sample uses the following libraries:

From nRF Connect SDK
  • drivers/lte_link_control
From nrfxlib
From Zephyr

In addition, it uses the following samples:

From nRF Connect SDK