Skip to main content
Associate III
November 25, 2024
Question

Implementing MQTT Communication with Azure IoT Hub on STM32F407

  • November 25, 2024
  • 6 replies
  • 2229 views

Hello STM Community,

I am currently working on a project using the STM32F407 microcontroller, and I need to implement MQTT communication with Azure IoT Hub for cloud connectivity. The STM32F407 is already connected to the internet through LTE modem via PPPoS, and now I need to integrate MQTT to send data to Azure IoT Hub

  • How to set up an MQTT client on STM32 for Azure IoT Hub?
  • How to handle TLS/SSL for secure communication with Azure?
  • Any resources or example code for device authentication and reconnection logic?

Any guidance or resources for setting this up would be greatly appreciated!

Thanks!

This topic has been closed for replies.

6 replies

Associate III
November 26, 2024

Hello,
Any update Today? 
Can I proceed with the implementation from
 https://github.com/eziya/STM32F4_HAL_ETH_MQTT_CLIENT   ?


Associate III
November 28, 2024

Hello,
Any update  Today?

Guillaume K
ST Employee
November 29, 2024

Hello

Did you look at Microsoft documentation to connect to their Azure IoT Hub ?

Microsoft provides C SDKs to connect to azure iot hub:

Azure IoT device and service SDKs - Azure IoT | Microsoft Learn (you need the "device" SDK)

There are 2 SDKs: "Azure IoT C SDK" and "Azure SDK for C". For embedded devices you need "Azure SDK for C" (https://github.com/Azure/azure-sdk-for-c).

General information to connect to Azure IoT Hub:

Use MQTT to communicate with Azure IoT Hub - Azure IoT Hub | Microsoft Learn

if you want low level MQTT connection details:

https://learn.microsoft.com/en-us/azure/iot/iot-mqtt-connect-to-iot-hub#using-the-mqtt-protocol-directly-as-a-device 

If your project uses FreeRTOS, see the link in "Azure IoT SDKs" page to GitHub - Azure/azure-iot-middleware-freertos: Azure IoT Middleware for FreeRTOS

If your project is based on Azure RTOS with Netxduo TCP-IP stack you can have a look at X-CUBE-AZURE or X-CUBE-AZURE-H5 (but they are for STM32U5/STM32H5, not for your STM32F4).

Associate III
November 30, 2024

Hi@ Guillaume K


I have reviewed the Azure documentation and would like to integrate the Azure SDK Middleware for FreeRTOS with my STM32F407-based application. However, the Azure documentation mentions that the middleware has only been tested with the following MCUs:

  • B-L475E-IOT01A
  • B-L4S5I-IOT01A
  • STM32H745I-DISCO

For my application, which is based on the STM32F407, which of these MCUs would you recommend I use as a reference for porting?

Additionally, I noticed that the X-CUBE-AZURE package is specifically designed for STM32U5 and STM32H5 devices. Is it possible to adapt X-CUBE-AZURE for the STM32F407, or would this require extensive modifications?

Best regards, 
Noushadali K.

Associate III
December 2, 2024

Hi,
Any update Today?

Guillaume K
ST Employee
December 2, 2024

Both X-CUBE-AZURE packages are made with Azure RTOS and Netxduo so it would be difficult to port to FreeRTOS.

I don't have much experience with Azure SDK middleware for FreeRTOS. 

The 3 boards you mention don't have the same network interface as yours (cellular).

I suggest you refer to Microsoft documentation about Azure SDK middleware for FreeRTOS, and your cellular modem documentation.