cancel
Showing results for 
Search instead for 
Did you mean: 

MQTT Message Receiving Issue on STM32 (MQTTYield Error / Delayed or Missing Messages)

Wertyus
Visitor

Hi all,

I'm working on an STM32-based system using FreeRTOS, LWIP (static IP), and the Eclipse Paho MQTTClient C library.

Problem Summary:

  • MQTT connection is successfully established (MQTTConnect() OK).

  • All SUBSCRIBE operations return SUBACK, everything looks fine.

  • MQTTYield() initially runs correctly but after a while:

    • Messages stop arriving or arrive with a delay.

    • Sometimes multiple messages are batched and received at once.

  • Inside MQTTYield(), the deliverMessage() call fails with error code 3 (FAILURE).

  • In net_read(), the recv() function either returns nothing or behaves like a timeout.

  • MQTT_LWIP_SOCKET is enabled.

  • recv() is non-blocking.

  • SO_RCVTIMEO is disabled, but issue persists.

  • cycle() is tested both once and inside a while loop – the same issue occurs.

  • It seems deliverMessage() is not properly triggered after readPacket().

This problem does not occur consistently in local/home network with Mosquitto. But in corporate/complex networks, messages stop being delivered.

MQTT CONNECT sent...
CONNACK received → rc=0, sessionPresent=0
MQTT connection established.
SUBSCRIBE OK → EPLINK/DEV/YGUM/control/voltage/set
SUBSCRIBE OK → EPLINK/DEV/YGUM/control/output_en
SUBSCRIBE OK → EPLINK/DEV/YGUM/control/fault/reset
All SUBSCRIBE operations completed.

Heap free after Flaman_Init: 10640 bytes
Min Ever Free Heap: 2272 bytes

PUBLISH received: topic="EPLINK/DEV/YGUM/control/process_id"
deliverMessage called → topic = EPLINK/DEV/YGUM/control/process_id
MQTTYield error: 3

...

PUBLISH received: topic="EPLINK/DEV/YGUM/control/voltage/set"
deliverMessage called → topic = EPLINK/DEV/YGUM/control/voltage/set
MQTTYield error: 3

Note: No messages are received after this point. The system connects again and shows the same behavior repeatedly.


My Questions:

  1. Why does MQTTYield() return error code 3 (FAILURE)?

  2. Could select() or recv() configuration cause this (e.g., timeout behavior)?

  3. Should cycle() be called multiple times per loop to handle all packets?

  4. Why are some messages delivered in batches or delayed significantly?


I can share relevant parts of net_read(), MQTTYield(), and cycle() logic if needed.
Thanks in advance to anyone who can help!

1 REPLY 1
Andrew Neil
Super User

@Wertyus wrote:

Eclipse Paho MQTTClient C library.


Have you checked out their support options: https://eclipse.dev/paho/support/ ?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.