From 3abe49fb0eb0b5d2a2cfa5b92ea61738fb1c4d5e Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Fri, 29 Sep 2017 21:00:56 +0200 Subject: [PATCH] Multi-image OTA support on small flash devices --- spejsiot/SpejsNode.cpp | 1 + spejsiot/endpoints/ImplementationEndpoint.cpp | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spejsiot/SpejsNode.cpp b/spejsiot/SpejsNode.cpp index 0b71c8f..237b93c 100644 --- a/spejsiot/SpejsNode.cpp +++ b/spejsiot/SpejsNode.cpp @@ -129,6 +129,7 @@ void SpejsNode::onConnected() { notify("$mac", WifiStation.getMAC()); notify("$fw/name", "spejsiot"); notify("$fw/version", BUILD_ID); + notify("$fw/slot", String(currentSlot)); // HTTP initialization http.listen(80); diff --git a/spejsiot/endpoints/ImplementationEndpoint.cpp b/spejsiot/endpoints/ImplementationEndpoint.cpp index 8f8aa07..2f1ee63 100644 --- a/spejsiot/endpoints/ImplementationEndpoint.cpp +++ b/spejsiot/endpoints/ImplementationEndpoint.cpp @@ -11,7 +11,12 @@ EndpointResult ImplementationEndpoint::onValue(String property, String value) { void ImplementationEndpoint::startOTA() { uint8_t slot; rboot_config bootconf; + +#ifdef RBOOT_TWO_ROMS + String romURL = OTA_URL + parent->deviceID + (parent->currentSlot ? "/rom1.bin" : "/rom0.bin"); +#else String romURL = OTA_URL + parent->deviceID + "/rom0.bin"; +#endif String spiffsURL = OTA_URL + parent->deviceID + "/spiff_rom.bin"; Serial.println("Updating..."); @@ -22,10 +27,7 @@ void ImplementationEndpoint::startOTA() { bootconf = rboot_get_config(); - if (parent->currentSlot == 0) - slot = 1; - else - slot = 0; + slot = !parent->currentSlot; Serial.printf("Updating to rom %d.\r\n", slot);