user71512: I'm using ESP8266WiFiMulti, ESP8266WebServer and ArduinoOTA to communicate with my device and perform over-the-air-updates. Everything was working perfectly until I moved the ESP8266 further from the WiFi router. The OTA upload slowed down, which caused upload timeouts after 5 seconds. It fails at a different point each time, usually between 30% and 60%.
How do I increase the OTA timeout to 30 seconds?
Here is the setup code, let me know if you need more:
void startWiFi() {
    ESP8266WiFiMulti wifiMulti;
    wifiMulti.addAP(ssid, password);
    wifiMulti.run();
}

void startOTA() {
    ArduinoOTA.setHostname(_hostname);
    ArduinoOTA.setPassword(_password);

    ArduinoOTA.onStart([]() {
        Serial.println("Start OTA");
    });
    ArduinoOTA.onEnd([]() {
        Serial.println("\nEnd OTA");
    });
    ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
    });
    ArduinoOTA.onError([](ota_error_t error) {
        Serial.printf("Error[%u]: ", error);
        if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed");
        else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed");
        else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed");
        else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed");
        else if (error == OTA_END_ERROR) Serial.println("End Failed");
    });
    ArduinoOTA.begin();
}


user4143: The only timeout I can find is in the espota.py script itself. That is riddled with such lines as:
sock.settimeout(10)

You would need to scour that program and change them all.
However
ArduinoOTA uses UDP for communication. Because of that it is unreliable (yes, that's a technical term). It doesn't have any form of retransmit / retry, so if a packet is lost it's lost for good. No amount of increasing of timeouts will make that packet reappear.
So increasing your timeouts most likely will just make it wait longer before failing.
You should consider switching to a more reliable update system which uses TCP instead of UDP - such as downloading an update from a website using ESP8266httpUpdate. 
Update:
ArduinoOTA uses a combination of both UDP (to initialise and authenticate the connection) and TCP (to make a "back channel" connection back to your computer) to download the actual binary.
The same still applies: you will need to alter the espota.py program to change its timeouts (sock2 is the back-channel object), but there is also one line in ArduinoOTA.cpp that will need to be altered to increase timeouts.  Line 294:
int waited = 1000;

This is not strictly the number of milliseconds to wait for incoming data, but it's not far off - it's a 1 millisecond delay in a loop while looking for incoming data.  Increasing that will allow more time for the ESP8266 to wait for data to arrive.
But of course, with an unstable WiFi connection YMMV...

71512: <p>I'm using <code>ESP8266WiFiMulti</code>, <code>ESP8266WebServer</code> and <code>ArduinoOTA</code> to communicate with my device and perform over-the-air-updates. Everything was working perfectly until I moved the ESP8266 further from the WiFi router. The OTA upload slowed down, which caused upload timeouts after 5 seconds. It fails at a different point each time, usually between 30% and 60%.</p>
<p>How do I increase the OTA timeout to 30 seconds?</p>
<p>Here is the setup code, let me know if you need more:</p>
<pre class="lang-cpp prettyprint-override"><code>void startWiFi() {
    ESP8266WiFiMulti wifiMulti;
    wifiMulti.addAP(ssid, password);
    wifiMulti.run();
}

void startOTA() {
    ArduinoOTA.setHostname(_hostname);
    ArduinoOTA.setPassword(_password);

    ArduinoOTA.onStart([]() {
        Serial.println(&quot;Start OTA&quot;);
    });
    ArduinoOTA.onEnd([]() {
        Serial.println(&quot;\nEnd OTA&quot;);
    });
    ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
        Serial.printf(&quot;OTA Progress: %u%%\r&quot;, (progress / (total / 100)));
    });
    ArduinoOTA.onError([](ota_error_t error) {
        Serial.printf(&quot;Error[%u]: &quot;, error);
        if (error == OTA_AUTH_ERROR) Serial.println(&quot;Auth Failed&quot;);
        else if (error == OTA_BEGIN_ERROR) Serial.println(&quot;Begin Failed&quot;);
        else if (error == OTA_CONNECT_ERROR) Serial.println(&quot;Connect Failed&quot;);
        else if (error == OTA_RECEIVE_ERROR) Serial.println(&quot;Receive Failed&quot;);
        else if (error == OTA_END_ERROR) Serial.println(&quot;End Failed&quot;);
    });
    ArduinoOTA.begin();
}
</code></pre>
 4143: <p>The only timeout I can find is in the <code>espota.py</code> script itself. That is riddled with such lines as:</p>
<pre><code>sock.settimeout(10)
</code></pre>
<p>You would need to scour that program and change them all.</p>
<p><s><strong>However</strong></p>
<p>ArduinoOTA uses UDP for communication. Because of that it is <em>unreliable</em> (yes, that's a technical term). It doesn't have any form of retransmit / retry, so if a packet is lost it's lost for good. No amount of increasing of timeouts will make that packet reappear.</p>
<p>So increasing your timeouts most likely will just make it wait longer before failing.</p>
<p>You should consider switching to a more reliable update system which uses TCP instead of UDP - such as downloading an update from a website using <code>ESP8266httpUpdate</code>. </s></p>
<p><strong>Update:</strong></p>
<p>ArduinoOTA uses a combination of both UDP (to initialise and authenticate the connection) and TCP (to make a &quot;back channel&quot; connection back to your computer) to download the actual binary.</p>
<p>The same still applies: you will need to alter the <code>espota.py</code> program to change its timeouts (<code>sock2</code> is the back-channel object), but there is also one line in <code>ArduinoOTA.cpp</code> that will need to be altered to increase timeouts.  <a href="https://github.com/esp8266/Arduino/blob/master/libraries/ArduinoOTA/ArduinoOTA.cpp#L294" rel="nofollow noreferrer">Line 294</a>:</p>
<pre><code>int waited = 1000;
</code></pre>
<p>This is not strictly the number of milliseconds to wait for incoming data, but it's not far off - it's a 1 millisecond delay in a loop while looking for incoming data.  Increasing that will allow more time for the ESP8266 to wait for data to arrive.</p>
<p>But of course, with an unstable WiFi connection YMMV...</p>
