Added OTA-Update
This commit is contained in:
parent
8d151458d4
commit
7ab8294dc7
@ -15,6 +15,11 @@ board_build.filesystem = littlefs
|
|||||||
board_build.f_flash = 80000000L
|
board_build.f_flash = 80000000L
|
||||||
board_build.ldscript = eagle.flash.4m1m.ld
|
board_build.ldscript = eagle.flash.4m1m.ld
|
||||||
|
|
||||||
|
upload_protocol = espota
|
||||||
|
upload_port = ESP_OTA.local
|
||||||
|
upload_flags=
|
||||||
|
--auth=UploadTheFlag
|
||||||
|
|
||||||
build_flags=
|
build_flags=
|
||||||
-D DEVICE_NAME='"DE CTF Timer Prototype 1"'
|
-D DEVICE_NAME='"DE CTF Timer Prototype 1"'
|
||||||
-D WIFI_CLIENT
|
-D WIFI_CLIENT
|
||||||
|
@ -17,6 +17,13 @@
|
|||||||
#define WIFI_PASS "CaptureTheFlag"
|
#define WIFI_PASS "CaptureTheFlag"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef OTA_PASS
|
||||||
|
#define OTA_PASS "UploadTheFlag"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef OTA_HOST
|
||||||
|
#define OTA_HOST "ESP_OTA"
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef DEVICE_NAME
|
#ifndef DEVICE_NAME
|
||||||
#define DEVICE_NAME WIFI_SSID
|
#define DEVICE_NAME WIFI_SSID
|
||||||
|
45
src/main.cpp
45
src/main.cpp
@ -12,7 +12,9 @@
|
|||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESPAsyncTCP.h>
|
#include <ESPAsyncTCP.h>
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
|
#include <ESP8266mDNS.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <ArduinoOTA.h>
|
||||||
#include <ESPAsyncWebServer.h>
|
#include <ESPAsyncWebServer.h>
|
||||||
#include <LittleFS.h>
|
#include <LittleFS.h>
|
||||||
#include <Wire.h>
|
#include <Wire.h>
|
||||||
@ -382,6 +384,48 @@ void setup()
|
|||||||
Serial.print(WiFi.localIP());
|
Serial.print(WiFi.localIP());
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
#ifdef CAPTIVE
|
||||||
dnsServer.start(53, "*", WiFi.softAPIP());
|
dnsServer.start(53, "*", WiFi.softAPIP());
|
||||||
#endif
|
#endif
|
||||||
@ -400,6 +444,7 @@ void loop()
|
|||||||
SerialOutputTicker.update();
|
SerialOutputTicker.update();
|
||||||
InputGetterTicker.update();
|
InputGetterTicker.update();
|
||||||
PowerMonitorTicker.update();
|
PowerMonitorTicker.update();
|
||||||
|
ArduinoOTA.handle();
|
||||||
|
|
||||||
#ifdef CAPTIVE
|
#ifdef CAPTIVE
|
||||||
dnsServer.processNextRequest();
|
dnsServer.processNextRequest();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user