Skip to content

Commit

Permalink
Use Arduino OTAStorage to support other OTA Storage libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
mobizt committed Jul 2, 2024
1 parent 0cb852a commit a42d570
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 97 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/mobizt/FirebaseClient/.github%2Fworkflows%2Fcompile_library.yml?logo=github&label=compile) [![Github Stars](https://img.shields.io/github/stars/mobizt/FirebaseClient?logo=github)](https://github.com/mobizt/FirebaseClient/stargazers) ![Github Issues](https://img.shields.io/github/issues/mobizt/FirebaseClient?logo=github)

![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.3.1-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient)
![GitHub Release](https://img.shields.io/github/v/release/mobizt/FirebaseClient) ![Arduino](https://img.shields.io/badge/Arduino-v1.3.2-57C207?logo=arduino) ![PlatformIO](https://badges.registry.platformio.org/packages/mobizt/library/FirebaseClient.svg) ![GitHub Release Date](https://img.shields.io/github/release-date/mobizt/FirebaseClient)

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

Expand Down Expand Up @@ -2498,17 +2498,17 @@ Since v1.3.1, the Arduino SAMD21 boards that use NINA firmware and WiFi101 firmw

The [Internal_Storage_OTA](https://github.com/mobizt/Internal_Storage_OTA) is the modified version of [WiFi101OTA](http://www.arduino.cc/en/Reference/WiFi101OT) library which contains only foure files e.g. `Internal_Storage_OTA.h`, `InternalStorage.h`, `InternalStorage.cpp`and `OTAStorage.h`.

The functions `OTAStorage::open` and `InternalStorageClass::open` are modified to accept an `int` parameter which will be compatible with other OTA libraries.

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

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)`
Then assign the `InternalStorage` class object to be used for `Realtume Database` via `RealtumeDatabase::setOTAStorage`, for `Google Cloud Storage` via `CloudStorage::setOTAStorage` and for `Firebase Storage` via `Storage::setOTAStorage`

If `InternalStorage` was not assigned before calling OTA function in case [Internal_Storage_OTA](https://github.com/mobizt/Internal_Storage_OTA), the error `OTA Storage was not set` will be occurred.

In SAMD21 Arduino boards, if `OTA Storage` was not set before calling OTA function, the error `OTA Storage was not set` will be occurred.

Finally, once the OTA update complete, in case [Internal_Storage_OTA](https://github.com/mobizt/Internal_Storage_OTA), you have to call `InternalStorage.apply()` to apply the update and then restart.

Other OTA libraries that provide `InternalStorageClass` object (`InternalStorage`) that derived from the modified version of Arduino WiFi101OTA's `OTAStorage` class can also be used.
Some OTA libraries that provide `Storage Class` object that derived from the modified version of Arduino WiFi101OTA's `OTAStorage` class can also be used.


## Project Preparation and Setup
Expand Down Expand Up @@ -3018,6 +3018,8 @@ You can assign the optional build options using one of the following methods.

- By adding compiler build flags with `-D name`.

- By defined the macros before including the library main header file `FirebaseClient.h`.

In PlatformIO IDE, using `build_flags` in PlatformIO IDE's platformio.ini is more convenient

```ini
Expand Down
9 changes: 5 additions & 4 deletions examples/CloudStorage/Async/Callback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

GoogleCloudStorage::GetOptions options;
Expand Down Expand Up @@ -228,9 +229,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
9 changes: 5 additions & 4 deletions examples/CloudStorage/Async/NoCallback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

GoogleCloudStorage::GetOptions options;
Expand Down Expand Up @@ -221,9 +222,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
9 changes: 5 additions & 4 deletions examples/CloudStorage/Sync/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

GoogleCloudStorage::GetOptions options;
Expand Down Expand Up @@ -227,9 +228,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
9 changes: 5 additions & 4 deletions examples/RealtimeDatabase/Async/Callback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

Database.ota(aClient, "/test/firmware/bin", asyncCB, "otaTask");
Expand Down Expand Up @@ -184,9 +185,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
9 changes: 5 additions & 4 deletions examples/RealtimeDatabase/Async/NoCallback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

Database.ota(aClient, "/test/firmware/bin", aResult_no_callback);
Expand Down Expand Up @@ -177,9 +178,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
9 changes: 5 additions & 4 deletions examples/Storage/Async/Callback/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

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

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

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

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

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

storage.ota(aClient, FirebaseStorage::Parent(STORAGE_BUCKET_ID, "firmware.bin"), aResult_no_callback);
Expand Down Expand Up @@ -183,9 +184,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
9 changes: 5 additions & 4 deletions examples/Storage/Sync/OTA/OTA.ino
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
// See https://github.com/mobizt/FirebaseClient#ota-update.
#if defined(ARDUINO_ARCH_SAMD)
#include <Internal_Storage_OTA.h>
#define OTA_STORAGE InternalStorage
#endif

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

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

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

// There is no OTA download progress available for sync OTA download.
Expand Down Expand Up @@ -195,9 +196,9 @@ void restart()
{
Serial.println("Update firmware completed.");
Serial.println();
#if defined(FIREBASE_OTA_UPDATER_STORAGE)
#if defined(OTA_STORAGE)
Serial.println("Applying update...");
InternalStorage.apply();
OTA_STORAGE.apply();
#elif defined(ESP32) || defined(ESP8266)
Serial.println("Restarting...\n\n");
ESP.restart();
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "FirebaseClient",
"version": "1.3.1",
"version": "1.3.2",
"keywords": "communication, REST, esp32, esp8266, arduino",
"description": "Async Firebase Client library for Arduino.",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name=FirebaseClient

version=1.3.1
version=1.3.2

author=Mobizt

Expand Down
6 changes: 3 additions & 3 deletions resources/docs/cloud_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,14 @@ void deleteObject(AsyncClientClass &aClient, const GoogleCloudStorage::Parent &p
- `uid` - The user specified UID of async result (optional).


21. ## 🔹 void setOTAStorage(InternalStorageClass &storage)
21. ## 🔹 void setOTAStorage(OTAStorage &storage)

Set Arduino OTA Storage.

```cpp
void setOTAStorage(InternalStorageClass &storage)
void setOTAStorage(OTAStorage &storage)
```
**Params:**
- `storage` - The Arduino InternalStorageClass object.
- `storage` - The Arduino `OTAStorage` class object.
6 changes: 3 additions & 3 deletions resources/docs/realtime_database.md
Original file line number Diff line number Diff line change
Expand Up @@ -987,17 +987,17 @@ class RealtimeDatabase
**Params:**
- `filter` - The event keywords for filtering.

31. ## 🔹 void setOTAStorage(InternalStorageClass &storage)
31. ## 🔹 void setOTAStorage(OTAStorage &storage)

Set Arduino OTA Storage.

```cpp
void setOTAStorage(InternalStorageClass &storage)
void setOTAStorage(OTAStorage &storage)
```

**Params:**

- `storage` - The Arduino InternalStorageClass object.
- `storage` - The Arduino `OTAStorage` class object.

32. ### 🔹 void loop()

Expand Down
6 changes: 3 additions & 3 deletions resources/docs/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,14 @@ void deleteObject(AsyncClientClass &aClient, const FirebaseStorage::Parent &pare
- `cb` - The async result callback (AsyncResultCallback).
- `uid` - The user specified UID of async result (optional).

21. ## 🔹 void setOTAStorage(InternalStorageClass &storage)
21. ## 🔹 void setOTAStorage(OTAStorage &storage)

Set Arduino OTA Storage.

```cpp
void setOTAStorage(InternalStorageClass &storage)
void setOTAStorage(OTAStorage &storage)
```
**Params:**
- `storage` - The Arduino InternalStorageClass object.
- `storage` - The Arduino `OTAStorage` class object.
Loading

0 comments on commit a42d570

Please sign in to comment.