Added logic to check for OTA partitions
Warning will be thrown If OTA is enabled but partition table is not configured for OTA. OTA will not be started.
This commit is contained in:
parent
98cfde8aa9
commit
3a519bdc54
|
|
@ -30,6 +30,7 @@
|
|||
#include <sodium.h>
|
||||
#include <WiFi.h>
|
||||
#include <ArduinoOTA.h>
|
||||
#include <esp_ota_ops.h>
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "HAP.h"
|
||||
|
|
@ -445,41 +446,45 @@ void Span::checkConnect(){
|
|||
hapServer->begin();
|
||||
|
||||
if(otaEnabled){
|
||||
ArduinoOTA.setHostname(hostName);
|
||||
ArduinoOTA.setPasswordHash(otaPwd);
|
||||
if(esp_ota_get_running_partition()!=esp_ota_get_next_update_partition(NULL)){
|
||||
ArduinoOTA.setHostname(hostName);
|
||||
ArduinoOTA.setPasswordHash(otaPwd);
|
||||
|
||||
ArduinoOTA
|
||||
.onStart([]() {
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
Serial.println("\n*** OTA Starting:" + type);
|
||||
homeSpan.statusLED.start(LED_OTA_STARTED);
|
||||
})
|
||||
.onEnd([]() {
|
||||
Serial.println("\n*** OTA Completed. Rebooting...");
|
||||
homeSpan.statusLED.off();
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("*** Progress: %u%%\r", (progress / (total / 100)));
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
Serial.printf("*** OTA Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed\n");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed\n");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed\n");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed\n");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed\n");
|
||||
});
|
||||
ArduinoOTA
|
||||
.onStart([]() {
|
||||
String type;
|
||||
if (ArduinoOTA.getCommand() == U_FLASH)
|
||||
type = "sketch";
|
||||
else // U_SPIFFS
|
||||
type = "filesystem";
|
||||
Serial.println("\n*** OTA Starting:" + type);
|
||||
homeSpan.statusLED.start(LED_OTA_STARTED);
|
||||
})
|
||||
.onEnd([]() {
|
||||
Serial.println("\n*** OTA Completed. Rebooting...");
|
||||
homeSpan.statusLED.off();
|
||||
})
|
||||
.onProgress([](unsigned int progress, unsigned int total) {
|
||||
Serial.printf("*** Progress: %u%%\r", (progress / (total / 100)));
|
||||
})
|
||||
.onError([](ota_error_t error) {
|
||||
Serial.printf("*** OTA Error[%u]: ", error);
|
||||
if (error == OTA_AUTH_ERROR) Serial.println("Auth Failed\n");
|
||||
else if (error == OTA_BEGIN_ERROR) Serial.println("Begin Failed\n");
|
||||
else if (error == OTA_CONNECT_ERROR) Serial.println("Connect Failed\n");
|
||||
else if (error == OTA_RECEIVE_ERROR) Serial.println("Receive Failed\n");
|
||||
else if (error == OTA_END_ERROR) Serial.println("End Failed\n");
|
||||
});
|
||||
|
||||
ArduinoOTA.begin();
|
||||
Serial.print("Starting OTA: ");
|
||||
Serial.print(displayName);
|
||||
Serial.print(" at ");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.print("\n");
|
||||
ArduinoOTA.begin();
|
||||
Serial.print("Starting OTA: ");
|
||||
Serial.print(displayName);
|
||||
Serial.print(" at ");
|
||||
Serial.print(WiFi.localIP());
|
||||
Serial.print("\n");
|
||||
} else {
|
||||
Serial.print("\n*** Warning: Can't enable OTA - Partition table used to compile this sketch is not configured for OTA.\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print("\n");
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ void setup() {
|
|||
|
||||
Serial.begin(115200);
|
||||
|
||||
homeSpan.setLogLevel(2);
|
||||
homeSpan.setLogLevel(1);
|
||||
|
||||
// homeSpan.setHostNameSuffix("");
|
||||
homeSpan.setPortNum(1200);
|
||||
homeSpan.setMaxConnections(16);
|
||||
// homeSpan.setQRID("One1");
|
||||
homeSpan.enableOTA();
|
||||
// homeSpan.enableOTA();
|
||||
homeSpan.setSketchVersion("Test 1.2.3");
|
||||
|
||||
homeSpan.begin(Category::Lighting,"HomeSpanTest");
|
||||
|
|
|
|||
Loading…
Reference in New Issue