From 2506afdf28205984f7681f9cadedd94e9ee31a4a Mon Sep 17 00:00:00 2001 From: Philip Johansson Date: Sun, 5 Apr 2020 22:51:58 +0200 Subject: [PATCH] OTA configuration --- platformio.ini | 5 +++++ src/main.cpp | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/platformio.ini b/platformio.ini index 8b03209..36239a0 100644 --- a/platformio.ini +++ b/platformio.ini @@ -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 diff --git a/src/main.cpp b/src/main.cpp index f94d2bd..5876527 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,7 +3,7 @@ #include "Vbat.h" #include "body.h" #include "settings.h" -#include +#include #include #include @@ -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(); } \ No newline at end of file