I have built the example sketch as shown below and it uploads via the serial port and runs just fine. However, after enabling OTA upload in my platform.ini file, it always fails with no response from the ESP. I have scoured the web and tried the solutions that have helped others including setting a specific port number, enabling authentication (which fails to authenticate), and have tried different IP addresses (static and DHCP). I started with a board = esp07 and the same env, and have tried switching to nodemcu and nodemcuv2 without any change in behavior. I don't know how to troubleshoot this any further.
My sketch:
include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
const char* ssid = ".....";
const char* password = ".....";
const IPAddress me(10, 248, 0, 171);
const IPAddress gateway(10, 248, 0, 1);
const IPAddress dnsServer(10, 248, 0, 1);
const IPAddress subnetMask(10, 248, 0, 171);
void setup() {
Serial.begin(115200);
Serial.println("Booting");
WiFi.mode(WIFI_STA);
WiFi.config(me, gateway, subnetMask);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
// Port defaults to 8266
ArduinoOTA.setPort(8266);
// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname("myesp8266");
// No authentication by default
//ArduinoOTA.setPassword("admin");
// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");
ArduinoOTA.onStart([]() {
String type;
if (ArduinoOTA.getCommand() == U_FLASH) {
type = "sketch";
} else { // U_SPIFFS
type = "filesystem";
}
// NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
Serial.println("Start updating " + type);
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("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();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
ArduinoOTA.handle();
Serial.println("Alive!");
delay(1000);
}
My platformio.ini file:
[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2 ;esp07
framework = arduino
upload_port = 10.248.0.171
;upload_flags = --auth=admin --port=8266
upload_flags = --port=8266
And, the error I get:
Configuring upload protocol...
Looking for upload port...
Use manually specified: 10.248.0.171
Uploading .pioenvs\nodemcuv2\firmware.bin
10:49:11 [DEBUG]: Options: {'esp_ip': '10.248.0.171', 'host_port': 56463, 'image': '.pioenvs\\nodemcuv2\\firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 8266, 'spiffs': False, 'debug': True
, 'progress': True}
10:49:11 [INFO]: Starting on 0.0.0.0:56463
10:49:11 [INFO]: Upload size: 287952
Sending invitation to 10.248.0.171 ..........
10:49:19 [ERROR]: No response from the ESP
*** [upload] Error 1