ArduinoOTA and WIFI_AP_STA mode -- upload only works on one interface
Posted: Sun Mar 15, 2020 9:31 pm
I have an ESP32 operating in AP-STA mode, with ArduinoOTA working. However, the upload only succeeds if my development machine (Windows) is connected to the ESP32's AP. It fails if the dev machine is connected to the same AP that the ESP is connected to as a STA.
I would like to understand why, and can this behavior be changed so I can upload via the ESP's STA interface instead?
Example sketch below. Details:
* the ESP32 connects to an AP called "Tumbo" and also acts as an AP with SSID "OTA"
* the ESP32 has a fixed IP address 192.168.4.106 for STA mode
When dev machine is connected to SSID "OTA" I can ping ESP32:
Upload succeeds:
The output from the ESP32:
When dev machine is connected to SSID "Tumbo" ping succeeds:
But upload fails:
Output from ESP32:
The whole sketch is here:
I would like to understand why, and can this behavior be changed so I can upload via the ESP's STA interface instead?
Example sketch below. Details:
* the ESP32 connects to an AP called "Tumbo" and also acts as an AP with SSID "OTA"
* the ESP32 has a fixed IP address 192.168.4.106 for STA mode
When dev machine is connected to SSID "OTA" I can ping ESP32:
Code: Select all
C:\ping 192.168.4.1
Pinging 192.168.4.1 with 32 bytes of data:
Reply from 192.168.4.1: bytes=32 time=4ms TTL=255
Code: Select all
espota.exe -r -i 192.168.4.1 -f firmware.bin -d -p 3232
11:24:00 [DEBUG]: Options: {'timeout': 10, 'esp_ip': '192.168.4.1', 'host_port': 41784, 'image': 'firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 3232, 'spiffs': False, 'debug': True, 'progress': True}
11:24:00 [INFO]: Starting on 0.0.0.0:41784
11:24:00 [INFO]: Upload size: 748336
Sending invitation to 192.168.4.1
11:24:00 [INFO]: Waiting for device...
Uploading: [============================================================] 100% Done...
11:24:15 [INFO]: Waiting for result...
11:24:16 [INFO]: Result: OK
11:24:16 [INFO]: Success
Code: Select all
OTA 1.0.2
Initialising Wifi...
Ready
IP address: 192.168.4.106
dhcps: send_offer>>udp_sendto result 0
Start updating sketch
Progress: 100%
End
Code: Select all
C:\ping 192.168.4.106
Pinging 192.168.4.106 with 32 bytes of data:
Reply from 192.168.4.106: bytes=32 time=416ms TTL=255
Code: Select all
espota.exe -r -i 192.168.4.106 -f firmware.bin -d -p 3232
11:26:12 [DEBUG]: Options: {'timeout': 10, 'esp_ip': '192.168.4.106', 'host_port': 48555, 'image': 'firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 3232, 'spiffs': False, 'debug': True, 'progress': True}
11:26:12 [INFO]: Starting on 0.0.0.0:48555
11:26:12 [INFO]: Upload size: 748336
Sending invitation to 192.168.4.106 ..........
11:27:52 [ERROR]: No response from the ESP
Code: Select all
OTA 1.0.2
Initialising Wifi...
Ready
IP address: 192.168.4.106
[E][WiFiUdp.cpp:183] endPacket(): could not send data: 5
Start updating sketch
Progress: 0%
Code: Select all
#include <ArduinoOTA.h>
#include <WiFi.h>
char version[] = "OTA 1.0.2";
#define WIFI_SSID "Tumbo"
#define WIFI_PASSWORD "admin"
#define AP_SSID "OTA"
#define AP_PASS "admin"
IPAddress local_IP(192, 168, 4, 106);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
void setup() {
Serial.begin(115200);
Serial.print("\n\n\");
Serial.print(version); // Yellow text
Serial.println();
if (WiFi.SSID() != WIFI_SSID) {
Serial.println(F("Initialising Wifi..."));
WiFi.mode(WIFI_AP_STA);
WiFi.softAP(AP_SSID, AP_PASS, 1, 1, 10); // channel = 1, hidden = true, 10 max
WiFi.config(local_IP, gateway, subnet);
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
WiFi.persistent(true);
WiFi.setAutoConnect(true);
WiFi.setAutoReconnect(true);
}
delay(2000);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(2000);
ESP.restart();
}
ArduinoOTA
.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
type = "sketch";
else // U_SPIFFS
type = "filesystem";
Serial.println("Start updating " + type);
})
.onEnd([]() { Serial.println("\nEnd"); })
.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
})
.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();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
ArduinoOTA.handle();
}