2024-07-30 10:05 PM
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:
My setup includes:
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
2024-08-02 04:23 AM
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
2024-08-05 11:29 PM
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
2024-08-14 06:21 AM
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
2024-08-20 11:51 PM
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
2024-09-03 03:43 AM
Hi @STea,
I hope this message finds you well. I wanted to follow up on my previous inquiry regarding the configuration of the ENC28J60 Ethernet module with RTOS on the STM32F407G board.
I’m currently working on integrating Ethernet and MQTT protocols without RTOS. However, if RTOS is necessary, I plan to transition to using RTOS with the ENC28J60. Once Ethernet is successfully configured with RTOS, I’ll proceed with the MQTT implementation.
Could you please provide guidance or share any relevant resources or documentation that might assist with this setup?
Best Regards
Gagan Gowda
2024-09-03 09:45 AM
Hello @ggowd.1 ,
To verify basic connectivity, ensure that the ENC28J60 Ethernet controller is correctly configured and that there are no physical connection issues. Since you can ping the IP address, the basic Ethernet setup seems to be working. Next, check your MQTT client configuration, including the server address, port, client ID, username, and password if required. Verify that the MQTT broker is running and accessible from your network. The error codes you mentioned indicate various issues: mqtt_connect return -10 suggests a connection failure, Publish err: -1 points to a publishing failure, and mqtt_connection_cb: Disconnected, reason: 256indicates a lost connection. Consult your MQTT library documentation for more details on these codes. Before diving into MQTT, test your Ethernet setup with a simple TCP echo server/client example to ensure basic communication works and insure you have access to the network. While you can implement Ethernet and MQTT without an RTOS, using one can simplify task management and timing control. For configuring ENC28J60 with RTOS on STM32F407G, set up FreeRTOS, integrate the ENC28J60 driver, use the LwIP stack for TCP/IP communication, and implement an MQTT library compatible with LwIP and FreeRTOS. Use Wireshark for network traffic analysis and add debug prints to trace errors. Ensure the ENC28J60 and STM32F407G are correctly powered and free of hardware issues.
Regards
2024-09-03 09:49 AM
@ggowd.1 wrote:The specific error messages I receive are:
- mqtt_connect return -10
- Publish err: -1
- mqtt_connection_cb: Disconnected, reason: 256
So have you looked-up what those messages/codes mean?
2024-09-10 04:09 AM
Hi @STea ,
"Thanks for your update. I have now checked and confirmed that I can successfully ping the IP address of the ENC28J60 board, and I am able to open the HTTP server using the IP address. I also tested the TCP echo server, and it is working fine.
However, when I check the MQTT functionality, I am encountering an error. I will post all the screenshots of the working setup, along with the main.c and other files. Please review and correct any mistakes you may find."
2024-09-10 04:11 AM
Hi @STea ,
Please find attached the screenshots of everything working.