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

12 REPLIES 12

Hello @ggowd.1 ,

If you are able to ping the host then the problem seems to be the connection to the MQTT server so make sure it is reachable on your local network (check port 1883 accessibility).

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 ,

Upon launching the program, I am unable to connect this broker from another device. I have confirmed that I am in the same network and that the server name is correct. I have also created a server on a different device and subscribed to the stm32f407g controller; however, when I attempt to publish from stm32f407 and attempt to connect to stm32f407 from a different device, I receive an error message.Error ConnectionRefused: [WinError 10061] Because the target machine actively refused to connect, no connection could be established.
Port was open

Best Regards,
Gagan Gowda

 

Hi @STea 

I wanted to follow up on my earlier message regarding the connection issue I’m experiencing while trying to publish to an MQTT broker using the STM32F407G controller. Here’s what I’ve done so far:

  • Both devices are on the same network.
  • The server name is correct.
  • The correct port is open.

When I create the MQTT broker on a different device, I can subscribe to it successfully from the STM32F407G controller. However, when I attempt to publish from the STM32F407G and try to connect to it from a different device, I receive the following error:
"Error ConnectionRefused: [WinError 10061] The target machine actively refused to connect."

Could you please provide guidance on why the connection might be refused when using the STM32F407G as the broker, and any settings I may need to check or adjust?

Best Regards,
Gagan Gowda