-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1b88b81
commit 4ab512f
Showing
9 changed files
with
252 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
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 | ||
created 13 July 2010 | ||
by dlf (Metodo2 srl) | ||
modified 31 May 2012 | ||
by Tom Igoe | ||
modified 16 January 2017 | ||
by Sandeep Mistry | ||
*/ | ||
|
||
#include <SPI.h> | ||
#include <WiFi101.h> | ||
#include <WiFi101OTA.h> | ||
|
||
char ssid[] = "yourNetwork"; // your network SSID (name) | ||
char pass[] = "secretPassword"; // 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 internal (flash) based storage | ||
WiFiOTA.begin("Arduino", "password", InternalStorage); | ||
|
||
// 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"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
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 | ||
*/ | ||
|
||
#include <Arduino.h> | ||
|
||
#include "InternalStorage.h" | ||
|
||
#define PAGE_SIZE (64) | ||
#define PAGES (4096) | ||
#define MAX_FLASH (PAGE_SIZE * PAGES) | ||
#define ROW_SIZE (PAGE_SIZE * 4) | ||
|
||
#define SKETCH_START_ADDRESS (0x2000) | ||
#define MAX_PARTIONED_SKETCH_SIZE ((MAX_FLASH - SKETCH_START_ADDRESS) / 2) | ||
#define STORAGE_START_ADDRESS (SKETCH_START_ADDRESS + MAX_PARTIONED_SKETCH_SIZE) | ||
|
||
extern "C" { | ||
// these functions must be in RAM (.data) and NOT inlined | ||
// as they erase and copy the sketch data in flash | ||
|
||
__attribute__ ((long_call, noinline, section (".data"))) | ||
static void eraseFlash(int address, int length) | ||
{ | ||
for (int i = 0; i < length; i += ROW_SIZE) { | ||
NVMCTRL->ADDR.reg = ((uint32_t)(address + i)) / 2; | ||
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_ER; | ||
|
||
while (!NVMCTRL->INTFLAG.bit.READY); | ||
} | ||
} | ||
|
||
__attribute__ ((long_call, noinline, section (".data"))) | ||
static void copyFlashAndReset(int dest, int src, int length) | ||
{ | ||
uint32_t* d = (uint32_t*)dest; | ||
uint32_t* s = (uint32_t*)src; | ||
|
||
eraseFlash(dest, length); | ||
|
||
for (int i = 0; i < length; i += 4) { | ||
*d++ = *s++; | ||
|
||
while (!NVMCTRL->INTFLAG.bit.READY); | ||
} | ||
|
||
NVIC_SystemReset(); | ||
} | ||
} | ||
|
||
int InternalStorageClass::open() | ||
{ | ||
_writeIndex = 0; | ||
_writeAddress = (uint32_t*)STORAGE_START_ADDRESS; | ||
|
||
// enable auto page writes | ||
NVMCTRL->CTRLB.bit.MANW = 0; | ||
|
||
eraseFlash(STORAGE_START_ADDRESS, MAX_PARTIONED_SKETCH_SIZE); | ||
|
||
return 1; | ||
} | ||
|
||
size_t InternalStorageClass::write(uint8_t b) | ||
{ | ||
_addressData.u8[_writeIndex] = b; | ||
_writeIndex++; | ||
|
||
if (_writeIndex == 4) { | ||
_writeIndex = 0; | ||
|
||
*_writeAddress = _addressData.u32; | ||
|
||
_writeAddress++; | ||
|
||
while (!NVMCTRL->INTFLAG.bit.READY); | ||
} | ||
|
||
return 1; | ||
} | ||
|
||
void InternalStorageClass::close() | ||
{ | ||
while ((int)_writeAddress % PAGE_SIZE) { | ||
write(0xff); | ||
} | ||
} | ||
|
||
void InternalStorageClass::clear() | ||
{ | ||
} | ||
|
||
void InternalStorageClass::apply() | ||
{ | ||
// disable interrupts, as vector table will be erase during flash sequence | ||
noInterrupts(); | ||
|
||
copyFlashAndReset(SKETCH_START_ADDRESS, STORAGE_START_ADDRESS, MAX_PARTIONED_SKETCH_SIZE); | ||
} | ||
|
||
InternalStorageClass InternalStorage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
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 _INTERNAL_STORAGE_H_INCLUDED | ||
#define _INTERNAL_STORAGE_H_INCLUDED | ||
|
||
#include "OTAStorage.h" | ||
|
||
class InternalStorageClass : public OTAStorage { | ||
public: | ||
virtual int open(); | ||
virtual size_t write(uint8_t); | ||
virtual void close(); | ||
virtual void clear(); | ||
virtual void apply(); | ||
|
||
private: | ||
union { | ||
uint32_t u32; | ||
uint8_t u8[4]; | ||
} _addressData; | ||
|
||
int _writeIndex; | ||
uint32_t* _writeAddress; | ||
}; | ||
|
||
extern InternalStorageClass InternalStorage; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters