A Blue Thing In The Cloud

When Technology Becomes Art

NRF7002 MQTT Client Example

Nordic Semiconductors, a key player in the development of Bluetooth Low Energy semiconductors, has introduced their latest NRF7002 IC to the market. This new IC serves as a WiFi companion chip, facilitating the creation of low-power, WiFi 6 devices. In this post, we will present a public repository, with an NRF7002 MQTT Client Example, showing how to use this cutting-edge technology by providing an example of an MQTT communication. The board used is NRF7002-DK, being used for publishing and subscribing on specific topics.

This MQTT Client Example implements different tasks. Firstly, it is focused on configuring the board to operate as a WiFi Station, establishing a connection with a router to enable internet connectivity. The status of the connection will be checked continuously, and, once the board is connected to the Wifi network, one of the LEDs of the board will be turned on. At this moment, the board will create the MQTT communication, with the following sequential instructions:

  • MQTT initialization. The board will initialize the MQTT protocol.
  • MQTT connection and subscription. The board will connect to the broker and then, it will subscribe to the specified subscription topic.
  • MQTT publish. The board will publish the specified message on the publish topic repeatedly.
  • MQTT disconnection. The MQTT disconnection will only occur when there’s a WiFi disconnection, so in normal scenarios, this state will never tale place.

In addition, the example contains callbacks for indicating a connection, a disconnection, a published message on any of the subscribed topics, or when a message is published.

Requirements

We recommend you our “Getting started with nRF7002-DK” post, so you will take over your board and IDE first. Then, this tutorial will provide you the instructions to install the IDE and make the necessary configurations to work with the new nrf7002dk board.

In addition, to test the example, we used MQTT Explorer to check if the board is publishing the correct messages.

Testing the NRF7002 MQTT Client Example

To test the NRF7002 MQTT Client Example, the first thing to do is to configure the prj.conf file. This file contains a list of settings of the board, and we need to modify some of them depending on the WiFi network configuration, or the desired MQTT configuration.

NRF7002 MQTT Client Example prj configuration

Following up, you can find the explanation of this default configuration:

WiFi Stationing configurations.

  • Security level configurations. Select the security level of the router (on the example above, WPA2) and comment the other options.
  • CONFIG_STA_SAMPLE_SSID. Introduce the name of the WiFi network.
  • CONFIG_STA_SAMPLE_PASSWORD. Introduces the password of the WiFi network.      

MQTT configurations

  • CONFIG_MQTT_SAMPLE_TRANSPORT_PUBLISH_TOPIC. Desired publishing topic
  • CONFIG_MQTT_SAMPLE_TRANSPORT_SUBSCRIBE_TOPIC. Desired subscribing topic
  • CONFIG_MQTT_SAMPLE_TRANSPORT_BROKER_HOSTNAME. Broker’s hostname
  • CONFIG_MQTT_SAMPLE_TRANSPORT_BROKER_USERNAME. Broker’s username. If the broker has no username, introduce “noUser”
  • CONFIG_MQTT_SAMPLE_TRANSPORT_BROKER_PASSWORD. Broker’s password. If the broker has no password, introduce “noPassword”
  • CONFIG_MQTT_SAMPLE_TRANSPORT_CLIENT_ID. Client’s ID
  • CONFIG_MQTT_SAMPLE_TRANSPORT_MESSAGE. MQTT message published on the publishing topic.
  • CONFIG_MQTT_SAMPLE_TRIGGER_TIMEOUT_SECONDS. Publishing period in seconds.

Then, build the example with the nrf7002dk configuration, and flash it. To test the working of the TCP/UDP connections, we created a session on MQTT Explorer, where we can publish and subscribe to different topics. The proposed scenario is the following one.

NRF7002 MQTT Example behaviour

Configuration of the MQTT scenario

We can see the exchange of messages between the board and the MQTT Explorer in both board’s serial port and on the MQTT Explorer interface.

NRF7002 MQTT Example Running

Scenario’s result on the board’s serial port

NRF7002 MQTT Client Example, on MQTT Explorer.

Scenario’s results on the MQTT Explorer interface