cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing MQTT in STM32F407G

ggowd.1
Associate III

Hi Team,

I am currently working on a project involving the STM32F407G microcontroller, where I have configured MQTT to connect to a server. However, I am encountering persistent issues and have been unable to establish a successful connection.

The specific error messages I receive are:

  • mqtt_connect return -10
  • Publish err: -1
  • mqtt_connection_cb: Disconnected, reason: 256

My setup includes:

  • No RTOS
  • Ethernet communication through the ENC28J60 controller

Despite spending over a week troubleshooting, I have been unable to resolve these issues. I have attached the relevant sections of my code for your reference. Could someone please provide guidance or suggestions on how to overcome these errors? 

Best Regards,
Gagan Gowda

4 REPLIES 4
STea
ST Employee

Hello @ggowd.1 ,

Your attachment was not included in the post can you add it. also is it possible to test that your Hardware setup is working by trying to run a simple TCP echo example to make sure that you are establishing a connection correctly with your external PHY .
Regards

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hello @STea ,

Thank you for your suggestion. I was able to ping the IP address in the command prompt, which indicates that the hardware setup is working to some extent. However, I am encountering an issue where I cannot subscribe to the MQTT server using Mosquitto.
Could you please provide guidance or documentation, procedures, or links to MQTT protocol.

Best Regards,
Gagan Gowda

Hello @ggowd.1 ,

You can see the following eziya/STM32F4_HAL_ETH_MQTT_CLIENT: STM32 + FREERTOS + LWIP + MQTT example (github.com)
which implement an MQTT client on STM32F4 using Lwip and FreeRtos which is very similar to your usecase
see also How to Implement Embedded Mqtt Client Using W5500 IC. : 5 Steps - Instructables
you can see also an implementation of pubsubclient MQTT using STM32duino which is a very simple and quick way to establish a client with very little time and effort STM32Examples/examples/Communication/MQTT/PubSubClient/mqtt_STM32Ethernet/mqtt_STM32Ethernet.ino at main · stm32duino/STM32Examples (github.com)

Regards

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @STea ,

Thank you for sharing links about the MQTT protocol. I am currently working on Ethernet and MQTT protocol without using RTOS. If it's not feasible to implement them without RTOS, I will transition to working with RTOS on the ENC28J60. Once Ethernet is functioning with RTOS, I will then proceed to implement MQTT.Is there a procedure to configure the ENC28J60 with RTOS on the STM32F407G board?

Best Regards,
Gagan Gowda