From 9851ddca350c711aa83e8c62f8cbb74d034d0e7d Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 26 Sep 2018 09:55:42 +0200 Subject: [PATCH 01/10] Make library compatible with MKR1010 Should change library name too :) --- examples/WiFi101_OTA/WiFi101_OTA.ino | 1 - examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino | 1 - src/InternalStorage.cpp | 4 ++++ src/SDStorage.cpp | 10 +++++++++- src/SerialFlashStorage.cpp | 10 +++++++++- src/WiFi101OTA.cpp | 12 +----------- src/WiFi101OTA.h | 21 ++++++++++++++++++++- 7 files changed, 43 insertions(+), 16 deletions(-) diff --git a/examples/WiFi101_OTA/WiFi101_OTA.ino b/examples/WiFi101_OTA/WiFi101_OTA.ino index 10058a8..fe1a912 100644 --- a/examples/WiFi101_OTA/WiFi101_OTA.ino +++ b/examples/WiFi101_OTA/WiFi101_OTA.ino @@ -19,7 +19,6 @@ */ #include -#include #include #include "arduino_secrets.h" diff --git a/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino b/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino index 299a07f..0f7f4db 100644 --- a/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino +++ b/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino @@ -21,7 +21,6 @@ #include #include -#include #include #include diff --git a/src/InternalStorage.cpp b/src/InternalStorage.cpp index 94f46d5..597a9a6 100644 --- a/src/InternalStorage.cpp +++ b/src/InternalStorage.cpp @@ -16,6 +16,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef __AVR__ + #include #include "InternalStorage.h" @@ -119,3 +121,5 @@ long InternalStorageClass::maxSize() } InternalStorageClass InternalStorage; + +#endif \ No newline at end of file diff --git a/src/SDStorage.cpp b/src/SDStorage.cpp index 377ebcc..a4c65be 100644 --- a/src/SDStorage.cpp +++ b/src/SDStorage.cpp @@ -20,6 +20,14 @@ #define UPDATE_FILE "UPDATE.BIN" +static inline void reboot() { +#ifdef __AVR__ + +#else + NVIC_SystemReset(); +#endif +} + int SDStorageClass::open(int length) { (void)length; @@ -50,7 +58,7 @@ void SDStorageClass::clear() void SDStorageClass::apply() { // just reset, SDU copies the data to flash - NVIC_SystemReset(); + reboot(); } SDStorageClass SDStorage; diff --git a/src/SerialFlashStorage.cpp b/src/SerialFlashStorage.cpp index 5992d71..a68f3fc 100644 --- a/src/SerialFlashStorage.cpp +++ b/src/SerialFlashStorage.cpp @@ -20,6 +20,14 @@ #define UPDATE_FILE "UPDATE.BIN" +static inline void reboot() { +#ifdef __AVR__ + +#else + NVIC_SystemReset(); +#endif +} + int SerialFlashStorageClass::open(int contentLength) { if (!SerialFlash.begin(SERIAL_FLASH_CS)) { @@ -63,7 +71,7 @@ void SerialFlashStorageClass::clear() void SerialFlashStorageClass::apply() { // just reset, SDU copies the data to flash - NVIC_SystemReset(); + reboot(); } SerialFlashStorageClass SerialFlashStorage; diff --git a/src/WiFi101OTA.cpp b/src/WiFi101OTA.cpp index 7e511ad..927d77f 100644 --- a/src/WiFi101OTA.cpp +++ b/src/WiFi101OTA.cpp @@ -20,16 +20,6 @@ #include "WiFi101OTA.h" -#if defined(ARDUINO_SAMD_ZERO) - #define BOARD "arduino_zero_edbg" -#elif defined(ARDUINO_SAMD_MKR1000) - #define BOARD "mkr1000" -#elif defined(ARDUINO_SAMD_MKRZERO) - #define BOARD "mkrzero" -#else - #error "Unsupported board!" -#endif - #define BOARD_LENGTH (sizeof(BOARD) - 1) static String base64Encode(const String& in) @@ -82,7 +72,7 @@ void WiFiOTAClass::begin(const char* name, const char* password, OTAStorage& sto _server.begin(); - _mdnsSocket.beginMulti(IPAddress(224, 0, 0, 251), 5353); + _mdnsSocket.beginMulticast(IPAddress(224, 0, 0, 251), 5353); } void WiFiOTAClass::poll() diff --git a/src/WiFi101OTA.h b/src/WiFi101OTA.h index 2f05b1f..b0baac0 100644 --- a/src/WiFi101OTA.h +++ b/src/WiFi101OTA.h @@ -21,13 +21,32 @@ #include -#include "WiFi101.h" +#if defined(ARDUINO_SAMD_ZERO) + #include "WiFi101.h" + #define BOARD "arduino_zero_edbg" +#elif defined(ARDUINO_SAMD_MKR1000) + #include "WiFi101.h" + #define BOARD "mkr1000" +#elif defined(ARDUINO_SAMD_MKRZERO) + #include "WiFi101.h" + #define BOARD "mkrzero" +#elif defined(ARDUINO_SAMD_MKRWIFI1010) + #include "WiFiNINA.h" + #define BOARD "mkrwifi1010" +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_MEGAAVR_UNO_WIFI_REV2) + #include "WiFiNINA.h" + #define BOARD "uno2018" +#else + #error "Unsupported board!" +#endif + #include "WiFiUdp.h" #include "OTAStorage.h" #include "SDStorage.h" #include "InternalStorage.h" #include "SerialFlashStorage.h" +#include "NINAStorage.h" class WiFiOTAClass { public: From 2b24a22f1b3f707a2eb15d3d5b50a5c2a207beda Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Tue, 11 Dec 2018 17:18:43 +0100 Subject: [PATCH 02/10] WIP: Add NINAStorage backend --- src/NINAStorage.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++ src/NINAStorage.h | 40 ++++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/NINAStorage.cpp create mode 100644 src/NINAStorage.h diff --git a/src/NINAStorage.cpp b/src/NINAStorage.cpp new file mode 100644 index 0000000..c26507b --- /dev/null +++ b/src/NINAStorage.cpp @@ -0,0 +1,75 @@ +/* + Copyright (c) 2018 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "NINAStorage.h" + +#define UPDATE_FILE "/fs/UPDATE.BIN" + +static inline void reboot() { +#ifdef __AVR__ + /* Write boot request */ + USERROW.USERROW31 = 0xEB; + _PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc); + while(NVMCTRL.STATUS & NVMCTRL_EEBUSY_bm); + + _PROTECTED_WRITE(RSTCTRL.SWRR, RSTCTRL_SWRE_bm); +#else + NVIC_SystemReset(); +#endif +} + +int NINAStorageClass::open(int contentLength) +{ + if (WiFiStorage.exists(UPDATE_FILE)) { + WiFiStorage.remove(UPDATE_FILE); + } + + WiFiStorageFile file = WiFiStorage.open(UPDATE_FILE); + + if (!file) { + return 0; + } + + _file = &file; + + return 1; +} + +size_t NINAStorageClass::write(uint8_t b) +{ + int ret = _file->write(&b, 1); + return ret; +} + +void NINAStorageClass::close() +{ + _file->close(); +} + +void NINAStorageClass::clear() +{ + WiFiStorage.remove(UPDATE_FILE); +} + +void NINAStorageClass::apply() +{ + WiFiDrv::applyOTA(); + reboot(); +} + +NINAStorageClass NINAStorage; diff --git a/src/NINAStorage.h b/src/NINAStorage.h new file mode 100644 index 0000000..f48d60d --- /dev/null +++ b/src/NINAStorage.h @@ -0,0 +1,40 @@ +/* + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _NINA_STORAGE_H_INCLUDED +#define _NINA_STORAGE_H_INCLUDED + +#include + +#include "OTAStorage.h" + +class NINAStorageClass : public OTAStorage { +public: + virtual int open(int length); + virtual size_t write(uint8_t); + virtual void close(); + virtual void clear(); + virtual void apply(); + +private: + WiFiStorageFile* _file; +}; + +extern NINAStorageClass NINAStorage; + +#endif From cc56edb84d3577c65b6cc6db5f3d4c0dbf6e4859 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 12 Dec 2018 11:36:10 +0100 Subject: [PATCH 03/10] Use downloadAPI if available --- src/NINAStorage.cpp | 18 ++++++++++++++---- src/NINAStorage.h | 5 +++++ src/OTAStorage.h | 6 ++++++ src/WiFi101OTA.cpp | 13 +++++++++++-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/NINAStorage.cpp b/src/NINAStorage.cpp index c26507b..4d11e01 100644 --- a/src/NINAStorage.cpp +++ b/src/NINAStorage.cpp @@ -41,10 +41,6 @@ int NINAStorageClass::open(int contentLength) WiFiStorageFile file = WiFiStorage.open(UPDATE_FILE); - if (!file) { - return 0; - } - _file = &file; return 1; @@ -72,4 +68,18 @@ void NINAStorageClass::apply() reboot(); } +void NINAStorageClass::download(String url) +{ + WiFiStorage.download(url, "UPDATE.BIN"); +} + +long NINAStorageClass::maxSize() +{ +#ifdef __AVR__ + return (0xFFFF - 0x3FFF - 0x100); +#else + return ((256 * 1024) - 0x2000); +#endif +} + NINAStorageClass NINAStorage; diff --git a/src/NINAStorage.h b/src/NINAStorage.h index f48d60d..dd7ceac 100644 --- a/src/NINAStorage.h +++ b/src/NINAStorage.h @@ -30,6 +30,11 @@ class NINAStorageClass : public OTAStorage { virtual void close(); virtual void clear(); virtual void apply(); + virtual long maxSize(); + virtual void download(String url); + virtual bool hasDownloadAPI() { + return true; + } private: WiFiStorageFile* _file; diff --git a/src/OTAStorage.h b/src/OTAStorage.h index 77d5418..b4aefe6 100644 --- a/src/OTAStorage.h +++ b/src/OTAStorage.h @@ -30,6 +30,12 @@ class OTAStorage { virtual long maxSize() { return ((256 * 1024) - 0x2000); } + virtual void download(String url) { + + } + virtual bool hasDownloadAPI() { + return false; + } }; #endif diff --git a/src/WiFi101OTA.cpp b/src/WiFi101OTA.cpp index 927d77f..6a1787e 100644 --- a/src/WiFi101OTA.cpp +++ b/src/WiFi101OTA.cpp @@ -287,15 +287,24 @@ void WiFiOTAClass::pollServer() } long read = 0; + String url; while (client.connected() && read < contentLength) { while (client.available()) { read++; - - _storage->write((char)client.read()); + char c = (char)client.read(); + if (_storage->hasDownloadAPI()) { + url += c; + } else { + _storage->write(c); + } } } + if (_storage->hasDownloadAPI()) { + _storage->download(url); + } + _storage->close(); if (read == contentLength) { From 104617302c02ec88acd0e387dc88adb1e22c9162 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 9 Aug 2019 09:23:27 +0200 Subject: [PATCH 04/10] Add Nano33IoT and MKRVidor as targets --- src/WiFi101OTA.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/WiFi101OTA.h b/src/WiFi101OTA.h index b0baac0..64cf9ee 100644 --- a/src/WiFi101OTA.h +++ b/src/WiFi101OTA.h @@ -33,6 +33,12 @@ #elif defined(ARDUINO_SAMD_MKRWIFI1010) #include "WiFiNINA.h" #define BOARD "mkrwifi1010" +#elif defined(ARDUINO_SAMD_NANO_33_IOT) + #include "WiFiNINA.h" + #define BOARD "nano_33_iot" +#elif defined(ARDUINO_SAMD_MKRVIDOR4000) + #include "WiFiNINA.h" + #define BOARD "mkrvidor4000" #elif defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_MEGAAVR_UNO_WIFI_REV2) #include "WiFiNINA.h" #define BOARD "uno2018" From 138e68acc48972eda556c37bcc75170b94121dff Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 14 Aug 2019 10:40:07 +0200 Subject: [PATCH 05/10] Update keywords.txt --- keywords.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/keywords.txt b/keywords.txt index 0972e9e..ec605e9 100644 --- a/keywords.txt +++ b/keywords.txt @@ -11,6 +11,8 @@ WiFiOTA KEYWORD1 InternalStorage KEYWORD1 SDStorage KEYWORD1 +NINAStorage KEYWORD1 +SerialFlashStorage KEYWORD1 ####################################### # Methods and Functions (KEYWORD2) From cba64b0a7dda6d9fcec096229fb747e543d7864c Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 14 Aug 2019 10:40:58 +0200 Subject: [PATCH 06/10] Use _has_include to select correct OTA medium --- src/NINAStorage.cpp | 4 ++++ src/NINAStorage.h | 13 ++++++++++++- src/SDStorage.cpp | 4 ++++ src/SDStorage.h | 13 ++++++++++++- src/SerialFlashStorage.cpp | 4 ++++ src/SerialFlashStorage.h | 13 ++++++++++++- 6 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/NINAStorage.cpp b/src/NINAStorage.cpp index 4d11e01..6d22096 100644 --- a/src/NINAStorage.cpp +++ b/src/NINAStorage.cpp @@ -18,6 +18,8 @@ #include "NINAStorage.h" +#ifdef HAS_NINA + #define UPDATE_FILE "/fs/UPDATE.BIN" static inline void reboot() { @@ -83,3 +85,5 @@ long NINAStorageClass::maxSize() } NINAStorageClass NINAStorage; + +#endif \ No newline at end of file diff --git a/src/NINAStorage.h b/src/NINAStorage.h index dd7ceac..82292bf 100644 --- a/src/NINAStorage.h +++ b/src/NINAStorage.h @@ -19,7 +19,17 @@ #ifndef _NINA_STORAGE_H_INCLUDED #define _NINA_STORAGE_H_INCLUDED -#include +#ifdef __has_include + #if __has_include() + #include + #define HAS_NINA 1 + #endif +#else + #include + #define HAS_NINA 1 +#endif + +#ifdef HAS_NINA #include "OTAStorage.h" @@ -43,3 +53,4 @@ class NINAStorageClass : public OTAStorage { extern NINAStorageClass NINAStorage; #endif +#endif diff --git a/src/SDStorage.cpp b/src/SDStorage.cpp index a4c65be..9fc77f9 100644 --- a/src/SDStorage.cpp +++ b/src/SDStorage.cpp @@ -18,6 +18,8 @@ #include "SDStorage.h" +#ifdef HAS_SD + #define UPDATE_FILE "UPDATE.BIN" static inline void reboot() { @@ -62,3 +64,5 @@ void SDStorageClass::apply() } SDStorageClass SDStorage; + +#endif \ No newline at end of file diff --git a/src/SDStorage.h b/src/SDStorage.h index 9f9479f..46f046c 100644 --- a/src/SDStorage.h +++ b/src/SDStorage.h @@ -19,7 +19,17 @@ #ifndef _SD_STORAGE_H_INCLUDED #define _SD_STORAGE_H_INCLUDED -#include +#ifdef __has_include + #if __has_include() + #include + #define HAS_SD 1 + #endif +#else + #include + #define HAS_SD 1 +#endif + +#ifdef HAS_SD #include "OTAStorage.h" @@ -42,3 +52,4 @@ class SDStorageClass : public OTAStorage { extern SDStorageClass SDStorage; #endif +#endif diff --git a/src/SerialFlashStorage.cpp b/src/SerialFlashStorage.cpp index a68f3fc..ed55718 100644 --- a/src/SerialFlashStorage.cpp +++ b/src/SerialFlashStorage.cpp @@ -18,6 +18,8 @@ #include "SerialFlashStorage.h" +#ifdef HAS_SERIALFLASH + #define UPDATE_FILE "UPDATE.BIN" static inline void reboot() { @@ -75,3 +77,5 @@ void SerialFlashStorageClass::apply() } SerialFlashStorageClass SerialFlashStorage; + +#endif \ No newline at end of file diff --git a/src/SerialFlashStorage.h b/src/SerialFlashStorage.h index f2af6c0..2dccfd5 100644 --- a/src/SerialFlashStorage.h +++ b/src/SerialFlashStorage.h @@ -19,7 +19,17 @@ #ifndef _SERIALFLASH_STORAGE_H_INCLUDED #define _SERIALFLASH_STORAGE_H_INCLUDED -#include +#ifdef __has_include + #if __has_include() + #include + #define HAS_SERIALFLASH 1 + #endif +#else + #include + #define HAS_SERIALFLASH 1 +#endif + +#ifdef HAS_SERIALFLASH #include "OTAStorage.h" @@ -41,3 +51,4 @@ class SerialFlashStorageClass : public OTAStorage { extern SerialFlashStorageClass SerialFlashStorage; #endif +#endif From 615380f10e2f9b025e634540bfeaa01560588e10 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Wed, 14 Aug 2019 12:37:14 +0200 Subject: [PATCH 07/10] Add NINAStorageRaw class to avoid forcin downloadAPI --- src/NINAStorage.cpp | 4 +- src/NINAStorageRaw.cpp | 100 +++++++++++++++++++++++++++++++++++++++++ src/NINAStorageRaw.h | 56 +++++++++++++++++++++++ src/WiFi101OTA.h | 1 + 4 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 src/NINAStorageRaw.cpp create mode 100644 src/NINAStorageRaw.h diff --git a/src/NINAStorage.cpp b/src/NINAStorage.cpp index 6d22096..d04d0ad 100644 --- a/src/NINAStorage.cpp +++ b/src/NINAStorage.cpp @@ -41,9 +41,7 @@ int NINAStorageClass::open(int contentLength) WiFiStorage.remove(UPDATE_FILE); } - WiFiStorageFile file = WiFiStorage.open(UPDATE_FILE); - - _file = &file; + _file = new WiFiStorageFile(UPDATE_FILE); return 1; } diff --git a/src/NINAStorageRaw.cpp b/src/NINAStorageRaw.cpp new file mode 100644 index 0000000..b5b20f3 --- /dev/null +++ b/src/NINAStorageRaw.cpp @@ -0,0 +1,100 @@ +/* + Copyright (c) 2018 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "NINAStorageRaw.h" + +#ifdef HAS_NINA + +#define UPDATE_FILE "/fs/UPDATE.BIN" + +static inline void reboot() { +#ifdef __AVR__ + /* Write boot request */ + USERROW.USERROW31 = 0xEB; + _PROTECTED_WRITE_SPM(NVMCTRL.CTRLA, NVMCTRL_CMD_PAGEERASEWRITE_gc); + while(NVMCTRL.STATUS & NVMCTRL_EEBUSY_bm); + + _PROTECTED_WRITE(RSTCTRL.SWRR, RSTCTRL_SWRE_bm); +#else + NVIC_SystemReset(); +#endif +} + +int NINAStorageRawClass::open(int contentLength) +{ + if (WiFiStorage.exists(UPDATE_FILE)) { + WiFiStorage.remove(UPDATE_FILE); + } + + _file = new WiFiStorageFile(UPDATE_FILE); + + return 1; +} + +static int buffer_index = 0; +static uint8_t buffer[2048]; + +size_t NINAStorageRawClass::write(uint8_t b) +{ + // buffer bytes in 2Kbytes chunks, otherwise this thing is slow as hell + if (buffer_index < sizeof(buffer)) { + buffer[buffer_index] = b; + buffer_index++; + } + if (buffer_index >= sizeof(buffer)) { + _file->write(buffer, sizeof(buffer)); + buffer_index = 0; + } + return 1; +} + +void NINAStorageRawClass::close() +{ + if (buffer_index > 0) { + _file->write(buffer, buffer_index); + } + _file->close(); +} + +void NINAStorageRawClass::clear() +{ + WiFiStorage.remove(UPDATE_FILE); +} + +void NINAStorageRawClass::apply() +{ + reboot(); +} + +void NINAStorageRawClass::download(String url) +{ + WiFiStorage.download(url, "UPDATE.BIN"); +} + +long NINAStorageRawClass::maxSize() +{ +#ifdef __AVR__ + return (0xFFFF - 0x3FFF - 0x100); +#else + return ((256 * 1024) - 0x2000); +#endif +} + +NINAStorageRawClass NINAStorageRaw; + +#endif \ No newline at end of file diff --git a/src/NINAStorageRaw.h b/src/NINAStorageRaw.h new file mode 100644 index 0000000..3a605cc --- /dev/null +++ b/src/NINAStorageRaw.h @@ -0,0 +1,56 @@ +/* + Copyright (c) 2017 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _NINA_STORAGERAW_H_INCLUDED +#define _NINA_STORAGERAW_H_INCLUDED + +#ifdef __has_include + #if __has_include() + #include + #define HAS_NINA 1 + #endif +#else + #include + #define HAS_NINA 1 +#endif + +#ifdef HAS_NINA + +#include "OTAStorage.h" + +class NINAStorageRawClass : public OTAStorage { +public: + virtual int open(int length); + virtual size_t write(uint8_t); + virtual void close(); + virtual void clear(); + virtual void apply(); + virtual long maxSize(); + virtual void download(String url); + virtual bool hasDownloadAPI() { + return false; + } + +private: + WiFiStorageFile* _file; +}; + +extern NINAStorageRawClass NINAStorageRaw; + +#endif +#endif \ No newline at end of file diff --git a/src/WiFi101OTA.h b/src/WiFi101OTA.h index 64cf9ee..fe89841 100644 --- a/src/WiFi101OTA.h +++ b/src/WiFi101OTA.h @@ -53,6 +53,7 @@ #include "InternalStorage.h" #include "SerialFlashStorage.h" #include "NINAStorage.h" +#include "NINAStorageRaw.h" class WiFiOTAClass { public: From 60be3635a2a7b14d238aa147bd46aac85401bc24 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 22 Aug 2019 13:07:44 +0200 Subject: [PATCH 08/10] Mass rename of the library --- .../{WiFi101_OTA/WiFi101_OTA.ino => WiFi_OTA/WiFi_OTA.ino} | 2 +- examples/{WiFi101_OTA => WiFi_OTA}/arduino_secrets.h | 0 .../WiFi101_SD_OTA.ino => WiFi_SD_OTA/WiFi_SD_OTA.ino} | 2 +- examples/{WiFi101_SD_OTA => WiFi_SD_OTA}/arduino_secrets.h | 0 library.properties | 6 +++--- src/{WiFi101OTA.cpp => Arduino_WiFiOTA.cpp} | 2 +- src/{WiFi101OTA.h => Arduino_WiFiOTA.h} | 0 7 files changed, 6 insertions(+), 6 deletions(-) rename examples/{WiFi101_OTA/WiFi101_OTA.ino => WiFi_OTA/WiFi_OTA.ino} (98%) rename examples/{WiFi101_OTA => WiFi_OTA}/arduino_secrets.h (100%) rename examples/{WiFi101_SD_OTA/WiFi101_SD_OTA.ino => WiFi_SD_OTA/WiFi_SD_OTA.ino} (98%) rename examples/{WiFi101_SD_OTA => WiFi_SD_OTA}/arduino_secrets.h (100%) rename src/{WiFi101OTA.cpp => Arduino_WiFiOTA.cpp} (99%) rename src/{WiFi101OTA.h => Arduino_WiFiOTA.h} (100%) diff --git a/examples/WiFi101_OTA/WiFi101_OTA.ino b/examples/WiFi_OTA/WiFi_OTA.ino similarity index 98% rename from examples/WiFi101_OTA/WiFi101_OTA.ino rename to examples/WiFi_OTA/WiFi_OTA.ino index fe1a912..d893e90 100644 --- a/examples/WiFi101_OTA/WiFi101_OTA.ino +++ b/examples/WiFi_OTA/WiFi_OTA.ino @@ -19,7 +19,7 @@ */ #include -#include +#include #include "arduino_secrets.h" ///////please enter your sensitive data in the Secret tab/arduino_secrets.h diff --git a/examples/WiFi101_OTA/arduino_secrets.h b/examples/WiFi_OTA/arduino_secrets.h similarity index 100% rename from examples/WiFi101_OTA/arduino_secrets.h rename to examples/WiFi_OTA/arduino_secrets.h diff --git a/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino b/examples/WiFi_SD_OTA/WiFi_SD_OTA.ino similarity index 98% rename from examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino rename to examples/WiFi_SD_OTA/WiFi_SD_OTA.ino index 0f7f4db..220ea5f 100644 --- a/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino +++ b/examples/WiFi_SD_OTA/WiFi_SD_OTA.ino @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include "arduino_secrets.h" diff --git a/examples/WiFi101_SD_OTA/arduino_secrets.h b/examples/WiFi_SD_OTA/arduino_secrets.h similarity index 100% rename from examples/WiFi101_SD_OTA/arduino_secrets.h rename to examples/WiFi_SD_OTA/arduino_secrets.h diff --git a/library.properties b/library.properties index 6fe1136..b23f011 100644 --- a/library.properties +++ b/library.properties @@ -1,9 +1,9 @@ -name=WiFi101OTA -version=1.0.2 +name=Arduino_WiFiOTA +version=1.1.0 author=Arduino maintainer=Arduino sentence=Update sketches on your board over WiFi paragraph=Requires an Arduino/Genuino SAMD board category=Other url=http://www.arduino.cc/en/Reference/WiFi101OTA -architectures=samd +architectures=samd,megaavr diff --git a/src/WiFi101OTA.cpp b/src/Arduino_WiFiOTA.cpp similarity index 99% rename from src/WiFi101OTA.cpp rename to src/Arduino_WiFiOTA.cpp index 6a1787e..4e7173b 100644 --- a/src/WiFi101OTA.cpp +++ b/src/Arduino_WiFiOTA.cpp @@ -18,7 +18,7 @@ #include -#include "WiFi101OTA.h" +#include "Arduino_WiFiOTA.h" #define BOARD_LENGTH (sizeof(BOARD) - 1) diff --git a/src/WiFi101OTA.h b/src/Arduino_WiFiOTA.h similarity index 100% rename from src/WiFi101OTA.h rename to src/Arduino_WiFiOTA.h From b73f052fdb92f5b4ea02cb5c4d48478d95a636c6 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 22 Aug 2019 13:07:58 +0200 Subject: [PATCH 09/10] Add missing keywords --- keywords.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/keywords.txt b/keywords.txt index ec605e9..cbadce3 100644 --- a/keywords.txt +++ b/keywords.txt @@ -12,6 +12,7 @@ WiFiOTA KEYWORD1 InternalStorage KEYWORD1 SDStorage KEYWORD1 NINAStorage KEYWORD1 +NINAStorageRaw KEYWORD1 SerialFlashStorage KEYWORD1 ####################################### From 7c02a6f1c67e2354f4e65b44b670db819b612698 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 22 Aug 2019 13:08:12 +0200 Subject: [PATCH 10/10] Add NINAStorage example --- examples/WiFi_Nina_OTA/WiFi_Nina_OTA.ino | 91 ++++++++++++++++++++++++ examples/WiFi_Nina_OTA/arduino_secrets.h | 3 + 2 files changed, 94 insertions(+) create mode 100644 examples/WiFi_Nina_OTA/WiFi_Nina_OTA.ino create mode 100644 examples/WiFi_Nina_OTA/arduino_secrets.h diff --git a/examples/WiFi_Nina_OTA/WiFi_Nina_OTA.ino b/examples/WiFi_Nina_OTA/WiFi_Nina_OTA.ino new file mode 100644 index 0000000..ba74901 --- /dev/null +++ b/examples/WiFi_Nina_OTA/WiFi_Nina_OTA.ino @@ -0,0 +1,91 @@ +/* + + This example connects to an WPA encrypted WiFi network. + Then it prints the MAC address of the Wifi shield, + the IP address obtained, and other network details. + It then polls for sketch updates over WiFi, sketches + can be updated by selecting a network port from within + the Arduino IDE: Tools -> Port -> Network Ports ... + + Circuit: + * WiFi shield attached + * SD shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 16 January 2017 + by Sandeep Mistry + */ + +#include + +// SAMD boards use a second stage bootloader approach and have enough RAM to retrieve the update firmware by themselves +// Uno WiFi Rev2 needs some little help, so the Nina module takes care of dowloading and flashing the board + +#ifdef ARDUINO_ARCH_SAMD +#include +#define STORAGE NINAStorageRaw +#else +#define STORAGE NINAStorage +#endif + + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// Wifi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password + +int status = WL_IDLE_STATUS; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to Wifi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // start the WiFi OTA library with Nina based storage + WiFiOTA.begin("Arduino", "password", STORAGE); + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // check for WiFi OTA updates + WiFiOTA.poll(); + + // add your normal loop code below ... +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/examples/WiFi_Nina_OTA/arduino_secrets.h b/examples/WiFi_Nina_OTA/arduino_secrets.h new file mode 100644 index 0000000..a8ff904 --- /dev/null +++ b/examples/WiFi_Nina_OTA/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" +