MCUXpresso SDK Documentation

lwip_mqtt_freertos#

Overview#

The lwip_mqtt demo application demonstrates MQTT client connecting to MQTT broker via unsecured socket. The application obtains IP and DNS addresses from DHCP and resolves broker’s hostname if needed. Then it connects to the broker and subscribes to the “lwip_topic/#” and “lwip_other/#” topics. Further it publishes five messages to the “lwip_topic/100” which are also received back as the board is subscribed to the “lwip_topic/#”. It then disconnects from the broker.

Prepare the Demo#

  1. Make sure the MQTT broker pointed to by EXAMPLE_MQTT_SERVER_HOST and EXAMPLE_MQTT_SERVER_PORT definitions is up and accessible on your network via unsecured socket. A public MQTT testing server can be used or you can install a broker locally and modify the definitions mentioned above.

    The public testing MQTT brokers might be overloaded and unable to connect to sometimes. Better option might be to install an MQTT broker, like Eclipse Mosquitto, locally and have full control. If you install this one, the following settings added to its configuration file mosquitto.conf allow to connect from the board to the broker via port 1883 and without a username and a password (provided there are no additional restrictions, like firewall blocking the port, in place):

    allow_anonymous true
    listener 1883
    

    Naturally, this means that anybody able to establish TCP connection with that computer on port 1883 might connect to the broker.

  2. Connect a USB cable between the PC host and the OpenSDA(or USB to Serial) USB port on the target board.

  3. Open a serial terminal on PC for OpenSDA serial(or USB to Serial) device with these settings:

    • 115200 baud rate

    • 8 data bits

    • No parity

    • One stop bit

    • No flow control

  4. Insert the Ethernet Cable into the target board’s RJ45 port and connect it to a router (or other DHCP server capable device).

  5. Download the program to the target board.

  6. Either press the reset button on your board or launch the debugger in your IDE to begin running the demo.

Running the demo#

When the demo runs, the log would be seen on the terminal like:

Initializing PHY...

************************************************
 MQTT client example
************************************************
Getting IP address from DHCP...

IPv4 Address     : 192.168.10.4
IPv4 Subnet mask : 255.255.255.0
IPv4 Gateway     : 192.168.10.1

Resolving "test.mosquitto.org"...
Connecting to MQTT broker at 5.196.78.28...
MQTT client "nxp_322c480e82967d6a" connected.
Subscribing to the topic "lwip_topic/#" with QoS 0...
Subscribing to the topic "lwip_other/#" with QoS 1...
Subscribed to the topic "lwip_topic/#".
Subscribed to the topic "lwip_other/#".
Going to publish to the topic "lwip_topic/100"...
Received 18 bytes from the topic "lwip_topic/100": "message from board"
Published to the topic "lwip_topic/100".
Going to publish to the topic "lwip_topic/100"...
Received 18 bytes from the topic "lwip_topic/100": "message from board"
Published to the topic "lwip_topic/100".
Going to publish to the topic "lwip_topic/100"...
Received 18 bytes from the topic "lwip_topic/100": "message from board"
Published to the topic "lwip_topic/100".
Going to publish to the topic "lwip_topic/100"...
Received 18 bytes from the topic "lwip_topic/100": "message from board"
Published to the topic "lwip_topic/100".
Going to publish to the topic "lwip_topic/100"...
Received 18 bytes from the topic "lwip_topic/100": "message from board"
Published to the topic "lwip_topic/100".
Disconnected from MQTT broker.

Supported Boards#

EVKB-IMXRT1050
Hardware requirements
  • Mini/micro USB cable

  • Network cable RJ45 standard

  • EVKB-IMXRT1050 board

  • Personal Computer

Board settings

No special settings are required.

MIMXRT1060-EVKB
Hardware requirements
  • Mini/micro USB cable

  • MIMXRT1060-EVKB board

  • Personal Computer

Board settings

No special settings are required.

MIMXRT1170-EVKB
Hardware requirements
  • Mini/micro USB cable

  • Network cable RJ45 standard

  • MIMXRT1170-EVKB board

  • Personal Computer

Board settings

This example uses 1G port(J4) as default. If want to test 100M port(J3), please set the macro BOARD_NETWORK_USE_100M_ENET_PORT to 1.

MIMXRT1060-EVKC
Hardware requirements
  • Mini/micro USB cable

  • MIMXRT1060-EVKC board

  • Personal Computer

Board settings

No special settings are required.

FRDM-IMXRT1152
Hardware requirements
  • FRDM-IMXRT1152 board

  • USB Type-C cable

  • RJ45 network cable

  • Personal Computer

Board settings
  • Connect the USB Type-C cable to the FRDM-IMXRT1152 USB debug connector.

  • Use the Gigabit Ethernet RJ45 port (J130).

  • Set J134 to position 1-2 for the shared ENET_MDIO / ETH0_RDATA3 routing.

EVK-MIMXRT1020
Hardware requirements
  • Mini/micro USB cable

  • Network cable RJ45 standard

  • EVK-MIMXRT1020 board

  • Personal Computer

Board settings

No special settings are required.

Note: To debug in qspiflash, following steps are needed:

  1. Select the flash target and compile.

  2. Set the SW8: 1 off 2 off 3 on 4 off, then power on the board and connect USB cable to J23.

  3. Start debugging in IDE.

    • Keil: Click “Download (F8)” to program the image to qspiflash first then clicking “Start/Stop Debug Session (Ctrl+F5)” to start debugging.

