paho.mqtt.embedded-c icon indicating copy to clipboard operation
paho.mqtt.embedded-c copied to clipboard

arduino version have a non atomic Timer implementation and block publish forever sometimes

Open pat1 opened this issue 3 years ago • 0 comments

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;
      }
    }

pat1 avatar Mar 26 '21 11:03 pat1