1 (edited by Guillaume 2017-09-15 22:45:32)

Topic: millis() overflow is an issue

Hello

In module esp8266wifi, there is this timeout thing:

if ( serverTimeOut < millis () )

...

void resetServerTimeOut()
{
    serverTimeOut = millis() + REMOTEXY_SERVER_TIMEOUT;
}

This is not the correct way to calculate time differences.

You must replace it by something like this:

if ( millis() - serverTimeOut >= REMOTEXY_SERVER_TIMEOUT )

...

void resetServerTimeOut()
{
    serverTimeOut = millis();
}

I don't remember if I already asked you this, but why don't you put the library on github? That would be a better place to discuss about issues, and I could even make fixes and pull requests. Also users will be able to download updates of your library with the Arduino IDE / PlatformIO IDE library managers, or whatever they are using.


Edit:

Here is the list of all "millis" used in your code.

Search "millis" (15 hits in 4 files)
  D:\Arduino\libraries\RemoteXY\classes\RemoteXY_API.h (9 hits)
    Line 173:     if (wireTimeOut<millis()) {
    Line 318:     wireTimeOut=millis()+REMOTEXY_TIMEOUT;
    Line 320:     if (cloudState==3) cloudTimeOut=millis()+REMOTEXY_CLOUD_ECHO_TIMEOUT;
    Line 371:     cloudTimeOut = millis()+REMOTEXY_CLOUD_RECONNECT_TIMEOUT;
    Line 383:       if (cloudTimeOut<=millis()) {
    Line 393:           cloudTimeOut = millis()+REMOTEXY_CLOUD_RECONNECT_TIMEOUT;
    Line 400:           cloudTimeOut = millis()+500;
    Line 406:       cloudTimeOut = millis()+ REMOTEXY_CLOUD_CONNECT_TIMEOUT;
    Line 410:       if (cloudTimeOut<=millis()) {
  D:\Arduino\libraries\RemoteXY\classes\RemoteXY_AT.h (2 hits)
    Line 69:     uint32_t timeOut = millis()+delay;
    Line 72:     while (timeOut>millis()) {
  D:\Arduino\libraries\RemoteXY\modules\esp8266wifi.h (2 hits)
    Line 101:         if (serverTimeOut<millis ()) {
    Line 173:     serverTimeOut = millis ()+REMOTEXY_SERVER_TIMEOUT;
  D:\Arduino\libraries\RemoteXY\modules\ethernet.h (2 hits)
    Line 63:         if (serverTimeOut<millis ()) {
    Line 119:     serverTimeOut = millis ()+REMOTEXY_SERVER_TIMEOUT;

All those lines need to be changed like in my example above.

2

Re: millis() overflow is an issue

Yes, I see, this can be a problem after 49 days...

3

Re: millis() overflow is an issue

The value returned by millis will rollover (go back to 0 in case of a unsigned integer) after 49.7 days.

Let's say the microcontroller is running since 49.69 days, millis() is about to rollover and you add something to it, the result is now too big to be stored in a uint32_t so the variable rolled over, and the result is not what you expect.

Basically, using substraction, the result will be what is expected, even when millis rolls over.

I won't go into details but if you search google "millis rollover" you will find better explanation of the problem.

4

Re: millis() overflow is an issue

Oh, yes, I understood this problem

5

Re: millis() overflow is an issue

Fixed in vers. 2.3.3 (29.11.2017) of library