OTA Update from Arduino IDE #346
-
Hi is it possible to configure AutoConnect so it supports OTA from Arduino IDE or Platform.io using espota protocol direct? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
AutoConnect can coexist with the Arduino OTA class, but it's best to avoid AutoConnect responding to HTTP requests during OTA updates. Therefore, use the Arduino OTA callback function to detect the OTA start and skip the AutoConnect::handleClient process while OTA is in progress. #include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <AutoConnect.h>
#define OTA_PASSWORD "otaadmin"
AutoConnect portal;
ota_state_t otaState;
void setupOTA() {
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);
otaState = OTA_RUNUPDATE;
});
ArduinoOTA.onEnd([]() {
Serial.println("\nEnd");
otaState = OTA_IDLE;
});
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");
otaState = OTA_IDLE;
});
}
void setup() {
delay(1000);
Serial.begin(115200);
Serial.println("");
setupOTA();
if (portal.begin()) {
ArduinoOTA.setPassword(OTA_PASSWORD);
ArduinoOTA.begin();
otaState = OTA_IDLE;
}
}
void loop() {
if (otaState == OTA_IDLE)
portal.handleClient();
if (WiFi.status() == WL_CONNECTED)
ArduinoOTA.handle();
} Note: |
Beta Was this translation helpful? Give feedback.
AutoConnect can coexist with the Arduino OTA class, but it's best to avoid AutoConnect responding to HTTP requests during OTA updates. Therefore, use the Arduino OTA callback function to detect the OTA start and skip the AutoConnect::handleClient process while OTA is in progress.
The following sketch is a sample based on this technique.