feat: add ota upgrade
This commit is contained in:
parent
7508cbe430
commit
064da6b4f1
2 changed files with 48 additions and 0 deletions
|
@ -59,3 +59,6 @@ build_flags =
|
|||
-D FEATURE_CONFIGAP=D0
|
||||
-D FEATURE_CONFIGAP_GND=D1
|
||||
-D FEATURE_LDR=A2
|
||||
-D FEATURE_OTA=1
|
||||
upload_protocol = espota
|
||||
upload_port = spaceapimap.local
|
|
@ -9,6 +9,9 @@
|
|||
#include <ESP32_C3_TimerInterrupt.h>
|
||||
#include <FS.h>
|
||||
#include <SPIFFS.h>
|
||||
#ifdef FEATURE_OTA
|
||||
#include <ArduinoOTA.h>
|
||||
#endif
|
||||
|
||||
#include "spacemap.h"
|
||||
|
||||
|
@ -204,6 +207,43 @@ void setup() {
|
|||
filter[0]["data"]["state"]["open"] = true;
|
||||
filter[0]["data"]["state"]["lastchange"] = true;
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
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);
|
||||
})
|
||||
.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");
|
||||
}
|
||||
})
|
||||
.setHostname("spaceapimap");
|
||||
ArduinoOTA.begin();
|
||||
#endif // FEATURE_OTA
|
||||
|
||||
#ifdef FEATURE_LDR
|
||||
analogSetPinAttenuation(FEATURE_LDR, ADC_11db);
|
||||
#endif // FEATURE_LDR
|
||||
|
@ -375,5 +415,10 @@ void loop() {
|
|||
}
|
||||
// Finally, update the LED chain
|
||||
pixels.show();
|
||||
|
||||
#ifdef FEATURE_OTA
|
||||
ArduinoOTA.handle();
|
||||
#endif
|
||||
|
||||
delay(50);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue