-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make library compatible with NINA WiFi module #15
base: master
Are you sure you want to change the base?
Changes from all commits
9851ddc
2b24a22
cc56edb
1046173
138e68a
cba64b0
615380f
60be363
b73f052
7c02a6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,91 @@ | ||||||
/* | ||||||
|
||||||
This example connects to an WPA encrypted WiFi network. | ||||||
Then it prints the MAC address of the Wifi shield, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 <Arduino_WiFiOTA.h> | ||||||
|
||||||
// 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 <SNU.h> | ||||||
#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):"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Serial.print(rssi); | ||||||
Serial.println(" dBm"); | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#define SECRET_SSID "" | ||
#define SECRET_PASS "" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
name=WiFi101OTA | ||
version=1.0.2 | ||
name=Arduino_WiFiOTA | ||
version=1.1.0 | ||
author=Arduino | ||
maintainer=Arduino <[email protected]> | ||
sentence=Update sketches on your board over WiFi | ||
paragraph=Requires an Arduino/Genuino SAMD board | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should read "SAMD or MEGA AVR" |
||
category=Other | ||
url=http://www.arduino.cc/en/Reference/WiFi101OTA | ||
architectures=samd | ||
architectures=samd,megaavr |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
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" | ||
|
||
#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 NINAStorageClass::open(int contentLength) | ||
{ | ||
if (WiFiStorage.exists(UPDATE_FILE)) { | ||
WiFiStorage.remove(UPDATE_FILE); | ||
} | ||
|
||
_file = new WiFiStorageFile(UPDATE_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(); | ||
} | ||
|
||
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; | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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_STORAGE_H_INCLUDED | ||
#define _NINA_STORAGE_H_INCLUDED | ||
|
||
#ifdef __has_include | ||
#if __has_include(<WiFiStorage.h>) | ||
#include <WiFiStorage.h> | ||
#define HAS_NINA 1 | ||
#endif | ||
#else | ||
#include <WiFiStorage.h> | ||
#define HAS_NINA 1 | ||
#endif | ||
|
||
#ifdef HAS_NINA | ||
|
||
#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(); | ||
virtual long maxSize(); | ||
virtual void download(String url); | ||
virtual bool hasDownloadAPI() { | ||
return true; | ||
} | ||
|
||
private: | ||
WiFiStorageFile* _file; | ||
}; | ||
|
||
extern NINAStorageClass NINAStorage; | ||
|
||
#endif | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.