OTA configuration

This commit is contained in:
Philip Johansson 2020-04-05 22:51:58 +02:00
parent 5d0e8fb56a
commit 2506afdf28
2 changed files with 39 additions and 1 deletions

View File

@ -12,3 +12,8 @@
platform = espressif32
board = esp32dev
framework = arduino
; OTA
; https://docs.platformio.org/en/latest/platforms/espressif8266.html#over-the-air-ota-update
upload_protocol = espota
upload_port = Hexapod

View File

@ -3,7 +3,7 @@
#include "Vbat.h"
#include "body.h"
#include "settings.h"
#include <Arduino.h>
#include <ArduinoOTA.h>
#include <WiFi.h>
#include <memory>
@ -85,6 +85,38 @@ void setup() {
remote->registerCallback(testRemoteCallback);
sweepLeg();
// OTA
ArduinoOTA.setHostname("Hexapod");
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();
}
void loop() {
@ -93,4 +125,5 @@ void loop() {
remote->loop();
body.healthCheck();
ArduinoOTA.handle();
}