Added OTA-Update

This commit is contained in:
Marcel Peterkau 2021-06-13 23:18:14 +02:00
parent 8d151458d4
commit 7ab8294dc7
3 changed files with 57 additions and 0 deletions

View File

@ -15,6 +15,11 @@ board_build.filesystem = littlefs
board_build.f_flash = 80000000L
board_build.ldscript = eagle.flash.4m1m.ld
upload_protocol = espota
upload_port = ESP_OTA.local
upload_flags=
--auth=UploadTheFlag
build_flags=
-D DEVICE_NAME='"DE CTF Timer Prototype 1"'
-D WIFI_CLIENT

View File

@ -17,6 +17,13 @@
#define WIFI_PASS "CaptureTheFlag"
#endif
#ifndef OTA_PASS
#define OTA_PASS "UploadTheFlag"
#endif
#ifndef OTA_HOST
#define OTA_HOST "ESP_OTA"
#endif
#ifndef DEVICE_NAME
#define DEVICE_NAME WIFI_SSID

View File

@ -12,7 +12,9 @@
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
#endif
#include <ArduinoOTA.h>
#include <ESPAsyncWebServer.h>
#include <LittleFS.h>
#include <Wire.h>
@ -382,6 +384,48 @@ void setup()
Serial.print(WiFi.localIP());
}
#endif
ArduinoOTA.setPort(8266);
ArduinoOTA.setHostname(OTA_HOST);
ArduinoOTA.setPassword(OTA_PASS);
ArduinoOTA.onStart([]()
{
String type;
if (ArduinoOTA.getCommand() == U_FLASH)
{
type = "sketch";
}
else
{
type = "filesystem";
LittleFS.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();
#ifdef CAPTIVE
dnsServer.start(53, "*", WiFi.softAPIP());
#endif
@ -400,6 +444,7 @@ void loop()
SerialOutputTicker.update();
InputGetterTicker.update();
PowerMonitorTicker.update();
ArduinoOTA.handle();
#ifdef CAPTIVE
dnsServer.processNextRequest();