MIMXRT1024-EVK
Hardware requirements
  • Mini/micro USB cable

  • Network cable RJ45 standard

  • MIMXRT1024-EVK board

  • Personal Computer

Board settings

No special settings are required.

Note: To debug in qspiflash, following steps are needed:

  1. Select the flash target and compile.

  2. Set the SW8: 1 off 2 off 3 on 4 off, then power on the board and connect USB cable to J23.

  3. Start debugging in IDE.

    • Keil: Click “Download (F8)” to program the image to qspiflash first then clicking “Start/Stop Debug Session (Ctrl+F5)” to start debugging.

MIMXRT1040-EVK
Hardware requirements
  • Mini/micro USB cable

  • MIMXRT1040-EVK board

  • Personal Computer

Board settings

No special settings are required.

EVK-MIMXRT1064
Hardware requirements
  • Mini/micro USB cable

  • EVK-MIMXRT1064 board

  • Personal Computer

Board settings

No special settings are required.

MIMXRT1160-EVK
Hardware requirements
  • Mini/micro USB cable

  • Network cable RJ45 standard

  • MIMXRT1160-EVK board

  • Personal Computer

Board settings

This example uses 1G port(J4) as default. If want to test 100M port(J3), please set the macro BOARD_NETWORK_USE_100M_ENET_PORT to 1.

MIMXRT1180-EVK
Hardware requirements
  • Mini/micro USB cable

  • Network cable RJ45 standard

  • MIMXRT1180-EVK board

  • Personal Computer

Board settings

This example uses Ethernet RJ45 port J32.

FRDM-MCXA577
Hardware requirements
  • Type-C USB cable

  • RJ45 Network cable (for 100BASE-TX mode)

  • 10BASE-T1S network adapter and cable (optional for 10BASE-T1S mode)

  • FRDM-MCXA577 board

  • Personal Computer

Board settings

Short position 2-3 on J29.

Use with 10BASE-T1S Ethernet

The example uses 100BASE-TX Ethernet over RJ45 by default. If you want to use the internal 10BASE-T1S digital PHY, redefine BOARD_NETWORK_USE_TENBASET_PHY from board.h to 1 and rebuild. Connect to a PC with a 10BASE-T1S network adapter instead of RJ45 and enable PLCA on a PC with the following parameters: - node ID: 0 (PLCA coordinator) - node count: 8 - TO timer: 32 BT - burst count: 0 - burst timer: 128 BT

FRDM-MCXE247
Hardware requirements
  • USB-C cable

  • Network cable RJ45 standard

  • FRDM-MCXE247 board

  • Personal Computer

Board settings

No special settings are required.

FRDM-MCXN947
Hardware requirements
  • Type-C USB cable

  • RJ45 Network cable

  • FRDM-MCXN947 board

  • Personal Computer

Board settings

Connect JP13 2-3 pin. Populate R274 to sync reference clock.

FRDM-MCXN947T
Hardware requirements
  • Type-C USB cable

  • RJ45 Network cable

  • FRDM-MCXN947T board

  • Personal Computer

Board settings

Connect JP13 2-3 pin. Populate R274 to sync reference clock.

FRDM-RW612
Hardware requirements
  • USB-C cable

  • Network cable RJ45 standard

  • FRDM-RW612 board

  • Personal Computer

Board settings

Make sure SJ21 and SJ22 have positions 1 and 2 soldered (default).

LPCXpresso54628
Hardware requirements
  • Mini/micro USB cable

  • RJ45 Network cable

  • LPCXpresso54628 board

  • Router or other device with DHCP server capability

  • Personal Computer

Board settings

For LPCXpresso54628 V2.0:JP11 and JP12 1-2 on.

LPCXpresso54S018
Hardware requirements
  • Mini/micro USB cable

  • RJ45 Network cable

  • LPCXpresso54S018 board

  • Router or other device with DHCP server capability

  • Personal Computer

Board settings
LPCXpresso54S018M
Hardware requirements
  • Mini/micro USB cable

  • RJ45 Network cable

  • LPCXpresso54S018M board

  • Router or other device with DHCP server capability

  • Personal Computer

Board settings

For LPCXpresso54S018M V2.0:JP11, JP12, JP14 and JP15 1-2 on.

MCX-N5XX-EVK
Hardware requirements
  • Mini/micro USB cable

  • RJ45 Network cable

  • MCX-N5XX-EVK board

  • Personal Computer

Board settings

Connect JP13 2-3 pin. Populate R274 to sync reference clock.

MCX-N9XX-EVK
Hardware requirements
  • Mini/micro USB cable

  • RJ45 Network cable

  • MCX-N9XX-EVK board

  • Personal Computer

Board settings

Connect JP13 2-3 pin. Populate R274 to sync reference clock.

RD-RW612-BGA
Hardware requirements
  • Micro USB cable

  • Network cable RJ45 standard

  • RD-RW612-BGA board

  • Personal Computer

Board settings

Connect JP54. Load R520, R508, R505 Remove R518, R507, R506

FRDM-IMXRT1186
Hardware requirements
  • Type-C USB cable

  • Network cable RJ45 standard

  • FRDM-IMXRT1186 board

  • Personal Computer

Board settings

Short jumpers J12 (1-2) and J13 (2-3) and connect network cable to J56A.