diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index 5ca9b3962..9f6ac7e2d 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -57,7 +57,8 @@ jobs: - name: ArduinoECCX08 - name: RTCZero - name: WiFi101 - - name: WiFiNINA + # Use the version of WiFiNINA from the tip of its repository's default branch + - source-url: https://github.com/arduino-libraries/WiFiNINA.git - name: Arduino_MKRMEM sketch-paths: '"examples/utility/Provisioning" "examples/utility/WiFi_Cloud_Blink"' # LoRaWAN boards diff --git a/extras/tools/bin2json.py b/extras/tools/bin2json.py index b7371c87e..88f45731e 100755 --- a/extras/tools/bin2json.py +++ b/extras/tools/bin2json.py @@ -5,7 +5,7 @@ import base64 CHUNK_SIZE = 256 # This is the chunk size of how the binary is split on the server side for not overloading the embedded device receive buffers. -INTER_CHUNK_DELAY_MS = 250 # This is delay between 2 consecutive chunks so as to not over load the embedded device. +INTER_CHUNK_DELAY_MS = 500 # This is delay between 2 consecutive chunks so as to not over load the embedded device. if len(sys.argv) != 3: print ("Usage: bin2json.py sketch.ota sketch.json") diff --git a/src/ArduinoIoTCloudTCP.cpp b/src/ArduinoIoTCloudTCP.cpp index 4b350366f..84b73cb8d 100644 --- a/src/ArduinoIoTCloudTCP.cpp +++ b/src/ArduinoIoTCloudTCP.cpp @@ -29,8 +29,9 @@ #include "tls/utility/CryptoUtil.h" #endif -#include "utility/ota/OTAStorage_SSU.h" +#include "utility/ota/OTAStorage_SNU.h" #include "utility/ota/OTAStorage_SFU.h" +#include "utility/ota/OTAStorage_SSU.h" #include "cbor/CBOREncoder.h" @@ -44,6 +45,8 @@ TimeService time_service; static OTAStorage_SSU ota_storage_ssu; #elif OTA_STORAGE_SFU static OTAStorage_SFU ota_storage_sfu; +#elif OTA_STORAGE_SNU + static OTAStorage_SNU ota_storage_snu; #endif /****************************************************************************** @@ -148,6 +151,8 @@ int ArduinoIoTCloudTCP::begin(String brokerAddress, uint16_t brokerPort) setOTAStorage(ota_storage_ssu); #elif OTA_STORAGE_SFU setOTAStorage(ota_storage_sfu); +#elif OTA_STORAGE_SNU + setOTAStorage(ota_storage_snu); #endif return 1; diff --git a/src/ArduinoIoTCloud_Config.h b/src/ArduinoIoTCloud_Config.h index 1f08f20f2..bd5b27437 100644 --- a/src/ArduinoIoTCloud_Config.h +++ b/src/ArduinoIoTCloud_Config.h @@ -26,6 +26,12 @@ #define OTA_STORAGE_SFU (0) #endif +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) + #define OTA_STORAGE_SNU (1) +#else + #define OTA_STORAGE_SNU (0) +#endif + #ifdef ARDUINO_SAMD_MKRGSM1400 #define OTA_STORAGE_SSU (1) #else @@ -36,7 +42,7 @@ * AUTOMATIC CONFIGURED DEFINES ******************************************************************************/ -#if OTA_STORAGE_SFU || OTA_STORAGE_SSU +#if OTA_STORAGE_SFU || OTA_STORAGE_SSU || OTA_STORAGE_SNU #define OTA_ENABLED (1) #else #define OTA_ENABLED (0) diff --git a/src/utility/ota/OTAStorage_SNU.cpp b/src/utility/ota/OTAStorage_SNU.cpp new file mode 100644 index 000000000..3e50498c8 --- /dev/null +++ b/src/utility/ota/OTAStorage_SNU.cpp @@ -0,0 +1,101 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include +#if OTA_STORAGE_SNU + +#include "OTAStorage_SNU.h" + +#include + +/****************************************************************************** + * CONSTANTS + ******************************************************************************/ + +static char const SNU_UPDATE_FILENAME[] = "/fs/UPDATE.BIN"; +static char const SNU_TEMP_UPDATE_FILENAME[] = "/fs/UPDATE.BIN.TMP"; + +/****************************************************************************** + * PUBLIC MEMBER FUNCTIONS + ******************************************************************************/ + +bool OTAStorage_SNU::init() +{ + /* Ensure that there are no remains of previous + * aborted downloads still existing in the memory + * of the nina module. + */ + WiFiStorage.remove(SNU_TEMP_UPDATE_FILENAME); + return true; +} + +bool OTAStorage_SNU::open(char const * /* file_name */) +{ + /* There's no need to explicitly open the file + * because when writing to it the file will always + * be opened with "ab+" mode and closed after each + * call to 'write'. + */ + return true; +} + +size_t OTAStorage_SNU::write(uint8_t const * const buf, size_t const num_bytes) +{ + WiFiStorageFile file(SNU_TEMP_UPDATE_FILENAME); + + /* We have to write in chunks because otherwise we exceed the size of + * the SPI buffer within the nina module. + */ + size_t bytes_written = 0; + size_t const WRITE_CHUNK_SIZE = 32; + + for(; bytes_written < (num_bytes - WRITE_CHUNK_SIZE); bytes_written += WRITE_CHUNK_SIZE) + { + if (file.write(buf + bytes_written, WRITE_CHUNK_SIZE) != WRITE_CHUNK_SIZE) + return bytes_written; + } + + bytes_written += file.write(buf + bytes_written, num_bytes - bytes_written); + + return bytes_written; +} + +void OTAStorage_SNU::close() +{ + /* Files are closed after each file operation on the nina side. */ +} + +void OTAStorage_SNU::remove(char const * /* file_name */) +{ + WiFiStorage.remove(SNU_TEMP_UPDATE_FILENAME); +} + +bool OTAStorage_SNU::rename(char const * /* old_file_name */, char const * /* new_file_name */) +{ + return WiFiStorage.rename(SNU_TEMP_UPDATE_FILENAME, SNU_UPDATE_FILENAME); +} + +void OTAStorage_SNU::deinit() +{ + /* Nothing to do */ +} + +#endif /* OTA_STORAGE_SNU */ diff --git a/src/utility/ota/OTAStorage_SNU.h b/src/utility/ota/OTAStorage_SNU.h new file mode 100644 index 000000000..7d0f24d4e --- /dev/null +++ b/src/utility/ota/OTAStorage_SNU.h @@ -0,0 +1,55 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2020 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef ARDUINO_OTA_STORAGE_SNU_H_ +#define ARDUINO_OTA_STORAGE_SNU_H_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include +#if OTA_STORAGE_SNU + +#include + +#include "OTAStorage.h" + +/****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class OTAStorage_SNU : public OTAStorage +{ +public: + + virtual ~OTAStorage_SNU() { } + + + virtual bool init () override; + virtual bool open (char const * file_name) override; + virtual size_t write (uint8_t const * const buf, size_t const num_bytes) override; + virtual void close () override; + virtual void remove(char const * file_name) override; + virtual bool rename(char const * old_file_name, char const * new_file_name) override; + virtual void deinit() override; + +}; + +#endif /* OTA_STORAGE_SNU */ + +#endif /* ARDUINO_OTA_STORAGE_SNU_H_ */