<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[RemoteXY community — millis() overflow is an issue]]></title>
	<link rel="self" href="https://forum.remotexy.com/extern.php?action=feed&amp;tid=258&amp;type=atom" />
	<updated>2017-11-30T14:07:07Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.remotexy.com/viewtopic.php?id=258</id>
		<entry>
			<title type="html"><![CDATA[Re: millis() overflow is an issue]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=1098#p1098" />
			<content type="html"><![CDATA[<p>Fixed in vers. 2.3.3 (29.11.2017) of library</p>]]></content>
			<author>
				<name><![CDATA[remotexy]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2</uri>
			</author>
			<updated>2017-11-30T14:07:07Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=1098#p1098</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: millis() overflow is an issue]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=927#p927" />
			<content type="html"><![CDATA[<p>Oh, yes, I understood this problem</p>]]></content>
			<author>
				<name><![CDATA[remotexy]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-20T07:10:20Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=927#p927</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: millis() overflow is an issue]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=924#p924" />
			<content type="html"><![CDATA[<p>The value returned by millis will rollover (go back to 0 in case of a unsigned integer) after 49.7 days.</p><p>Let&#039;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.</p><p>Basically, using substraction, the result will be what is expected, even when millis rolls over.</p><p>I won&#039;t go into details but if you search google &quot;millis rollover&quot; you will find better explanation of the problem.</p>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2017-09-16T20:26:36Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=924#p924</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: millis() overflow is an issue]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=923#p923" />
			<content type="html"><![CDATA[<p>Yes, I see, this can be a problem after 49 days...</p>]]></content>
			<author>
				<name><![CDATA[remotexy]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=2</uri>
			</author>
			<updated>2017-09-16T19:37:13Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=923#p923</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[millis() overflow is an issue]]></title>
			<link rel="alternate" href="https://forum.remotexy.com/viewtopic.php?pid=920#p920" />
			<content type="html"><![CDATA[<p>Hello</p><p>In module esp8266wifi, there is this timeout thing:</p><div class="codebox"><pre><code>if ( serverTimeOut &lt; millis () )

...

void resetServerTimeOut()
{
    serverTimeOut = millis() + REMOTEXY_SERVER_TIMEOUT;
}</code></pre></div><p>This is not the correct way to calculate time differences.</p><p>You must replace it by something like this:</p><div class="codebox"><pre><code>if ( millis() - serverTimeOut &gt;= REMOTEXY_SERVER_TIMEOUT )

...

void resetServerTimeOut()
{
    serverTimeOut = millis();
}</code></pre></div><p>I don&#039;t remember if I already asked you this, but why don&#039;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.</p><br /><p>Edit:</p><p>Here is the list of all &quot;millis&quot; used in your code.<br /></p><div class="quotebox"><blockquote><p>Search &quot;millis&quot; (15 hits in 4 files)<br />&nbsp; D:\Arduino\libraries\RemoteXY\classes\RemoteXY_API.h (9 hits)<br />&nbsp; &nbsp; Line 173:&nbsp; &nbsp; &nbsp;if (wireTimeOut&lt;millis()) {<br />&nbsp; &nbsp; Line 318:&nbsp; &nbsp; &nbsp;wireTimeOut=millis()+REMOTEXY_TIMEOUT;<br />&nbsp; &nbsp; Line 320:&nbsp; &nbsp; &nbsp;if (cloudState==3) cloudTimeOut=millis()+REMOTEXY_CLOUD_ECHO_TIMEOUT;<br />&nbsp; &nbsp; Line 371:&nbsp; &nbsp; &nbsp;cloudTimeOut = millis()+REMOTEXY_CLOUD_RECONNECT_TIMEOUT;<br />&nbsp; &nbsp; Line 383:&nbsp; &nbsp; &nbsp; &nbsp;if (cloudTimeOut&lt;=millis()) {<br />&nbsp; &nbsp; Line 393:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cloudTimeOut = millis()+REMOTEXY_CLOUD_RECONNECT_TIMEOUT;<br />&nbsp; &nbsp; Line 400:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;cloudTimeOut = millis()+500;<br />&nbsp; &nbsp; Line 406:&nbsp; &nbsp; &nbsp; &nbsp;cloudTimeOut = millis()+ REMOTEXY_CLOUD_CONNECT_TIMEOUT; <br />&nbsp; &nbsp; Line 410:&nbsp; &nbsp; &nbsp; &nbsp;if (cloudTimeOut&lt;=millis()) {<br />&nbsp; D:\Arduino\libraries\RemoteXY\classes\RemoteXY_AT.h (2 hits)<br />&nbsp; &nbsp; Line 69:&nbsp; &nbsp; &nbsp;uint32_t timeOut = millis()+delay;<br />&nbsp; &nbsp; Line 72:&nbsp; &nbsp; &nbsp;while (timeOut&gt;millis()) {<br />&nbsp; D:\Arduino\libraries\RemoteXY\modules\esp8266wifi.h (2 hits)<br />&nbsp; &nbsp; Line 101:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (serverTimeOut&lt;millis ()) {<br />&nbsp; &nbsp; Line 173:&nbsp; &nbsp; &nbsp;serverTimeOut = millis ()+REMOTEXY_SERVER_TIMEOUT;<br />&nbsp; D:\Arduino\libraries\RemoteXY\modules\ethernet.h (2 hits)<br />&nbsp; &nbsp; Line 63:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (serverTimeOut&lt;millis ()) {<br />&nbsp; &nbsp; Line 119:&nbsp; &nbsp; &nbsp;serverTimeOut = millis ()+REMOTEXY_SERVER_TIMEOUT;</p></blockquote></div><p>All those lines need to be changed like in my example above.</p>]]></content>
			<author>
				<name><![CDATA[Guillaume]]></name>
				<uri>https://forum.remotexy.com/profile.php?id=23</uri>
			</author>
			<updated>2017-09-15T12:39:43Z</updated>
			<id>https://forum.remotexy.com/viewtopic.php?pid=920#p920</id>
		</entry>
</feed>
