paho.mqtt.embedded-c
paho.mqtt.embedded-c copied to clipboard
arduino version have a non atomic Timer implementation and block publish forever sometimes
The timer is not atomic as used in the library first is called timer.expired() and after timer.left_ms() so sometimes when time left is small timer.left_ms() return a very big value.
I think the best solution is to make timer atomic https://github.com/eclipse/paho.mqtt.embedded-c/blob/29ab2aa29c5e47794284376d7f8386cfd54c3eed/MQTTClient/src/arduino/Countdown.h#L48 as below:
int left_ms()
{
unsigned long now=millis();
if(now >= interval_end_ms){
return 0;
}else{
return interval_end_ms - now;
}
}