Skip to content

Commit

Permalink
Add support more Arduino boards for OTA firmware update
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 2, 2024
1 parent 59e00e8 commit 8cd8a36
Show file tree
Hide file tree
Showing 22 changed files with 230 additions and 132 deletions.
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

[![GitHub Sponsors](https://img.shields.io/github/sponsors/mobizt?logo=github)](https://github.com/sponsors/mobizt)

Revision `2024-07-01T09:17:48Z`
Revision `2024-07-02T04:31:38Z`

## Table of Contents

Expand Down Expand Up @@ -2493,23 +2493,18 @@ The OTA firmware update is supported using bin file stored in `Firebase Storage`

The Arduino devices that is natively supports OTA firmware update is `ESP8266`, `ESP32` and `Raspberry Pi Pico`.

Since v1.3.1, the Arduino SAMD21 boards that use NINA firmware and WiFi101 firmware are also supported using [WiFi101OTA](https://github.com/arduino-libraries/WiFi101OTA) library.
Since v1.3.1, the Arduino SAMD21 boards that use NINA firmware and WiFi101 firmware are also supported using [Internal_Storage_OTA](https://github.com/mobizt/Internal_Storage_OTA) library.

In [WiFi101OTA](https://github.com/arduino-libraries/WiFi101OTA) library, only three files e.g. `InternalStorage.h`, `InternalStorage.cpp` and `OTAStorage.h` will be used.

To allow OTA update in Arduino SAMD21 boards, include `InternalStorage.h` in your sketch.
To allow OTA update in Arduino SAMD21 boards, you have to include `Internal_Storage_OTA.h` in your sketch.

```cpp
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#endif
```
Then assign the `InternalStorage` class object to be used for `Realtume Database` via `RealtumeDatabase::setOTAStorage(InternalStorage)`, for `Google Cloud Storage` via `CloudStorage::setOTAStorage(InternalStorage)` and for `Firebase Storage` via `Storage::setOTAStorage(InternalStorage)`

In Arduino board that uses NINA firmware, you have to keep only those 3 files and delete all other files from [WiFi101OTA](https://github.com/arduino-libraries/WiFi101OTA)'s src folder and `WiFi101` library must be removed in this case.
If `InternalStorage` was not assigned before calling OTA function in case [Internal_Storage_OTA](https://github.com/mobizt/Internal_Storage_OTA) or Arduino compatible OTA library was included, the error `OTA Storage was not set` will be occurred.

Some Arduino compatible OTA library that provides the `InternalStorage.h` class that derived from `OTAStorage.h` class also can be used.
Finally, once the OTA update complete, in case [Internal_Storage_OTA](https://github.com/mobizt/Internal_Storage_OTA), you have to call `InternalStorage.apply()`.

The macro `FIREBASE_UPDATER_INTERNAL_STORAGE` is defined as `InternalStorage` class object when [WiFi101OTA](https://github.com/arduino-libraries/WiFi101OTA) and/or Arduino compatible OTA library are installed.
You can use other Arduino OTA libraries that provide `InternalStorageClass` object (`InternalStorage`) that derived from modified version of Arduino WiFi101OTA's `OTAStorage` class.


## Project Preparation and Setup
Expand Down
17 changes: 11 additions & 6 deletions examples/CloudStorage/Async/Callback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -148,6 +148,10 @@ void loop()

Serial.println("OTA update download...");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
cstorage.setOTAStorage(InternalStorage);
#endif

GoogleCloudStorage::GetOptions options;

cstorage.ota(aClient, GoogleCloudStorage::Parent(STORAGE_BUCKET_ID, "firmware.bin"), options, asyncCB, "otaTask");
Expand Down Expand Up @@ -224,13 +228,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/CloudStorage/Async/NoCallback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -147,6 +147,10 @@ void loop()

Serial.println("OTA update download...");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
cstorage.setOTAStorage(InternalStorage);
#endif

GoogleCloudStorage::GetOptions options;

cstorage.ota(aClient, GoogleCloudStorage::Parent(STORAGE_BUCKET_ID, "firmware.bin"), options, aResult_no_callback);
Expand Down Expand Up @@ -217,13 +221,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/CloudStorage/Sync/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -149,6 +149,10 @@ void loop()

Serial.println("OTA update download...");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
cstorage.setOTAStorage(InternalStorage);
#endif

GoogleCloudStorage::GetOptions options;

// There is no OTA download progress available for sync OTA download.
Expand Down Expand Up @@ -223,13 +227,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/RealtimeDatabase/Async/Callback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -128,6 +128,10 @@ void loop()

Serial.println("Asynchronous OTA update... ");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Database.setOTAStorage(InternalStorage);
#endif

Database.ota(aClient, "/test/firmware/bin", asyncCB, "otaTask");
}
}
Expand Down Expand Up @@ -180,13 +184,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/RealtimeDatabase/Async/NoCallback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -127,6 +127,10 @@ void loop()

Serial.println("Asynchronous OTA update... ");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Database.setOTAStorage(InternalStorage);
#endif

Database.ota(aClient, "/test/firmware/bin", aResult_no_callback);
}

Expand Down Expand Up @@ -173,13 +177,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/Storage/Async/Callback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -130,6 +130,10 @@ void loop()

Serial.println("OTA update download...");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
storage.setOTAStorage(InternalStorage);
#endif

storage.ota(aClient, FirebaseStorage::Parent(STORAGE_BUCKET_ID, "firmware.bin"), asyncCB, "otaTask");
}
}
Expand Down Expand Up @@ -186,13 +190,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/Storage/Async/NoCallback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -129,6 +129,10 @@ void loop()

Serial.println("OTA update download...");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
storage.setOTAStorage(InternalStorage);
#endif

storage.ota(aClient, FirebaseStorage::Parent(STORAGE_BUCKET_ID, "firmware.bin"), aResult_no_callback);
}

Expand Down Expand Up @@ -179,13 +183,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
17 changes: 11 additions & 6 deletions examples/Storage/Sync/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@

// For Arduino SAMD21 OTA supports.
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if __has_include(<InternalStorage.h>)
#include <InternalStorage.h>
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#endif

#define WIFI_SSID "WIFI_AP"
Expand Down Expand Up @@ -137,6 +137,10 @@ void loop()

Serial.println("OTA update download...");

#if defined(FIREBASE_OTA_UPDATER_STORAGE)
storage.setOTAStorage(InternalStorage);
#endif

// There is no OTA download progress available for sync OTA download.
// To get the OTA download progress, use async OTA download instead.

Expand Down Expand Up @@ -191,13 +195,14 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
delay(2000);
#if defined(ESP32) || defined(ESP8266)
ESP.restart();
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
Serial.println("Restarting...\n\n");
rp2040.restart();
#elif defined(FIREBASE_UPDATER_INTERNAL_STORAGE)
FIREBASE_UPDATER_INTERNAL_STORAGE.apply();
#endif
}
1 change: 1 addition & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ unsetAsyncResult KEYWORD2
setSSEFilters KEYWORD2
setJWTProcessor KEYWORD2
setSessionTimeout KEYWORD2
setOTAStorage KEYWORD2

###################
# Struct (KEYWORD3)
Expand Down
Loading

0 comments on commit 8cd8a36

Please sign in to comment.