IP Configuration
This commit is contained in:
62
lib/WiFiNINA/CHANGELOG
Normal file
62
lib/WiFiNINA/CHANGELOG
Normal file
@@ -0,0 +1,62 @@
|
||||
WiFiNINA ?.?.? - ????.??.??
|
||||
|
||||
WiFiNINA 1.8.0 - 2020.11.18
|
||||
|
||||
* Limit the maximum length of the download URL for the OTA binary since the receive buffer on the nina firmware can't hold more than 128 bytes (#131)
|
||||
* Introduce WiFiBearSSLClient (offloaded to Nina) (#139)
|
||||
* Change WIFI_FIRMWARE_LATEST_VERSION to 1.4.2
|
||||
|
||||
WiFiNINA 1.7.1 - 2020.08.26
|
||||
|
||||
* Change WIFI_FIRMWARE_LATEST_VERSION to 1.4.1
|
||||
|
||||
WiFiNINA 1.7.0 - 2020.08.06
|
||||
|
||||
* Add downloadOTA command to download OTA file and verify length/CRC (#124) (to be used together with nina-fw > arduino/nina-fw@d4a2118)
|
||||
|
||||
WiFiNINA 1.6.0 - 2020.07.13
|
||||
|
||||
* Adding API to make use of file storage/retieval capability available since nina-fw 1.5.0 (#74)
|
||||
* Speed up of duration of function ServerDrv::getDataBuf (#84)
|
||||
|
||||
WiFiNINA 1.5.0 - 2019.12.30
|
||||
|
||||
* Add WiFi.reasonCode() API to retrieve the deauthentication reason code
|
||||
* Use WIFI_FIRMWARE_LATEST_VERSION in example sketch FW version checks
|
||||
* Updated firmware updaters for Nano 33 IoT
|
||||
* Added Nano 33 IoT to explicit targets list
|
||||
* Added WPA2 Enterprise support: PEAP/MSCHAPv2 (depends on NINA f/w 1.3.0)
|
||||
|
||||
WiFiNINA 1.4.0 - 2019.03.27
|
||||
|
||||
* Improved connection time, by increasing poll time of checking connection status to 100ms on begin
|
||||
* Added WiFiClass::setTimeout(...) API to set timeout of begin
|
||||
* Fixed issue of WiFiServer:available() only reporting the first byte in the WiFiChatServer example
|
||||
|
||||
WiFiNINA 1.3.0 - 2018.11.13
|
||||
|
||||
* Added Tools/CheckFirmwareVersion example to check NINA firmware version
|
||||
* Changed examples where required, the server's URL arduino.cc:80 to example.org:80, because http://arduino.cc will be no longer available
|
||||
* Changed WiFi.end() to not put the reset pin mode in input mode
|
||||
* Use 1000000 baud for the firmware updater, and added support for the Uno WiFi Rev2
|
||||
|
||||
WiFiNINA 1.2.0 - 2018.10.05
|
||||
|
||||
* Changed WiFi.begin(...) not to fail, if not connected in 5 seconds
|
||||
* Removed retrying to get the host by name if it fails
|
||||
* Renamed WiFiNINAFirmwareUpdater example to SerialNINAPassthrough
|
||||
* Added new Firmware Updater Tool sketch (which talks to ESP32 boot ROM)
|
||||
* Changed firmware version comparison check to < instead of !=
|
||||
|
||||
WiFiNINA 1.1.1 - 2018.09.11
|
||||
|
||||
* Improved byte by byte read performance of sockets by adding a socket buffer
|
||||
|
||||
WiFiNINA 1.1.0 - 2018.08.13
|
||||
|
||||
* Added support for MKR Vidor 4000
|
||||
* Added handling of unknown encryption type in the ScanNetworks example
|
||||
|
||||
WiFiNINA 1.0.0 - 2018.07.11
|
||||
|
||||
* Initial release
|
||||
35
lib/WiFiNINA/README.adoc
Normal file
35
lib/WiFiNINA/README.adoc
Normal file
@@ -0,0 +1,35 @@
|
||||
// Define the repository information in these attributes
|
||||
:repository-owner: arduino-libraries
|
||||
:repository-name: WiFiNINA
|
||||
|
||||
= {repository-name} library for Arduino =
|
||||
|
||||
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"]
|
||||
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"]
|
||||
image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"]
|
||||
|
||||
Enables network connection (local and Internet) with the Arduino MKR WiFi 1010, Arduino MKR VIDOR 4000 and Arduino UNO WiFi Rev.2.
|
||||
|
||||
With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The board can connect either to open or encrypted networks (WEP, WPA). The IP address can be assigned statically or through a DHCP. The library can also manage DNS.
|
||||
|
||||
For more information about this library please visit us at
|
||||
https://www.arduino.cc/en/Reference/{repository-name}
|
||||
|
||||
== License ==
|
||||
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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
|
||||
163
lib/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino
Normal file
163
lib/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
WiFi Web Server LED Blink
|
||||
|
||||
A simple web server that lets you blink an LED via the web.
|
||||
This sketch will create a new access point (with no password).
|
||||
It will then launch a new server and print out the IP address
|
||||
to the Serial Monitor. From there, you can open that address in a web browser
|
||||
to turn on and off the LED on pin 13.
|
||||
|
||||
If the IP address of your board is yourAddress:
|
||||
http://yourAddress/H turns the LED on
|
||||
http://yourAddress/L turns it off
|
||||
|
||||
created 25 Nov 2012
|
||||
by Tom Igoe
|
||||
adapted to WiFi AP by Adafruit
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int led = LED_BUILTIN;
|
||||
int status = WL_IDLE_STATUS;
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
Serial.println("Access Point Web Server");
|
||||
|
||||
pinMode(led, OUTPUT); // set the LED pin mode
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// by default the local IP address will be 192.168.4.1
|
||||
// you can override it with the following:
|
||||
// WiFi.config(IPAddress(10, 0, 0, 1));
|
||||
|
||||
// print the network name (SSID);
|
||||
Serial.print("Creating access point named: ");
|
||||
Serial.println(ssid);
|
||||
|
||||
// Create open network. Change this line if you want to create an WEP network:
|
||||
status = WiFi.beginAP(ssid, pass);
|
||||
if (status != WL_AP_LISTENING) {
|
||||
Serial.println("Creating access point failed");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
|
||||
// start the web server on port 80
|
||||
server.begin();
|
||||
|
||||
// you're connected now, so print out the status
|
||||
printWiFiStatus();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// compare the previous status to the current status
|
||||
if (status != WiFi.status()) {
|
||||
// it has changed update the variable
|
||||
status = WiFi.status();
|
||||
|
||||
if (status == WL_AP_CONNECTED) {
|
||||
// a device has connected to the AP
|
||||
Serial.println("Device connected to AP");
|
||||
} else {
|
||||
// a device has disconnected from the AP, and we are back in listening mode
|
||||
Serial.println("Device disconnected from AP");
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient client = server.available(); // listen for incoming clients
|
||||
|
||||
if (client) { // if you get a client,
|
||||
Serial.println("new client"); // print a message out the serial port
|
||||
String currentLine = ""; // make a String to hold incoming data from the client
|
||||
while (client.connected()) { // loop while the client's connected
|
||||
delayMicroseconds(10); // This is required for the Arduino Nano RP2040 Connect - otherwise it will loop so fast that SPI will never be served.
|
||||
if (client.available()) { // if there's bytes to read from the client,
|
||||
char c = client.read(); // read a byte, then
|
||||
Serial.write(c); // print it out the serial monitor
|
||||
if (c == '\n') { // if the byte is a newline character
|
||||
|
||||
// if the current line is blank, you got two newline characters in a row.
|
||||
// that's the end of the client HTTP request, so send a response:
|
||||
if (currentLine.length() == 0) {
|
||||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
||||
// and a content-type so the client knows what's coming, then a blank line:
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-type:text/html");
|
||||
client.println();
|
||||
|
||||
// the content of the HTTP response follows the header:
|
||||
client.print("Click <a href=\"/H\">here</a> turn the LED on<br>");
|
||||
client.print("Click <a href=\"/L\">here</a> turn the LED off<br>");
|
||||
|
||||
// The HTTP response ends with another blank line:
|
||||
client.println();
|
||||
// break out of the while loop:
|
||||
break;
|
||||
}
|
||||
else { // if you got a newline, then clear currentLine:
|
||||
currentLine = "";
|
||||
}
|
||||
}
|
||||
else if (c != '\r') { // if you got anything else but a carriage return character,
|
||||
currentLine += c; // add it to the end of the currentLine
|
||||
}
|
||||
|
||||
// Check to see if the client request was "GET /H" or "GET /L":
|
||||
if (currentLine.endsWith("GET /H")) {
|
||||
digitalWrite(led, HIGH); // GET /H turns the LED on
|
||||
}
|
||||
if (currentLine.endsWith("GET /L")) {
|
||||
digitalWrite(led, LOW); // GET /L turns the LED off
|
||||
}
|
||||
}
|
||||
}
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("client disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
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 where to go in a browser:
|
||||
Serial.print("To see this page in action, open a browser to http://");
|
||||
Serial.println(ip);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// Both SSID and password must be 8 characters or longer
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
This example connects to an unencrypted WiFi network.
|
||||
Then it prints the MAC address of the board,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
int status = WL_IDLE_STATUS; // the WiFi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network:
|
||||
while (status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to open SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// you're connected now, so print out the data:
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your board's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
printMacAddress(mac);
|
||||
|
||||
// print your subnet mask:
|
||||
IPAddress subnet = WiFi.subnetMask();
|
||||
Serial.print("NetMask: ");
|
||||
Serial.println(subnet);
|
||||
|
||||
// print your gateway address:
|
||||
IPAddress gateway = WiFi.gatewayIP();
|
||||
Serial.print("Gateway: ");
|
||||
Serial.println(gateway);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
printMacAddress(bssid);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption, HEX);
|
||||
}
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#define SECRET_SSID ""
|
||||
120
lib/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino
Normal file
120
lib/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino
Normal file
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
This example connects to a WEP-encrypted WiFi network.
|
||||
Then it prints the MAC address of the WiFi module,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
If you use 40-bit WEP, you need a key that is 10 characters long,
|
||||
and the characters must be hexadecimal (0-9 or A-F).
|
||||
e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work
|
||||
(too short) and ABBAISDEAF won't work (I and S are not
|
||||
hexadecimal characters).
|
||||
|
||||
For 128-bit, you need a string that is 26 characters long.
|
||||
D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters,
|
||||
all in the 0-9, A-F range.
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number
|
||||
int status = WL_IDLE_STATUS; // the WiFi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network:
|
||||
while (status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WEP network, SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, keyIndex, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// once you are connected :
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your board's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
printMacAddress(mac);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
printMacAddress(bssid);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
2
lib/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
111
lib/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino
Normal file
111
lib/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
This example connects to an unencrypted WiFi network.
|
||||
Then it prints the MAC address of the WiFi module,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int status = WL_IDLE_STATUS; // the WiFi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network:
|
||||
while (status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WPA SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// you're connected now, so print out the data:
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your board's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
printMacAddress(mac);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
printMacAddress(bssid);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
2
lib/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
This example connects to a WPA2 Enterprise WiFi network.
|
||||
Then it prints the MAC address of the WiFi module,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
Based on ConnectWithWPA.ino by dlf (Metodo2 srl) and Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your WPA2 enterprise network SSID (name)
|
||||
char user[] = SECRET_USER; // your WPA2 enterprise username
|
||||
char pass[] = SECRET_PASS; // your WPA2 enterprise password
|
||||
int status = WL_IDLE_STATUS; // the WiFi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network:
|
||||
while (status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WPA SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA2 enterprise network:
|
||||
// - You can optionally provide additional identity and CA cert (string) parameters if your network requires them:
|
||||
// WiFi.beginEnterprise(ssid, user, pass, identity, caCert)
|
||||
status = WiFi.beginEnterprise(ssid, user, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// you're connected now, so print out the data:
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your board's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
printMacAddress(mac);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
printMacAddress(bssid);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_USER ""
|
||||
#define SECRET_PASS ""
|
||||
116
lib/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino
Normal file
116
lib/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
This example prints the board's MAC address, and
|
||||
scans for available WiFi networks using the NINA module.
|
||||
Every ten seconds, it scans again. It doesn't actually
|
||||
connect to any network, so no encryption scheme is specified.
|
||||
|
||||
Circuit:
|
||||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 21 Junn 2012
|
||||
by Tom Igoe and Jaymes Dec
|
||||
*/
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC: ");
|
||||
printMacAddress(mac);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// scan for existing networks:
|
||||
Serial.println("Scanning available networks...");
|
||||
listNetworks();
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
void listNetworks() {
|
||||
// scan for nearby networks:
|
||||
Serial.println("** Scan Networks **");
|
||||
int numSsid = WiFi.scanNetworks();
|
||||
if (numSsid == -1) {
|
||||
Serial.println("Couldn't get a WiFi connection");
|
||||
while (true);
|
||||
}
|
||||
|
||||
// print the list of networks seen:
|
||||
Serial.print("number of available networks:");
|
||||
Serial.println(numSsid);
|
||||
|
||||
// print the network number and name for each network found:
|
||||
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
|
||||
Serial.print(thisNet);
|
||||
Serial.print(") ");
|
||||
Serial.print(WiFi.SSID(thisNet));
|
||||
Serial.print("\tSignal: ");
|
||||
Serial.print(WiFi.RSSI(thisNet));
|
||||
Serial.print(" dBm");
|
||||
Serial.print("\tEncryption: ");
|
||||
printEncryptionType(WiFi.encryptionType(thisNet));
|
||||
}
|
||||
}
|
||||
|
||||
void printEncryptionType(int thisType) {
|
||||
// read the encryption type and print out the name:
|
||||
switch (thisType) {
|
||||
case ENC_TYPE_WEP:
|
||||
Serial.println("WEP");
|
||||
break;
|
||||
case ENC_TYPE_TKIP:
|
||||
Serial.println("WPA");
|
||||
break;
|
||||
case ENC_TYPE_CCMP:
|
||||
Serial.println("WPA2");
|
||||
break;
|
||||
case ENC_TYPE_NONE:
|
||||
Serial.println("None");
|
||||
break;
|
||||
case ENC_TYPE_AUTO:
|
||||
Serial.println("Auto");
|
||||
break;
|
||||
case ENC_TYPE_UNKNOWN:
|
||||
default:
|
||||
Serial.println("Unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
This example prints the board's MAC address, and
|
||||
scans for available WiFi networks using the NINA module.
|
||||
Every ten seconds, it scans again. It doesn't actually
|
||||
connect to any network, so no encryption scheme is specified.
|
||||
BSSID and WiFi channel are printed
|
||||
|
||||
Circuit:
|
||||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
|
||||
This example is based on ScanNetworks
|
||||
|
||||
created 1 Mar 2017
|
||||
by Arturo Guadalupi
|
||||
*/
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC: ");
|
||||
printMacAddress(mac);
|
||||
|
||||
// scan for existing networks:
|
||||
Serial.println();
|
||||
Serial.println("Scanning available networks...");
|
||||
listNetworks();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(10000);
|
||||
// scan for existing networks:
|
||||
Serial.println("Scanning available networks...");
|
||||
listNetworks();
|
||||
}
|
||||
|
||||
void listNetworks() {
|
||||
// scan for nearby networks:
|
||||
Serial.println("** Scan Networks **");
|
||||
int numSsid = WiFi.scanNetworks();
|
||||
if (numSsid == -1)
|
||||
{
|
||||
Serial.println("Couldn't get a WiFi connection");
|
||||
while (true);
|
||||
}
|
||||
|
||||
// print the list of networks seen:
|
||||
Serial.print("number of available networks: ");
|
||||
Serial.println(numSsid);
|
||||
|
||||
// print the network number and name for each network found:
|
||||
for (int thisNet = 0; thisNet < numSsid; thisNet++) {
|
||||
Serial.print(thisNet + 1);
|
||||
Serial.print(") ");
|
||||
Serial.print("Signal: ");
|
||||
Serial.print(WiFi.RSSI(thisNet));
|
||||
Serial.print(" dBm");
|
||||
Serial.print("\tChannel: ");
|
||||
Serial.print(WiFi.channel(thisNet));
|
||||
byte bssid[6];
|
||||
Serial.print("\t\tBSSID: ");
|
||||
printMacAddress(WiFi.BSSID(thisNet, bssid));
|
||||
Serial.print("\tEncryption: ");
|
||||
printEncryptionType(WiFi.encryptionType(thisNet));
|
||||
Serial.print("\t\tSSID: ");
|
||||
Serial.println(WiFi.SSID(thisNet));
|
||||
Serial.flush();
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printEncryptionType(int thisType) {
|
||||
// read the encryption type and print out the name:
|
||||
switch (thisType) {
|
||||
case ENC_TYPE_WEP:
|
||||
Serial.print("WEP");
|
||||
break;
|
||||
case ENC_TYPE_TKIP:
|
||||
Serial.print("WPA");
|
||||
break;
|
||||
case ENC_TYPE_CCMP:
|
||||
Serial.print("WPA2");
|
||||
break;
|
||||
case ENC_TYPE_NONE:
|
||||
Serial.print("None");
|
||||
break;
|
||||
case ENC_TYPE_AUTO:
|
||||
Serial.print("Auto");
|
||||
break;
|
||||
case ENC_TYPE_UNKNOWN:
|
||||
default:
|
||||
Serial.print("Unknown");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void print2Digits(byte thisByte) {
|
||||
if (thisByte < 0xF) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(thisByte, HEX);
|
||||
}
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
WiFi Web Server LED Blink
|
||||
|
||||
A simple web server that lets you blink an LED via the web.
|
||||
This sketch will print the IP address of your WiFi module (once connected)
|
||||
to the Serial Monitor. From there, you can open that address in a web browser
|
||||
to turn on and off the LED on pin 9.
|
||||
|
||||
If the IP address of your board is yourAddress:
|
||||
http://yourAddress/H turns the LED on
|
||||
http://yourAddress/L turns it off
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the WiFi.begin() call accordingly.
|
||||
|
||||
Circuit:
|
||||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
* LED attached to pin 9
|
||||
|
||||
created 25 Nov 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // initialize serial communication
|
||||
pinMode(9, OUTPUT); // set the LED pin mode
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network:
|
||||
while (status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to Network named: ");
|
||||
Serial.println(ssid); // print the network name (SSID);
|
||||
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
server.begin(); // start the web server on port 80
|
||||
printWifiStatus(); // you're connected now, so print out the status
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
WiFiClient client = server.available(); // listen for incoming clients
|
||||
|
||||
if (client) { // if you get a client,
|
||||
Serial.println("new client"); // print a message out the serial port
|
||||
String currentLine = ""; // make a String to hold incoming data from the client
|
||||
while (client.connected()) { // loop while the client's connected
|
||||
if (client.available()) { // if there's bytes to read from the client,
|
||||
char c = client.read(); // read a byte, then
|
||||
Serial.write(c); // print it out the serial monitor
|
||||
if (c == '\n') { // if the byte is a newline character
|
||||
|
||||
// if the current line is blank, you got two newline characters in a row.
|
||||
// that's the end of the client HTTP request, so send a response:
|
||||
if (currentLine.length() == 0) {
|
||||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
||||
// and a content-type so the client knows what's coming, then a blank line:
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-type:text/html");
|
||||
client.println();
|
||||
|
||||
// the content of the HTTP response follows the header:
|
||||
client.print("Click <a href=\"/H\">here</a> turn the LED on pin 9 on<br>");
|
||||
client.print("Click <a href=\"/L\">here</a> turn the LED on pin 9 off<br>");
|
||||
|
||||
// The HTTP response ends with another blank line:
|
||||
client.println();
|
||||
// break out of the while loop:
|
||||
break;
|
||||
} else { // if you got a newline, then clear currentLine:
|
||||
currentLine = "";
|
||||
}
|
||||
} else if (c != '\r') { // if you got anything else but a carriage return character,
|
||||
currentLine += c; // add it to the end of the currentLine
|
||||
}
|
||||
|
||||
// Check to see if the client request was "GET /H" or "GET /L":
|
||||
if (currentLine.endsWith("GET /H")) {
|
||||
digitalWrite(9, HIGH); // GET /H turns the LED on
|
||||
}
|
||||
if (currentLine.endsWith("GET /L")) {
|
||||
digitalWrite(9, LOW); // GET /L turns the LED off
|
||||
}
|
||||
}
|
||||
}
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("client disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
// print where to go in a browser:
|
||||
Serial.print("To see this page in action, open a browser to http://");
|
||||
Serial.println(ip);
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This example checks if the firmware loaded on the NINA module
|
||||
* is updated.
|
||||
*
|
||||
* Circuit:
|
||||
* - Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
*
|
||||
* Created 17 October 2018 by Riccardo Rosario Rizzo
|
||||
* This code is in the public domain.
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
void setup() {
|
||||
// Initialize serial
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// Print a welcome message
|
||||
Serial.println("WiFiNINA firmware check.");
|
||||
Serial.println();
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
// Print firmware version on the module
|
||||
String fv = WiFi.firmwareVersion();
|
||||
String latestFv;
|
||||
Serial.print("Firmware version installed: ");
|
||||
Serial.println(fv);
|
||||
|
||||
latestFv = WIFI_FIRMWARE_LATEST_VERSION;
|
||||
|
||||
// Print required firmware version
|
||||
Serial.print("Latest firmware version available : ");
|
||||
Serial.println(latestFv);
|
||||
|
||||
// Check if the latest version is installed
|
||||
Serial.println();
|
||||
if (fv >= latestFv) {
|
||||
Serial.println("Check result: PASSED");
|
||||
} else {
|
||||
Serial.println("Check result: NOT PASSED");
|
||||
Serial.println(" - The firmware version on the module does not match the");
|
||||
Serial.println(" version required by the library, you may experience");
|
||||
Serial.println(" issues or failures.");
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// do nothing
|
||||
}
|
||||
335
lib/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp
Normal file
335
lib/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp
Normal file
@@ -0,0 +1,335 @@
|
||||
/*
|
||||
ESP32BootROM - part of the Firmware Updater for the
|
||||
Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2.
|
||||
|
||||
Copyright (c) 2018 Arduino SA. All rights 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
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
#include <VidorPeripherals.h>
|
||||
|
||||
#define NINA_GPIO0 FPGA_NINA_GPIO0
|
||||
#define NINA_RESETN FPGA_SPIWIFI_RESET
|
||||
#endif
|
||||
|
||||
|
||||
#include "ESP32BootROM.h"
|
||||
|
||||
ESP32BootROMClass::ESP32BootROMClass(HardwareSerial& serial, int gpio0Pin, int resetnPin) :
|
||||
_serial(&serial),
|
||||
_gpio0Pin(gpio0Pin),
|
||||
_resetnPin(resetnPin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::begin(unsigned long baudrate)
|
||||
{
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
FPGA.begin();
|
||||
|
||||
_serial->begin(119400);
|
||||
|
||||
FPGA.pinMode(_gpio0Pin, OUTPUT);
|
||||
FPGA.pinMode(_resetnPin, OUTPUT);
|
||||
|
||||
FPGA.digitalWrite(_gpio0Pin, LOW);
|
||||
|
||||
FPGA.digitalWrite(_resetnPin, LOW);
|
||||
delay(10);
|
||||
FPGA.digitalWrite(_resetnPin, HIGH);
|
||||
delay(100);
|
||||
|
||||
#elif defined(ARDUINO_AVR_UNO_WIFI_REV2)
|
||||
_serial->begin(119400);
|
||||
|
||||
pinMode(_gpio0Pin, OUTPUT);
|
||||
pinMode(_resetnPin, OUTPUT);
|
||||
|
||||
digitalWrite(_gpio0Pin, LOW);
|
||||
|
||||
digitalWrite(_resetnPin, LOW);
|
||||
delay(100);
|
||||
digitalWrite(_resetnPin, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(_resetnPin, LOW);
|
||||
#else
|
||||
_serial->begin(115200);
|
||||
|
||||
pinMode(_gpio0Pin, OUTPUT);
|
||||
pinMode(_resetnPin, OUTPUT);
|
||||
|
||||
digitalWrite(_gpio0Pin, LOW);
|
||||
|
||||
digitalWrite(_resetnPin, HIGH);
|
||||
delay(10);
|
||||
digitalWrite(_resetnPin, LOW);
|
||||
delay(100);
|
||||
#if defined(ARDUINO_SAMD_NANO_33_IOT) ||defined(ARDUINO_NANO_RP2040_CONNECT)
|
||||
digitalWrite(_resetnPin, HIGH);
|
||||
delay(100);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int synced = 0;
|
||||
|
||||
for (int retries = 0; !synced && (retries < 5); retries++) {
|
||||
synced = sync();
|
||||
}
|
||||
|
||||
if (!synced) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT)
|
||||
(void)baudrate;
|
||||
#else
|
||||
if (baudrate != 115200) {
|
||||
if (!changeBaudrate(baudrate)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
delay(100);
|
||||
|
||||
_serial->end();
|
||||
_serial->begin(baudrate);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!spiAttach()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ESP32BootROMClass::end() {
|
||||
_serial->end();
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::sync()
|
||||
{
|
||||
const uint8_t data[] = {
|
||||
0x07, 0x07, 0x12, 0x20,
|
||||
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55
|
||||
};
|
||||
|
||||
command(0x08, data, sizeof(data));
|
||||
|
||||
int results[8];
|
||||
|
||||
for (int i = 0; i < 8; i++) {
|
||||
results[i] = response(0x08, 100);
|
||||
}
|
||||
|
||||
return (results[0] == 0);
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::changeBaudrate(unsigned long baudrate)
|
||||
{
|
||||
const uint32_t data[2] = {
|
||||
baudrate,
|
||||
0
|
||||
};
|
||||
|
||||
command(0x0f, data, sizeof(data));
|
||||
|
||||
return (response(0x0f, 3000) == 0);
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::spiAttach()
|
||||
{
|
||||
const uint8_t data[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
command(0x0d, data, sizeof(data));
|
||||
|
||||
return (response(0x0d, 3000) == 0);
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::beginFlash(uint32_t offset, uint32_t size, uint32_t chunkSize) {
|
||||
const uint32_t data[4] = {
|
||||
size,
|
||||
size / chunkSize,
|
||||
chunkSize,
|
||||
offset
|
||||
};
|
||||
|
||||
command(0x02, data, sizeof(data));
|
||||
|
||||
_flashSequenceNumber = 0;
|
||||
_chunkSize = chunkSize;
|
||||
|
||||
return (response(0x02, 120000) == 0);
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::dataFlash(const void* data, uint32_t length)
|
||||
{
|
||||
uint32_t cmdData[4 + (_chunkSize / 4)];
|
||||
|
||||
cmdData[0] = length;
|
||||
cmdData[1] = _flashSequenceNumber++;
|
||||
cmdData[2] = 0;
|
||||
cmdData[3] = 0;
|
||||
|
||||
memcpy(&cmdData[4], data, length);
|
||||
|
||||
if (length < _chunkSize) {
|
||||
memset(&cmdData[4 + (length / 4)], 0xff, _chunkSize - length);
|
||||
}
|
||||
|
||||
command(0x03, cmdData, sizeof(cmdData));
|
||||
|
||||
return (response(0x03, 3000) == 0);
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::endFlash(uint32_t reboot) {
|
||||
const uint32_t data[1] = {
|
||||
reboot
|
||||
};
|
||||
|
||||
command(0x04, data, sizeof(data));
|
||||
|
||||
return (response(0x04, 3000) == 0);
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::md5Flash(uint32_t offset, uint32_t size, uint8_t* result)
|
||||
{
|
||||
const uint32_t data[4] = {
|
||||
offset,
|
||||
size,
|
||||
0,
|
||||
0
|
||||
};
|
||||
|
||||
command(0x13, data, sizeof(data));
|
||||
|
||||
uint8_t asciiResult[32];
|
||||
|
||||
if (response(0x13, 3000, asciiResult) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
char temp[3] = { 0, 0, 0 };
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
temp[0] = asciiResult[i * 2];
|
||||
temp[1] = asciiResult[i * 2 + 1];
|
||||
|
||||
result[i] = strtoul(temp, NULL, 16);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void ESP32BootROMClass::command(int opcode, const void* data, uint16_t length)
|
||||
{
|
||||
uint32_t checksum = 0;
|
||||
|
||||
if (opcode == 0x03) {
|
||||
checksum = 0xef; // seed
|
||||
|
||||
for (uint16_t i = 16; i < length; i++) {
|
||||
checksum ^= ((const uint8_t*)data)[i];
|
||||
}
|
||||
}
|
||||
|
||||
_serial->write(0xc0);
|
||||
_serial->write((uint8_t)0x00); // direction
|
||||
_serial->write(opcode);
|
||||
_serial->write((uint8_t*)&length, sizeof(length));
|
||||
writeEscapedBytes((uint8_t*)&checksum, sizeof(checksum));
|
||||
writeEscapedBytes((uint8_t*)data, length);
|
||||
_serial->write(0xc0);
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
// _serial->flush(); // doesn't work!
|
||||
#else
|
||||
_serial->flush();
|
||||
#endif
|
||||
}
|
||||
|
||||
int ESP32BootROMClass::response(int opcode, unsigned long timeout, void* body)
|
||||
{
|
||||
uint8_t data[10 + 256];
|
||||
uint16_t index = 0;
|
||||
|
||||
uint8_t responseLength = 4;
|
||||
|
||||
for (unsigned long start = millis(); (index < (uint16_t)(10 + responseLength)) && (millis() - start) < timeout;) {
|
||||
if (_serial->available()) {
|
||||
data[index] = _serial->read();
|
||||
|
||||
if (index == 3) {
|
||||
responseLength = data[index];
|
||||
}
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (index) {
|
||||
for (int i = 0; i < index; i++) {
|
||||
byte b = data[i];
|
||||
|
||||
if (b < 0x10) {
|
||||
Serial.print('0');
|
||||
}
|
||||
|
||||
Serial.print(b, HEX);
|
||||
Serial.print(' ');
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (index != (uint16_t)(10 + responseLength)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (data[0] != 0xc0 || data[1] != 0x01 || data[2] != opcode || data[responseLength + 5] != 0x00 || data[responseLength + 6] != 0x00 || data[responseLength + 9] != 0xc0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (body) {
|
||||
memcpy(body, &data[9], responseLength - 4);
|
||||
}
|
||||
|
||||
return data[responseLength + 5];
|
||||
}
|
||||
|
||||
void ESP32BootROMClass::writeEscapedBytes(const uint8_t* data, uint16_t length)
|
||||
{
|
||||
uint16_t written = 0;
|
||||
|
||||
while (written < length) {
|
||||
uint8_t b = data[written++];
|
||||
|
||||
if (b == 0xdb) {
|
||||
_serial->write(0xdb);
|
||||
_serial->write(0xdd);
|
||||
} else if (b == 0xc0) {
|
||||
_serial->write(0xdb);
|
||||
_serial->write(0xdc);
|
||||
} else {
|
||||
_serial->write(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ESP32BootROMClass ESP32BootROM(SerialNina, NINA_GPIO0, NINA_RESETN);
|
||||
56
lib/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h
Normal file
56
lib/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
ESP32BootROM - part of the Firmware Updater for the
|
||||
Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2.
|
||||
|
||||
Copyright (c) 2018 Arduino SA. All rights 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>
|
||||
|
||||
class ESP32BootROMClass {
|
||||
public:
|
||||
ESP32BootROMClass(HardwareSerial& hwSerial, int gpio0Pin, int resetnPin);
|
||||
|
||||
int begin(unsigned long baudrate);
|
||||
void end();
|
||||
|
||||
int beginFlash(uint32_t offset, uint32_t size, uint32_t chunkSize);
|
||||
int dataFlash(const void* data, uint32_t length);
|
||||
int endFlash(uint32_t reboot);
|
||||
|
||||
int md5Flash(uint32_t offset, uint32_t size, uint8_t* result);
|
||||
|
||||
private:
|
||||
int sync();
|
||||
int changeBaudrate(unsigned long baudrate);
|
||||
int spiAttach();
|
||||
|
||||
void command(int opcode, const void* data, uint16_t length);
|
||||
int response(int opcode, unsigned long timeout, void* body = NULL);
|
||||
|
||||
void writeEscapedBytes(const uint8_t* data, uint16_t length);
|
||||
|
||||
private:
|
||||
HardwareSerial* _serial;
|
||||
int _gpio0Pin;
|
||||
int _resetnPin;
|
||||
|
||||
uint32_t _flashSequenceNumber;
|
||||
uint32_t _chunkSize;
|
||||
};
|
||||
|
||||
extern ESP32BootROMClass ESP32BootROM;
|
||||
60
lib/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino
Normal file
60
lib/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
Endianess.ino - Network byte order conversion functions.
|
||||
Copyright (c) 2015 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
|
||||
*/
|
||||
|
||||
bool isBigEndian() {
|
||||
uint32_t test = 0x11223344;
|
||||
uint8_t *pTest = reinterpret_cast<uint8_t *>(&test);
|
||||
return pTest[0] == 0x11;
|
||||
}
|
||||
|
||||
uint32_t fromNetwork32(uint32_t from) {
|
||||
static const bool be = isBigEndian();
|
||||
if (be) {
|
||||
return from;
|
||||
} else {
|
||||
uint8_t *pFrom = reinterpret_cast<uint8_t *>(&from);
|
||||
uint32_t to;
|
||||
to = pFrom[0]; to <<= 8;
|
||||
to |= pFrom[1]; to <<= 8;
|
||||
to |= pFrom[2]; to <<= 8;
|
||||
to |= pFrom[3];
|
||||
return to;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t fromNetwork16(uint16_t from) {
|
||||
static bool be = isBigEndian();
|
||||
if (be) {
|
||||
return from;
|
||||
} else {
|
||||
uint8_t *pFrom = reinterpret_cast<uint8_t *>(&from);
|
||||
uint16_t to;
|
||||
to = pFrom[0]; to <<= 8;
|
||||
to |= pFrom[1];
|
||||
return to;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t toNetwork32(uint32_t to) {
|
||||
return fromNetwork32(to);
|
||||
}
|
||||
|
||||
uint16_t toNetwork16(uint16_t to) {
|
||||
return fromNetwork16(to);
|
||||
}
|
||||
142
lib/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino
Normal file
142
lib/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino
Normal file
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
FirmwareUpdater - Firmware Updater for the
|
||||
Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2.
|
||||
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 "ESP32BootROM.h"
|
||||
|
||||
typedef struct __attribute__((__packed__)) {
|
||||
uint8_t command;
|
||||
uint32_t address;
|
||||
uint32_t arg1;
|
||||
uint16_t payloadLength;
|
||||
|
||||
// payloadLength bytes of data follows...
|
||||
} UartPacket;
|
||||
|
||||
static const int MAX_PAYLOAD_SIZE = 1024;
|
||||
|
||||
#define CMD_READ_FLASH 0x01
|
||||
#define CMD_WRITE_FLASH 0x02
|
||||
#define CMD_ERASE_FLASH 0x03
|
||||
#define CMD_MD5_FLASH 0x04
|
||||
#define CMD_MAX_PAYLOAD_SIZE 0x50
|
||||
#define CMD_HELLO 0x99
|
||||
|
||||
void setup() {
|
||||
Serial.begin(1000000);
|
||||
|
||||
if (!ESP32BootROM.begin(921600)) {
|
||||
Serial.println("Unable to communicate with ESP32 boot ROM!");
|
||||
while (1);
|
||||
}
|
||||
}
|
||||
|
||||
void receivePacket(UartPacket *pkt, uint8_t *payload) {
|
||||
// Read command
|
||||
uint8_t *p = reinterpret_cast<uint8_t *>(pkt);
|
||||
uint16_t l = sizeof(UartPacket);
|
||||
while (l > 0) {
|
||||
int c = Serial.read();
|
||||
if (c == -1)
|
||||
continue;
|
||||
*p++ = c;
|
||||
l--;
|
||||
}
|
||||
|
||||
// Convert parameters from network byte order to cpu byte order
|
||||
pkt->address = fromNetwork32(pkt->address);
|
||||
pkt->arg1 = fromNetwork32(pkt->arg1);
|
||||
pkt->payloadLength = fromNetwork16(pkt->payloadLength);
|
||||
|
||||
// Read payload
|
||||
l = pkt->payloadLength;
|
||||
while (l > 0) {
|
||||
int c = Serial.read();
|
||||
if (c == -1)
|
||||
continue;
|
||||
*payload++ = c;
|
||||
l--;
|
||||
}
|
||||
}
|
||||
|
||||
// Allocated statically so the compiler can tell us
|
||||
// about the amount of used RAM
|
||||
static UartPacket pkt;
|
||||
static uint8_t payload[MAX_PAYLOAD_SIZE];
|
||||
|
||||
void loop() {
|
||||
receivePacket(&pkt, payload);
|
||||
|
||||
if (pkt.command == CMD_HELLO) {
|
||||
if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788)
|
||||
Serial.print("v10000");
|
||||
}
|
||||
|
||||
if (pkt.command == CMD_MAX_PAYLOAD_SIZE) {
|
||||
uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE);
|
||||
Serial.write(reinterpret_cast<uint8_t *>(&res), sizeof(res));
|
||||
}
|
||||
|
||||
if (pkt.command == CMD_READ_FLASH) {
|
||||
// not supported!
|
||||
Serial.println("ER");
|
||||
}
|
||||
|
||||
if (pkt.command == CMD_WRITE_FLASH) {
|
||||
uint32_t len = pkt.payloadLength;
|
||||
if (!ESP32BootROM.dataFlash(payload, len)) {
|
||||
Serial.print("ER");
|
||||
} else {
|
||||
Serial.print("OK");
|
||||
}
|
||||
}
|
||||
|
||||
if (pkt.command == CMD_ERASE_FLASH) {
|
||||
uint32_t address = pkt.address;
|
||||
uint32_t len = pkt.arg1;
|
||||
if (!ESP32BootROM.beginFlash(address, len, MAX_PAYLOAD_SIZE)) {
|
||||
Serial.print("ER");
|
||||
} else {
|
||||
Serial.print("OK");
|
||||
}
|
||||
}
|
||||
|
||||
if (pkt.command == CMD_MD5_FLASH) {
|
||||
uint32_t address = pkt.address;
|
||||
uint32_t len = pkt.arg1;
|
||||
|
||||
if (!ESP32BootROM.endFlash(1)) {
|
||||
Serial.print("ER");
|
||||
} else {
|
||||
ESP32BootROM.end();
|
||||
|
||||
uint8_t md5[16];
|
||||
|
||||
if (!ESP32BootROM.begin(921600)) {
|
||||
Serial.print("ER");
|
||||
} else if (!ESP32BootROM.md5Flash(address, len, md5)) {
|
||||
Serial.print("ER");
|
||||
} else {
|
||||
Serial.print("OK");
|
||||
Serial.write(md5, sizeof(md5));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
SerialNINAPassthrough - Use esptool to flash the u-blox NINA (ESP32) module
|
||||
Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2.
|
||||
|
||||
Copyright (c) 2018 Arduino SA. All rights 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
|
||||
*/
|
||||
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
#include <VidorPeripherals.h>
|
||||
|
||||
unsigned long baud = 119400;
|
||||
#else
|
||||
unsigned long baud = 115200;
|
||||
#endif
|
||||
|
||||
int rts = -1;
|
||||
int dtr = -1;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(baud);
|
||||
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
FPGA.begin();
|
||||
#endif
|
||||
|
||||
SerialNina.begin(baud);
|
||||
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
FPGA.pinMode(FPGA_NINA_GPIO0, OUTPUT);
|
||||
FPGA.pinMode(FPGA_SPIWIFI_RESET, OUTPUT);
|
||||
#else
|
||||
pinMode(NINA_GPIO0, OUTPUT);
|
||||
pinMode(NINA_RESETN, OUTPUT);
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_AVR_UNO_WIFI_REV2
|
||||
// manually put the NINA in upload mode
|
||||
digitalWrite(NINA_GPIO0, LOW);
|
||||
|
||||
digitalWrite(NINA_RESETN, LOW);
|
||||
delay(100);
|
||||
digitalWrite(NINA_RESETN, HIGH);
|
||||
delay(100);
|
||||
digitalWrite(NINA_RESETN, LOW);
|
||||
#endif
|
||||
}
|
||||
|
||||
void loop() {
|
||||
#ifndef ARDUINO_AVR_UNO_WIFI_REV2
|
||||
if (rts != Serial.rts()) {
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
FPGA.digitalWrite(FPGA_SPIWIFI_RESET, (Serial.rts() == 1) ? LOW : HIGH);
|
||||
#elif defined(ARDUINO_SAMD_NANO_33_IOT)
|
||||
digitalWrite(NINA_RESETN, Serial.rts() ? LOW : HIGH);
|
||||
#else
|
||||
digitalWrite(NINA_RESETN, Serial.rts());
|
||||
#endif
|
||||
rts = Serial.rts();
|
||||
}
|
||||
|
||||
if (dtr != Serial.dtr()) {
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
FPGA.digitalWrite(FPGA_NINA_GPIO0, (Serial.dtr() == 1) ? HIGH : LOW);
|
||||
#else
|
||||
digitalWrite(NINA_GPIO0, (Serial.dtr() == 0) ? HIGH : LOW);
|
||||
#endif
|
||||
dtr = Serial.dtr();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (Serial.available()) {
|
||||
SerialNina.write(Serial.read());
|
||||
}
|
||||
|
||||
if (SerialNina.available()) {
|
||||
Serial.write(SerialNina.read());
|
||||
}
|
||||
|
||||
#ifndef ARDUINO_AVR_UNO_WIFI_REV2
|
||||
// check if the USB virtual serial wants a new baud rate
|
||||
if (Serial.baud() != baud) {
|
||||
rts = -1;
|
||||
dtr = -1;
|
||||
|
||||
baud = Serial.baud();
|
||||
#ifndef ARDUINO_SAMD_MKRVIDOR4000
|
||||
SerialNina.begin(baud);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
117
lib/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino
Normal file
117
lib/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino
Normal file
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
Chat Server
|
||||
|
||||
A simple server that distributes any incoming messages to all
|
||||
connected clients. To use, telnet to your device's IP address and type.
|
||||
You can see the client's input in the serial monitor as well.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the WiFi.begin() call accordingly.
|
||||
|
||||
|
||||
Circuit:
|
||||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
WiFiServer server(23);
|
||||
|
||||
boolean alreadyConnected = false; // whether or not the client was connected previously
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// start the server:
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// wait for a new client:
|
||||
WiFiClient client = server.available();
|
||||
|
||||
|
||||
// when the client sends the first byte, say hello:
|
||||
if (client) {
|
||||
if (!alreadyConnected) {
|
||||
// clear out the input buffer:
|
||||
client.flush();
|
||||
Serial.println("We have a new client");
|
||||
client.println("Hello, client!");
|
||||
alreadyConnected = true;
|
||||
}
|
||||
|
||||
if (client.available() > 0) {
|
||||
// read the bytes incoming from the client:
|
||||
char thisChar = client.read();
|
||||
// echo the bytes back to the client:
|
||||
server.write(thisChar);
|
||||
// echo the bytes to the server as well:
|
||||
Serial.write(thisChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
2
lib/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
135
lib/WiFiNINA/examples/WiFiPing/WiFiPing.ino
Normal file
135
lib/WiFiNINA/examples/WiFiPing/WiFiPing.ino
Normal file
@@ -0,0 +1,135 @@
|
||||
/*
|
||||
This example connects to an encrypted WiFi network (WPA/WPA2).
|
||||
Then it prints the MAC address of the board,
|
||||
the IP address obtained, and other network details.
|
||||
Then it continuously pings given host specified by IP Address or name.
|
||||
|
||||
Circuit:
|
||||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 09 June 2016
|
||||
by Petar Georgiev
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int status = WL_IDLE_STATUS; // the WiFi radio's status
|
||||
|
||||
// Specify IP address or hostname
|
||||
String hostName = "www.google.com";
|
||||
int pingResult;
|
||||
|
||||
void setup() {
|
||||
// Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// attempt to connect to WiFi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WPA SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 5 seconds for connection:
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
// you're connected now, so print out the data:
|
||||
Serial.println("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWiFiData();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Pinging ");
|
||||
Serial.print(hostName);
|
||||
Serial.print(": ");
|
||||
|
||||
pingResult = WiFi.ping(hostName);
|
||||
|
||||
if (pingResult >= 0) {
|
||||
Serial.print("SUCCESS! RTT = ");
|
||||
Serial.print(pingResult);
|
||||
Serial.println(" ms");
|
||||
} else {
|
||||
Serial.print("FAILED! Error code: ");
|
||||
Serial.println(pingResult);
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
}
|
||||
|
||||
void printWiFiData() {
|
||||
// print your board's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP address : ");
|
||||
Serial.println(ip);
|
||||
|
||||
Serial.print("Subnet mask: ");
|
||||
Serial.println((IPAddress)WiFi.subnetMask());
|
||||
|
||||
Serial.print("Gateway IP : ");
|
||||
Serial.println((IPAddress)WiFi.gatewayIP());
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
printMacAddress(mac);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
printMacAddress(bssid);
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI): ");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type: ");
|
||||
Serial.println(encryption, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void printMacAddress(byte mac[]) {
|
||||
for (int i = 5; i >= 0; i--) {
|
||||
if (mac[i] < 16) {
|
||||
Serial.print("0");
|
||||
}
|
||||
Serial.print(mac[i], HEX);
|
||||
if (i > 0) {
|
||||
Serial.print(":");
|
||||
}
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
2
lib/WiFiNINA/examples/WiFiPing/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/WiFiPing/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
112
lib/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino
Normal file
112
lib/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
This example creates a client object that connects and transfers
|
||||
data using always SSL.
|
||||
|
||||
It is compatible with the methods normally related to plain
|
||||
connections, like client.connect(host, port).
|
||||
|
||||
Written by Arturo Guadalupi
|
||||
last revision November 2015
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
|
||||
char server[] = "www.google.com"; // name address for Google (using DNS)
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
WiFiSSLClient client;
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
Serial.println("Connected to WiFi");
|
||||
printWiFiStatus();
|
||||
|
||||
Serial.println("\nStarting connection to server...");
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 443)) {
|
||||
Serial.println("connected to server");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /search?q=arduino HTTP/1.1");
|
||||
client.println("Host: www.google.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected()) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting from server.");
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWiFiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
2
lib/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
42
lib/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino
Normal file
42
lib/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
This example shows how to interact with NINA internal memory partition
|
||||
APIs are modeled on SerialFlash library (not on SD) to speedup operations and avoid buffers.
|
||||
*/
|
||||
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
void setup() {
|
||||
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while (true);
|
||||
}
|
||||
|
||||
WiFiStorageFile file = WiFiStorage.open("/fs/testfile");
|
||||
|
||||
if (file) {
|
||||
file.erase();
|
||||
}
|
||||
|
||||
String test = "Cantami o Diva del pelide Achille";
|
||||
file.write(test.c_str(), test.length());
|
||||
|
||||
if (file) {
|
||||
file.seek(0);
|
||||
while (file.available()) {
|
||||
uint8_t buf[128];
|
||||
int ret = file.read(buf, 128);
|
||||
Serial.write(buf, ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
|
||||
}
|
||||
173
lib/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino
Normal file
173
lib/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino
Normal file
@@ -0,0 +1,173 @@
|
||||
/*
|
||||
Udp NTP Client
|
||||
|
||||
Get the time from a Network Time Protocol (NTP) time server
|
||||
Demonstrates use of UDP sendPacket and ReceivePacket
|
||||
For more on NTP time servers and the messages needed to communicate with them,
|
||||
see http://en.wikipedia.org/wiki/Network_Time_Protocol
|
||||
|
||||
created 4 Sep 2010
|
||||
by Michael Margolis
|
||||
modified 9 Apr 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
unsigned int localPort = 2390; // local port to listen for UDP packets
|
||||
|
||||
IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server
|
||||
|
||||
const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message
|
||||
|
||||
byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets
|
||||
|
||||
// A UDP instance to let us send and receive packets over UDP
|
||||
WiFiUDP Udp;
|
||||
|
||||
void setup() {
|
||||
// Open serial communications and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
Serial.println("Connected to WiFi");
|
||||
printWifiStatus();
|
||||
|
||||
Serial.println("\nStarting connection to server...");
|
||||
Udp.begin(localPort);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sendNTPpacket(timeServer); // send an NTP packet to a time server
|
||||
// wait to see if a reply is available
|
||||
delay(1000);
|
||||
if (Udp.parsePacket()) {
|
||||
Serial.println("packet received");
|
||||
// We've received a packet, read the data from it
|
||||
Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
|
||||
|
||||
//the timestamp starts at byte 40 of the received packet and is four bytes,
|
||||
// or two words, long. First, extract the two words:
|
||||
|
||||
unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
|
||||
unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
|
||||
// combine the four bytes (two words) into a long integer
|
||||
// this is NTP time (seconds since Jan 1 1900):
|
||||
unsigned long secsSince1900 = highWord << 16 | lowWord;
|
||||
Serial.print("Seconds since Jan 1 1900 = ");
|
||||
Serial.println(secsSince1900);
|
||||
|
||||
// now convert NTP time into everyday time:
|
||||
Serial.print("Unix time = ");
|
||||
// Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
|
||||
const unsigned long seventyYears = 2208988800UL;
|
||||
// subtract seventy years:
|
||||
unsigned long epoch = secsSince1900 - seventyYears;
|
||||
// print Unix time:
|
||||
Serial.println(epoch);
|
||||
|
||||
|
||||
// print the hour, minute and second:
|
||||
Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
|
||||
Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
|
||||
Serial.print(':');
|
||||
if (((epoch % 3600) / 60) < 10) {
|
||||
// In the first 10 minutes of each hour, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
|
||||
Serial.print(':');
|
||||
if ((epoch % 60) < 10) {
|
||||
// In the first 10 seconds of each minute, we'll want a leading '0'
|
||||
Serial.print('0');
|
||||
}
|
||||
Serial.println(epoch % 60); // print the second
|
||||
}
|
||||
// wait ten seconds before asking for the time again
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// send an NTP request to the time server at the given address
|
||||
unsigned long sendNTPpacket(IPAddress& address) {
|
||||
//Serial.println("1");
|
||||
// set all bytes in the buffer to 0
|
||||
memset(packetBuffer, 0, NTP_PACKET_SIZE);
|
||||
// Initialize values needed to form NTP request
|
||||
// (see URL above for details on the packets)
|
||||
//Serial.println("2");
|
||||
packetBuffer[0] = 0b11100011; // LI, Version, Mode
|
||||
packetBuffer[1] = 0; // Stratum, or type of clock
|
||||
packetBuffer[2] = 6; // Polling Interval
|
||||
packetBuffer[3] = 0xEC; // Peer Clock Precision
|
||||
// 8 bytes of zero for Root Delay & Root Dispersion
|
||||
packetBuffer[12] = 49;
|
||||
packetBuffer[13] = 0x4E;
|
||||
packetBuffer[14] = 49;
|
||||
packetBuffer[15] = 52;
|
||||
|
||||
//Serial.println("3");
|
||||
|
||||
// all NTP fields have been given values, now
|
||||
// you can send a packet requesting a timestamp:
|
||||
Udp.beginPacket(address, 123); //NTP requests are to port 123
|
||||
//Serial.println("4");
|
||||
Udp.write(packetBuffer, NTP_PACKET_SIZE);
|
||||
//Serial.println("5");
|
||||
Udp.endPacket();
|
||||
//Serial.println("6");
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
2
lib/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
WiFi UDP Send and Receive String
|
||||
|
||||
This sketch waits for a UDP packet on localPort using the WiFi module.
|
||||
When a packet is received an Acknowledge packet is sent to the client on port remotePort
|
||||
|
||||
created 30 December 2012
|
||||
by dlf (Metodo2 srl)
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
#include <WiFiUdp.h>
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
unsigned int localPort = 2390; // local port to listen on
|
||||
|
||||
char packetBuffer[256]; //buffer to hold incoming packet
|
||||
char ReplyBuffer[] = "acknowledged"; // a string to send back
|
||||
|
||||
WiFiUDP Udp;
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
Serial.println("Connected to WiFi");
|
||||
printWifiStatus();
|
||||
|
||||
Serial.println("\nStarting connection to server...");
|
||||
// if you get a connection, report back via serial:
|
||||
Udp.begin(localPort);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// if there's data available, read a packet
|
||||
int packetSize = Udp.parsePacket();
|
||||
if (packetSize) {
|
||||
Serial.print("Received packet of size ");
|
||||
Serial.println(packetSize);
|
||||
Serial.print("From ");
|
||||
IPAddress remoteIp = Udp.remoteIP();
|
||||
Serial.print(remoteIp);
|
||||
Serial.print(", port ");
|
||||
Serial.println(Udp.remotePort());
|
||||
|
||||
// read the packet into packetBufffer
|
||||
int len = Udp.read(packetBuffer, 255);
|
||||
if (len > 0) {
|
||||
packetBuffer[len] = 0;
|
||||
}
|
||||
Serial.println("Contents:");
|
||||
Serial.println(packetBuffer);
|
||||
|
||||
// send a reply, to the IP address and port that sent us the packet we received
|
||||
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
|
||||
Udp.write(ReplyBuffer);
|
||||
Udp.endPacket();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
122
lib/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino
Normal file
122
lib/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
Web client
|
||||
|
||||
This sketch connects to a website (http://www.google.com)
|
||||
using the WiFi module.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the WiFi.begin() call accordingly.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the WiFi.begin() call accordingly.
|
||||
|
||||
Circuit:
|
||||
* Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2)
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
|
||||
char server[] = "www.google.com"; // name address for Google (using DNS)
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
WiFiClient client;
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
Serial.println("Connected to WiFi");
|
||||
printWifiStatus();
|
||||
|
||||
Serial.println("\nStarting connection to server...");
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connected to server");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /search?q=arduino HTTP/1.1");
|
||||
client.println("Host: www.google.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected()) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting from server.");
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while (true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
2
lib/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
Repeating WiFi Web Client
|
||||
|
||||
This sketch connects to a a web server and makes a request
|
||||
using a WiFi equipped Arduino board.
|
||||
|
||||
created 23 April 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
modified 13 Jan 2014
|
||||
by Federico Vanzati
|
||||
|
||||
http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating
|
||||
This code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
// Initialize the WiFi client library
|
||||
WiFiClient client;
|
||||
|
||||
// server address:
|
||||
char server[] = "example.org";
|
||||
//IPAddress server(64,131,82,241);
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if ten seconds have passed since your last connection,
|
||||
// then connect again and send data:
|
||||
if (millis() - lastConnectionTime > postingInterval) {
|
||||
httpRequest();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// this method makes a HTTP connection to the server:
|
||||
void httpRequest() {
|
||||
// close any connection before send a new request.
|
||||
// This will free the socket on the NINA module
|
||||
client.stop();
|
||||
|
||||
// if there's a successful connection:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connecting...");
|
||||
// send the HTTP GET request:
|
||||
client.println("GET / HTTP/1.1");
|
||||
client.println("Host: example.org");
|
||||
client.println("User-Agent: ArduinoWiFi/1.1");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
// note the time that the connection was made:
|
||||
lastConnectionTime = millis();
|
||||
} else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
137
lib/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino
Normal file
137
lib/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
WiFi Web Server
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the WiFi.begin() call accordingly.
|
||||
|
||||
Circuit:
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFiNINA.h>
|
||||
|
||||
|
||||
#include "arduino_secrets.h"
|
||||
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
|
||||
char ssid[] = SECRET_SSID; // your network SSID (name)
|
||||
char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for native USB port only
|
||||
}
|
||||
|
||||
// check for the WiFi module:
|
||||
if (WiFi.status() == WL_NO_MODULE) {
|
||||
Serial.println("Communication with WiFi module failed!");
|
||||
// don't continue
|
||||
while (true);
|
||||
}
|
||||
|
||||
String fv = WiFi.firmwareVersion();
|
||||
if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
|
||||
Serial.println("Please upgrade the firmware");
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// listen for incoming clients
|
||||
WiFiClient client = server.available();
|
||||
if (client) {
|
||||
Serial.println("new client");
|
||||
// an HTTP request ends with a blank line
|
||||
boolean currentLineIsBlank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the HTTP request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard HTTP response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connection: close"); // the connection will be closed after completion of the response
|
||||
client.println("Refresh: 5"); // refresh the page automatically every 5 sec
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
// output the value of each analog input pin
|
||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
||||
int sensorReading = analogRead(analogChannel);
|
||||
client.print("analog input ");
|
||||
client.print(analogChannel);
|
||||
client.print(" is ");
|
||||
client.print(sensorReading);
|
||||
client.println("<br />");
|
||||
}
|
||||
client.println("</html>");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
} else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("client disconnected");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your board'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");
|
||||
}
|
||||
2
lib/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h
Normal file
2
lib/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h
Normal file
@@ -0,0 +1,2 @@
|
||||
#define SECRET_SSID ""
|
||||
#define SECRET_PASS ""
|
||||
65
lib/WiFiNINA/keywords.txt
Normal file
65
lib/WiFiNINA/keywords.txt
Normal file
@@ -0,0 +1,65 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For WiFiNINA
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Library (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
WiFi KEYWORD1
|
||||
WiFiNINA KEYWORD1
|
||||
WiFiUdp KEYWORD1
|
||||
WiFiClient KEYWORD1
|
||||
WiFiSSLClient KEYWORD1
|
||||
WiFiServer KEYWORD1
|
||||
WiFiUDP KEYWORD1
|
||||
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
firmwareVersion KEYWORD2
|
||||
status KEYWORD2
|
||||
reasonCode KEYWORD2
|
||||
connect KEYWORD2
|
||||
write KEYWORD2
|
||||
available KEYWORD2
|
||||
config KEYWORD2
|
||||
setDNS KEYWORD2
|
||||
read KEYWORD2
|
||||
flush KEYWORD2
|
||||
stop KEYWORD2
|
||||
connected KEYWORD2
|
||||
begin KEYWORD2
|
||||
disconnect KEYWORD2
|
||||
macAddress KEYWORD2
|
||||
localIP KEYWORD2
|
||||
subnetMask KEYWORD2
|
||||
gatewayIP KEYWORD2
|
||||
SSID KEYWORD2
|
||||
BSSID KEYWORD2
|
||||
RSSI KEYWORD2
|
||||
encryptionType KEYWORD2
|
||||
beginPacket KEYWORD2
|
||||
endPacket KEYWORD2
|
||||
parsePacket KEYWORD2
|
||||
remoteIP KEYWORD2
|
||||
remotePort KEYWORD2
|
||||
|
||||
beginAP KEYWORD2
|
||||
beginEnterprise KEYWORD2
|
||||
setHostname KEYWORD2
|
||||
end KEYWORD2
|
||||
getTime KEYWORD2
|
||||
lowPowerMode KEYWORD2
|
||||
noLowPowerMode KEYWORD2
|
||||
ping KEYWORD2
|
||||
beginMulticast KEYWORD2
|
||||
setTimeout KEYWORD2
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
10
lib/WiFiNINA/library.properties
Normal file
10
lib/WiFiNINA/library.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
name=WiFiNINA
|
||||
version=1.8.8
|
||||
author=Arduino
|
||||
maintainer=Arduino <info@arduino.cc>
|
||||
sentence=Enables network connection (local and Internet) with the Arduino MKR WiFi 1010, Arduino MKR VIDOR 4000, Arduino UNO WiFi Rev.2 and Nano 33 IoT.
|
||||
paragraph=With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The board can connect either to open or encrypted networks (WEP, WPA). The IP address can be assigned statically or through a DHCP. The library can also manage DNS.
|
||||
category=Communication
|
||||
url=http://www.arduino.cc/en/Reference/WiFiNINA
|
||||
architectures=*
|
||||
includes=WiFiNINA.h
|
||||
385
lib/WiFiNINA/src/WiFi.cpp
Normal file
385
lib/WiFiNINA/src/WiFi.cpp
Normal file
@@ -0,0 +1,385 @@
|
||||
/*
|
||||
WiFi.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 "utility/wifi_drv.h"
|
||||
#include "WiFi.h"
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
WiFiClass::WiFiClass() : _timeout(50000)
|
||||
{
|
||||
}
|
||||
|
||||
void WiFiClass::init()
|
||||
{
|
||||
WiFiDrv::wifiDriverInit();
|
||||
}
|
||||
|
||||
const char* WiFiClass::firmwareVersion()
|
||||
{
|
||||
return WiFiDrv::getFwVersion();
|
||||
}
|
||||
|
||||
int WiFiClass::begin(const char* ssid)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
||||
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
|
||||
{
|
||||
for (unsigned long start = millis(); (millis() - start) < _timeout;)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
||||
// set encryption key
|
||||
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
|
||||
{
|
||||
for (unsigned long start = millis(); (millis() - start) < _timeout;)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::begin(const char* ssid, const char *passphrase)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
||||
// set passphrase
|
||||
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
|
||||
{
|
||||
for (unsigned long start = millis(); (millis() - start) < _timeout;)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginAP(const char *ssid)
|
||||
{
|
||||
return beginAP(ssid, 1);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginAP(const char *ssid, uint8_t channel)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
||||
if (WiFiDrv::wifiSetApNetwork(ssid, strlen(ssid), channel) != WL_FAILURE)
|
||||
{
|
||||
for (unsigned long start = millis(); (millis() - start) < _timeout;)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
status = WL_AP_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginAP(const char *ssid, const char* passphrase)
|
||||
{
|
||||
return beginAP(ssid, passphrase, 1);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginAP(const char *ssid, const char* passphrase, uint8_t channel)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
||||
// set passphrase
|
||||
if (WiFiDrv::wifiSetApPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase), channel)!= WL_FAILURE)
|
||||
{
|
||||
for (unsigned long start = millis(); (millis() - start) < _timeout;)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
status = WL_AP_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginEnterprise(const char* ssid, const char* username, const char* password)
|
||||
{
|
||||
return beginEnterprise(ssid, username, password, "");
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginEnterprise(const char* ssid, const char* username, const char* password, const char* identity)
|
||||
{
|
||||
return beginEnterprise(ssid, username, password, identity, "");
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::beginEnterprise(const char* ssid, const char* username, const char* password, const char* identity, const char* ca)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
||||
// set passphrase
|
||||
if (WiFiDrv::wifiSetEnterprise(0 /*PEAP/MSCHAPv2*/, ssid, strlen(ssid), username, strlen(username), password, strlen(password), identity, strlen(identity), ca, strlen(ca) + 1)!= WL_FAILURE)
|
||||
{
|
||||
for (unsigned long start = millis(); (millis() - start) < _timeout;)
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip)
|
||||
{
|
||||
WiFiDrv::config(1, (uint32_t)local_ip, 0, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip, IPAddress dns_server)
|
||||
{
|
||||
WiFiDrv::config(1, (uint32_t)local_ip, 0, 0);
|
||||
WiFiDrv::setDNS(1, (uint32_t)dns_server, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
|
||||
{
|
||||
WiFiDrv::config(2, (uint32_t)local_ip, (uint32_t)gateway, 0);
|
||||
WiFiDrv::setDNS(1, (uint32_t)dns_server, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
|
||||
{
|
||||
WiFiDrv::config(3, (uint32_t)local_ip, (uint32_t)gateway, (uint32_t)subnet);
|
||||
WiFiDrv::setDNS(1, (uint32_t)dns_server, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::setDNS(IPAddress dns_server1)
|
||||
{
|
||||
WiFiDrv::setDNS(1, (uint32_t)dns_server1, 0);
|
||||
}
|
||||
|
||||
void WiFiClass::setDNS(IPAddress dns_server1, IPAddress dns_server2)
|
||||
{
|
||||
WiFiDrv::setDNS(2, (uint32_t)dns_server1, (uint32_t)dns_server2);
|
||||
}
|
||||
|
||||
void WiFiClass::setHostname(const char* name)
|
||||
{
|
||||
WiFiDrv::setHostname(name);
|
||||
}
|
||||
|
||||
int WiFiClass::disconnect()
|
||||
{
|
||||
return WiFiDrv::disconnect();
|
||||
}
|
||||
|
||||
void WiFiClass::end(void)
|
||||
{
|
||||
WiFiDrv::wifiDriverDeinit();
|
||||
}
|
||||
|
||||
uint8_t* WiFiClass::macAddress(uint8_t* mac)
|
||||
{
|
||||
uint8_t* _mac = WiFiDrv::getMacAddress();
|
||||
memcpy(mac, _mac, WL_MAC_ADDR_LENGTH);
|
||||
return mac;
|
||||
}
|
||||
|
||||
IPAddress WiFiClass::localIP()
|
||||
{
|
||||
IPAddress ret;
|
||||
WiFiDrv::getIpAddress(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
IPAddress WiFiClass::subnetMask()
|
||||
{
|
||||
IPAddress ret;
|
||||
WiFiDrv::getSubnetMask(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
IPAddress WiFiClass::gatewayIP()
|
||||
{
|
||||
IPAddress ret;
|
||||
WiFiDrv::getGatewayIP(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char* WiFiClass::SSID()
|
||||
{
|
||||
return WiFiDrv::getCurrentSSID();
|
||||
}
|
||||
|
||||
uint8_t* WiFiClass::BSSID(uint8_t* bssid)
|
||||
{
|
||||
uint8_t* _bssid = WiFiDrv::getCurrentBSSID();
|
||||
memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
|
||||
return bssid;
|
||||
}
|
||||
|
||||
int32_t WiFiClass::RSSI()
|
||||
{
|
||||
return WiFiDrv::getCurrentRSSI();
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::encryptionType()
|
||||
{
|
||||
return WiFiDrv::getCurrentEncryptionType();
|
||||
}
|
||||
|
||||
|
||||
int8_t WiFiClass::scanNetworks()
|
||||
{
|
||||
uint8_t attempts = 10;
|
||||
uint8_t numOfNetworks = 0;
|
||||
|
||||
if (WiFiDrv::startScanNetworks() == WL_FAILURE)
|
||||
return WL_FAILURE;
|
||||
do
|
||||
{
|
||||
delay(2000);
|
||||
numOfNetworks = WiFiDrv::getScanNetworks();
|
||||
}
|
||||
while (( numOfNetworks == 0)&&(--attempts>0));
|
||||
return numOfNetworks;
|
||||
}
|
||||
|
||||
const char* WiFiClass::SSID(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getSSIDNetoworks(networkItem);
|
||||
}
|
||||
|
||||
int32_t WiFiClass::RSSI(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getRSSINetoworks(networkItem);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::encryptionType(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getEncTypeNetowrks(networkItem);
|
||||
}
|
||||
|
||||
uint8_t* WiFiClass::BSSID(uint8_t networkItem, uint8_t* bssid)
|
||||
{
|
||||
return WiFiDrv::getBSSIDNetowrks(networkItem, bssid);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::channel(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getChannelNetowrks(networkItem);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::status()
|
||||
{
|
||||
return WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::reasonCode()
|
||||
{
|
||||
return WiFiDrv::getReasonCode();
|
||||
}
|
||||
|
||||
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
|
||||
{
|
||||
return WiFiDrv::getHostByName(aHostname, aResult);
|
||||
}
|
||||
|
||||
unsigned long WiFiClass::getTime()
|
||||
{
|
||||
return WiFiDrv::getTime();
|
||||
}
|
||||
|
||||
void WiFiClass::lowPowerMode()
|
||||
{
|
||||
WiFiDrv::setPowerMode(1);
|
||||
}
|
||||
|
||||
void WiFiClass::noLowPowerMode()
|
||||
{
|
||||
WiFiDrv::setPowerMode(0);
|
||||
}
|
||||
|
||||
int WiFiClass::ping(const char* hostname, uint8_t ttl)
|
||||
{
|
||||
IPAddress ip;
|
||||
|
||||
if (!hostByName(hostname, ip)) {
|
||||
return WL_PING_UNKNOWN_HOST;
|
||||
}
|
||||
|
||||
return ping(ip, ttl);
|
||||
}
|
||||
|
||||
int WiFiClass::ping(const String &hostname, uint8_t ttl)
|
||||
{
|
||||
return ping(hostname.c_str(), ttl);
|
||||
}
|
||||
|
||||
int WiFiClass::ping(IPAddress host, uint8_t ttl)
|
||||
{
|
||||
return WiFiDrv::ping(host, ttl);
|
||||
}
|
||||
|
||||
void WiFiClass::setTimeout(unsigned long timeout)
|
||||
{
|
||||
_timeout = timeout;
|
||||
}
|
||||
WiFiClass WiFi;
|
||||
281
lib/WiFiNINA/src/WiFi.h
Normal file
281
lib/WiFiNINA/src/WiFi.h
Normal file
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
WiFi.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 WiFi_h
|
||||
#define WiFi_h
|
||||
|
||||
#define WIFI_FIRMWARE_LATEST_VERSION "1.4.4"
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
}
|
||||
|
||||
#include "IPAddress.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiSSLClient.h"
|
||||
#include "WiFiServer.h"
|
||||
#include "WiFiStorage.h"
|
||||
|
||||
class WiFiClass
|
||||
{
|
||||
private:
|
||||
|
||||
static void init();
|
||||
unsigned long _timeout;
|
||||
public:
|
||||
WiFiClass();
|
||||
|
||||
/*
|
||||
* Get firmware version
|
||||
*/
|
||||
static const char* firmwareVersion();
|
||||
|
||||
|
||||
/* Start WiFi connection for OPEN networks
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
*/
|
||||
int begin(const char* ssid);
|
||||
|
||||
/* Start WiFi connection with WEP encryption.
|
||||
* Configure a key into the device. The key type (WEP-40, WEP-104)
|
||||
* is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104).
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param key_idx: The key index to set. Valid values are 0-3.
|
||||
* param key: Key input buffer.
|
||||
*/
|
||||
int begin(const char* ssid, uint8_t key_idx, const char* key);
|
||||
|
||||
/* Start WiFi connection with passphrase
|
||||
* the most secure supported mode will be automatically selected
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param passphrase: Passphrase. Valid characters in a passphrase
|
||||
* must be between ASCII 32-126 (decimal).
|
||||
*/
|
||||
int begin(const char* ssid, const char *passphrase);
|
||||
|
||||
uint8_t beginAP(const char *ssid);
|
||||
uint8_t beginAP(const char *ssid, uint8_t channel);
|
||||
uint8_t beginAP(const char *ssid, const char* passphrase);
|
||||
uint8_t beginAP(const char *ssid, const char* passphrase, uint8_t channel);
|
||||
|
||||
uint8_t beginEnterprise(const char* ssid, const char* username, const char* password);
|
||||
uint8_t beginEnterprise(const char* ssid, const char* username, const char* password, const char* identity);
|
||||
uint8_t beginEnterprise(const char* ssid, const char* username, const char* password, const char* identity, const char* ca);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
*/
|
||||
void config(IPAddress local_ip);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
* param dns_server: IP configuration for DNS server 1
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress dns_server);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
* param dns_server: IP configuration for DNS server 1
|
||||
* param gateway : Static gateway configuration
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway);
|
||||
|
||||
/* Change Ip configuration settings disabling the dhcp client
|
||||
*
|
||||
* param local_ip: Static ip configuration
|
||||
* param dns_server: IP configuration for DNS server 1
|
||||
* param gateway: Static gateway configuration
|
||||
* param subnet: Static Subnet mask
|
||||
*/
|
||||
void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet);
|
||||
|
||||
/* Change DNS Ip configuration
|
||||
*
|
||||
* param dns_server1: ip configuration for DNS server 1
|
||||
*/
|
||||
void setDNS(IPAddress dns_server1);
|
||||
|
||||
/* Change DNS Ip configuration
|
||||
*
|
||||
* param dns_server1: ip configuration for DNS server 1
|
||||
* param dns_server2: ip configuration for DNS server 2
|
||||
*
|
||||
*/
|
||||
void setDNS(IPAddress dns_server1, IPAddress dns_server2);
|
||||
|
||||
|
||||
/* Set the hostname used for DHCP requests
|
||||
*
|
||||
* param name: hostname to set
|
||||
*
|
||||
*/
|
||||
void setHostname(const char* name);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: one value of wl_status_t enum
|
||||
*/
|
||||
int disconnect(void);
|
||||
|
||||
void end(void);
|
||||
|
||||
/*
|
||||
* Get the interface MAC address.
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
uint8_t* macAddress(uint8_t* mac);
|
||||
|
||||
/*
|
||||
* Get the interface IP address.
|
||||
*
|
||||
* return: Ip address value
|
||||
*/
|
||||
IPAddress localIP();
|
||||
|
||||
/*
|
||||
* Get the interface subnet mask address.
|
||||
*
|
||||
* return: subnet mask address value
|
||||
*/
|
||||
IPAddress subnetMask();
|
||||
|
||||
/*
|
||||
* Get the gateway ip address.
|
||||
*
|
||||
* return: gateway ip address value
|
||||
*/
|
||||
IPAddress gatewayIP();
|
||||
|
||||
/*
|
||||
* Return the current SSID associated with the network
|
||||
*
|
||||
* return: ssid string
|
||||
*/
|
||||
const char* SSID();
|
||||
|
||||
/*
|
||||
* Return the current BSSID associated with the network.
|
||||
* It is the MAC address of the Access Point
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
uint8_t* BSSID(uint8_t* bssid);
|
||||
|
||||
/*
|
||||
* Return the current RSSI /Received Signal Strength in dBm)
|
||||
* associated with the network
|
||||
*
|
||||
* return: signed value
|
||||
*/
|
||||
int32_t RSSI();
|
||||
|
||||
/*
|
||||
* Return the Encryption Type associated with the network
|
||||
*
|
||||
* return: one value of wl_enc_type enum
|
||||
*/
|
||||
uint8_t encryptionType();
|
||||
|
||||
/*
|
||||
* Start scan WiFi networks available
|
||||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
int8_t scanNetworks();
|
||||
|
||||
/*
|
||||
* Return the SSID discovered during the network scan.
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: ssid string of the specified item on the networks scanned list
|
||||
*/
|
||||
const char* SSID(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the encryption type of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
|
||||
*/
|
||||
uint8_t encryptionType(uint8_t networkItem);
|
||||
|
||||
uint8_t* BSSID(uint8_t networkItem, uint8_t* bssid);
|
||||
uint8_t channel(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the RSSI of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: signed value of RSSI of the specified item on the networks scanned list
|
||||
*/
|
||||
int32_t RSSI(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return Connection status.
|
||||
*
|
||||
* return: one of the value defined in wl_status_t
|
||||
*/
|
||||
uint8_t status();
|
||||
|
||||
/*
|
||||
* Return The deauthentication reason code.
|
||||
*
|
||||
* return: the deauthentication reason code
|
||||
*/
|
||||
uint8_t reasonCode();
|
||||
|
||||
/*
|
||||
* Resolve the given hostname to an IP address.
|
||||
* param aHostname: Name to be resolved
|
||||
* param aResult: IPAddress structure to store the returned IP address
|
||||
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||
* else error code
|
||||
*/
|
||||
int hostByName(const char* aHostname, IPAddress& aResult);
|
||||
|
||||
unsigned long getTime();
|
||||
|
||||
void lowPowerMode();
|
||||
void noLowPowerMode();
|
||||
|
||||
int ping(const char* hostname, uint8_t ttl = 128);
|
||||
int ping(const String &hostname, uint8_t ttl = 128);
|
||||
int ping(IPAddress host, uint8_t ttl = 128);
|
||||
|
||||
void setTimeout(unsigned long timeout);
|
||||
};
|
||||
|
||||
extern WiFiClass WiFi;
|
||||
|
||||
#endif
|
||||
363
lib/WiFiNINA/src/WiFiClient.cpp
Normal file
363
lib/WiFiNINA/src/WiFiClient.cpp
Normal file
@@ -0,0 +1,363 @@
|
||||
/*
|
||||
WiFiClient.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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
|
||||
*/
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
#include "string.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
|
||||
#include "utility/server_drv.h"
|
||||
#include "utility/wifi_drv.h"
|
||||
#include "utility/WiFiSocketBuffer.h"
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiClient.h"
|
||||
|
||||
uint16_t WiFiClient::_srcport = 1024;
|
||||
|
||||
WiFiClient::WiFiClient() : _sock(NO_SOCKET_AVAIL), _retrySend(true) {
|
||||
}
|
||||
|
||||
WiFiClient::WiFiClient(uint8_t sock) : _sock(sock), _retrySend(true) {
|
||||
}
|
||||
|
||||
int WiFiClient::connect(const char* host, uint16_t port) {
|
||||
IPAddress remote_addr;
|
||||
if (WiFi.hostByName(host, remote_addr))
|
||||
{
|
||||
return connect(remote_addr, port);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WiFiClient::connect(IPAddress ip, uint16_t port) {
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(uint32_t(ip), port, _sock);
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
// wait 4 second for the connection to close
|
||||
while (!connected() && millis() - start < 10000)
|
||||
delay(1);
|
||||
|
||||
if (!connected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
Serial.println("No Socket available");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WiFiClient::connectSSL(IPAddress ip, uint16_t port)
|
||||
{
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(uint32_t(ip), port, _sock, TLS_MODE);
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
// wait 4 second for the connection to close
|
||||
while (!connected() && millis() - start < 10000)
|
||||
delay(1);
|
||||
|
||||
if (!connected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
Serial.println("No Socket available");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WiFiClient::connectSSL(const char *host, uint16_t port)
|
||||
{
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(host, strlen(host), uint32_t(0), port, _sock, TLS_MODE);
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
// wait 4 second for the connection to close
|
||||
while (!connected() && millis() - start < 10000)
|
||||
delay(1);
|
||||
|
||||
if (!connected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
Serial.println("No Socket available");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WiFiClient::connectBearSSL(IPAddress ip, uint16_t port)
|
||||
{
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(uint32_t(ip), port, _sock, TLS_BEARSSL_MODE);
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
// wait 4 second for the connection to close
|
||||
while (!connected() && millis() - start < 10000)
|
||||
delay(1);
|
||||
|
||||
if (!connected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
Serial.println("No Socket available");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int WiFiClient::connectBearSSL(const char *host, uint16_t port)
|
||||
{
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(host, strlen(host), uint32_t(0), port, _sock, TLS_BEARSSL_MODE);
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
// wait 4 second for the connection to close
|
||||
while (!connected() && millis() - start < 10000)
|
||||
delay(1);
|
||||
|
||||
if (!connected())
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
Serial.println("No Socket available");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(uint8_t b) {
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(const uint8_t *buf, size_t size) {
|
||||
if (_sock == NO_SOCKET_AVAIL)
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
if (size==0)
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t written = ServerDrv::sendData(_sock, buf, size);
|
||||
if (!written && _retrySend) {
|
||||
written = retry(buf, size, true);
|
||||
}
|
||||
if(!written){
|
||||
// close socket
|
||||
ServerDrv::stopClient(_sock);
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ServerDrv::checkDataSent(_sock))
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
size_t WiFiClient::retry(const uint8_t *buf, size_t size, bool write) {
|
||||
size_t rec_bytes = 0;
|
||||
|
||||
if (write) {
|
||||
|
||||
//RETRY WRITE
|
||||
for (int i=0; i<5; i++) {
|
||||
rec_bytes = ServerDrv::sendData(_sock, buf, size);
|
||||
if (rec_bytes) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rec_bytes;
|
||||
|
||||
} else {
|
||||
return rec_bytes;
|
||||
//RETRY READ
|
||||
// To be implemented, if needed
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int WiFiClient::available() {
|
||||
if (_sock != 255)
|
||||
{
|
||||
return WiFiSocketBuffer.available(_sock);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WiFiClient::read() {
|
||||
if (!available())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t b;
|
||||
|
||||
WiFiSocketBuffer.read(_sock, &b, sizeof(b));
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
|
||||
int WiFiClient::read(uint8_t* buf, size_t size) {
|
||||
return WiFiSocketBuffer.read(_sock, buf, size);
|
||||
}
|
||||
|
||||
int WiFiClient::peek() {
|
||||
return WiFiSocketBuffer.peek(_sock);
|
||||
}
|
||||
|
||||
void WiFiClient::setRetry(bool retry) {
|
||||
_retrySend = retry;
|
||||
}
|
||||
|
||||
void WiFiClient::flush() {
|
||||
// TODO: a real check to ensure transmission has been completed
|
||||
}
|
||||
|
||||
void WiFiClient::stop() {
|
||||
|
||||
if (_sock == 255)
|
||||
return;
|
||||
|
||||
ServerDrv::stopClient(_sock);
|
||||
|
||||
int count = 0;
|
||||
// wait maximum 5 secs for the connection to close
|
||||
while (status() != CLOSED && ++count < 50)
|
||||
delay(100);
|
||||
|
||||
WiFiSocketBuffer.close(_sock);
|
||||
_sock = 255;
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::connected() {
|
||||
|
||||
if (_sock == 255) {
|
||||
return 0;
|
||||
} else if (available()) {
|
||||
return 1;
|
||||
} else {
|
||||
uint8_t s = status();
|
||||
|
||||
uint8_t result = !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
|
||||
s == FIN_WAIT_2 || s == TIME_WAIT ||
|
||||
s == SYN_SENT || s== SYN_RCVD ||
|
||||
(s == CLOSE_WAIT));
|
||||
|
||||
if (result == 0) {
|
||||
WiFiSocketBuffer.close(_sock);
|
||||
_sock = 255;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t WiFiClient::status() {
|
||||
if (_sock == 255) {
|
||||
return CLOSED;
|
||||
} else {
|
||||
return ServerDrv::getClientState(_sock);
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient::operator bool() {
|
||||
return _sock != 255;
|
||||
}
|
||||
|
||||
IPAddress WiFiClient::remoteIP()
|
||||
{
|
||||
uint8_t _remoteIp[4] = {0};
|
||||
uint8_t _remotePort[2] = {0};
|
||||
|
||||
WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
|
||||
IPAddress ip(_remoteIp);
|
||||
return ip;
|
||||
}
|
||||
|
||||
uint16_t WiFiClient::remotePort()
|
||||
{
|
||||
uint8_t _remoteIp[4] = {0};
|
||||
uint8_t _remotePort[2] = {0};
|
||||
|
||||
WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
|
||||
uint16_t port = (_remotePort[0]<<8)+_remotePort[1];
|
||||
return port;
|
||||
}
|
||||
69
lib/WiFiNINA/src/WiFiClient.h
Normal file
69
lib/WiFiNINA/src/WiFiClient.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
WiFiClient.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 wificlient_h
|
||||
#define wificlient_h
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#include "Client.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
class WiFiClient : public Client {
|
||||
|
||||
public:
|
||||
WiFiClient();
|
||||
WiFiClient(uint8_t sock);
|
||||
|
||||
uint8_t status();
|
||||
virtual int connect(IPAddress ip, uint16_t port);
|
||||
virtual int connect(const char *host, uint16_t port);
|
||||
virtual int connectSSL(IPAddress ip, uint16_t port);
|
||||
virtual int connectSSL(const char *host, uint16_t port);
|
||||
virtual int connectBearSSL(IPAddress ip, uint16_t port);
|
||||
virtual int connectBearSSL(const char *host, uint16_t port);
|
||||
virtual size_t write(uint8_t);
|
||||
virtual size_t write(const uint8_t *buf, size_t size);
|
||||
virtual size_t retry(const uint8_t *buf, size_t size, bool write);
|
||||
virtual int available();
|
||||
virtual int read();
|
||||
virtual int read(uint8_t *buf, size_t size);
|
||||
virtual int peek();
|
||||
virtual void setRetry(bool retry);
|
||||
virtual void flush();
|
||||
virtual void stop();
|
||||
virtual uint8_t connected();
|
||||
virtual operator bool();
|
||||
|
||||
virtual IPAddress remoteIP();
|
||||
virtual uint16_t remotePort();
|
||||
|
||||
friend class WiFiServer;
|
||||
friend class WiFiDrv;
|
||||
|
||||
using Print::write;
|
||||
|
||||
private:
|
||||
static uint16_t _srcport;
|
||||
uint8_t _sock; //not used
|
||||
uint16_t _socket;
|
||||
bool _retrySend;
|
||||
};
|
||||
|
||||
#endif
|
||||
25
lib/WiFiNINA/src/WiFiNINA.h
Normal file
25
lib/WiFiNINA/src/WiFiNINA.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
This file is part of the WiFiNINA library.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef WiFiNINA_h
|
||||
#define WiFiNINA_h
|
||||
|
||||
#include "WiFi.h"
|
||||
|
||||
#endif
|
||||
60
lib/WiFiNINA/src/WiFiSSLClient.cpp
Normal file
60
lib/WiFiNINA/src/WiFiSSLClient.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
This file is part of the WiFiNINA library.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include "WiFiSSLClient.h"
|
||||
|
||||
WiFiSSLClient::WiFiSSLClient() :
|
||||
WiFiClient()
|
||||
{
|
||||
}
|
||||
|
||||
WiFiSSLClient::WiFiSSLClient(uint8_t sock) :
|
||||
WiFiClient(sock)
|
||||
{
|
||||
}
|
||||
|
||||
int WiFiSSLClient::connect(IPAddress ip, uint16_t port)
|
||||
{
|
||||
return WiFiClient::connectSSL(ip, port);
|
||||
}
|
||||
|
||||
int WiFiSSLClient::connect(const char* host, uint16_t port)
|
||||
{
|
||||
return WiFiClient::connectSSL(host, port);
|
||||
}
|
||||
|
||||
WiFiBearSSLClient::WiFiBearSSLClient() :
|
||||
WiFiClient()
|
||||
{
|
||||
}
|
||||
|
||||
WiFiBearSSLClient::WiFiBearSSLClient(uint8_t sock) :
|
||||
WiFiClient(sock)
|
||||
{
|
||||
}
|
||||
|
||||
int WiFiBearSSLClient::connect(IPAddress ip, uint16_t port)
|
||||
{
|
||||
return WiFiClient::connectBearSSL(ip, port);
|
||||
}
|
||||
|
||||
int WiFiBearSSLClient::connect(const char* host, uint16_t port)
|
||||
{
|
||||
return WiFiClient::connectBearSSL(host, port);
|
||||
}
|
||||
45
lib/WiFiNINA/src/WiFiSSLClient.h
Normal file
45
lib/WiFiNINA/src/WiFiSSLClient.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
This file is part of the WiFiNINA library.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef WIFISSLCLIENT_H
|
||||
#define WIFISSLCLIENT_H
|
||||
|
||||
#include "WiFiClient.h"
|
||||
|
||||
class WiFiSSLClient : public WiFiClient {
|
||||
|
||||
public:
|
||||
WiFiSSLClient();
|
||||
WiFiSSLClient(uint8_t sock);
|
||||
|
||||
virtual int connect(IPAddress ip, uint16_t port);
|
||||
virtual int connect(const char* host, uint16_t port);
|
||||
};
|
||||
|
||||
class WiFiBearSSLClient : public WiFiClient {
|
||||
|
||||
public:
|
||||
WiFiBearSSLClient();
|
||||
WiFiBearSSLClient(uint8_t sock);
|
||||
|
||||
virtual int connect(IPAddress ip, uint16_t port);
|
||||
virtual int connect(const char* host, uint16_t port);
|
||||
};
|
||||
|
||||
#endif /* WIFISSLCLIENT_H */
|
||||
119
lib/WiFiNINA/src/WiFiServer.cpp
Normal file
119
lib/WiFiNINA/src/WiFiServer.cpp
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
WiFiServer.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 <string.h>
|
||||
#include "utility/server_drv.h"
|
||||
|
||||
extern "C" {
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
|
||||
WiFiServer::WiFiServer(uint16_t port) :
|
||||
_sock(NO_SOCKET_AVAIL),
|
||||
_lastSock(NO_SOCKET_AVAIL)
|
||||
{
|
||||
_port = port;
|
||||
}
|
||||
|
||||
void WiFiServer::begin()
|
||||
{
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startServer(_port, _sock);
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient WiFiServer::available(byte* status)
|
||||
{
|
||||
int sock = NO_SOCKET_AVAIL;
|
||||
|
||||
if (_sock != NO_SOCKET_AVAIL) {
|
||||
// check previous received client socket
|
||||
if (_lastSock != NO_SOCKET_AVAIL) {
|
||||
WiFiClient client(_lastSock);
|
||||
|
||||
if (client.connected() && client.available()) {
|
||||
sock = _lastSock;
|
||||
}
|
||||
}
|
||||
|
||||
if (sock == NO_SOCKET_AVAIL) {
|
||||
// check for new client socket
|
||||
sock = ServerDrv::availServer(_sock);
|
||||
}
|
||||
}
|
||||
|
||||
if (sock != NO_SOCKET_AVAIL) {
|
||||
WiFiClient client(sock);
|
||||
|
||||
if (status != NULL) {
|
||||
*status = client.status();
|
||||
}
|
||||
|
||||
_lastSock = sock;
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
return WiFiClient(255);
|
||||
}
|
||||
|
||||
uint8_t WiFiServer::status() {
|
||||
if (_sock == NO_SOCKET_AVAIL) {
|
||||
return CLOSED;
|
||||
} else {
|
||||
return ServerDrv::getServerState(_sock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
size_t WiFiServer::write(uint8_t b)
|
||||
{
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
size_t WiFiServer::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
if (size==0)
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t written = ServerDrv::sendData(_sock, buffer, size);
|
||||
if (!written)
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!ServerDrv::checkDataSent(_sock))
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
49
lib/WiFiNINA/src/WiFiServer.h
Normal file
49
lib/WiFiNINA/src/WiFiServer.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
WiFiServer.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 wifiserver_h
|
||||
#define wifiserver_h
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
}
|
||||
|
||||
#include "Server.h"
|
||||
|
||||
class WiFiClient;
|
||||
|
||||
class WiFiServer : public Server {
|
||||
private:
|
||||
uint8_t _sock;
|
||||
uint8_t _lastSock;
|
||||
uint16_t _port;
|
||||
void* pcb;
|
||||
public:
|
||||
WiFiServer(uint16_t);
|
||||
WiFiClient available(uint8_t* status = NULL);
|
||||
void begin();
|
||||
virtual size_t write(uint8_t);
|
||||
virtual size_t write(const uint8_t *buf, size_t size);
|
||||
uint8_t status();
|
||||
|
||||
using Print::write;
|
||||
};
|
||||
|
||||
#endif
|
||||
30
lib/WiFiNINA/src/WiFiStorage.cpp
Normal file
30
lib/WiFiNINA/src/WiFiStorage.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
WiFiStorage.cpp - Library for Arduino boards based on NINA WiFi module.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 "WiFiStorage.h"
|
||||
|
||||
WiFiStorageFile WiFiStorageClass::open(const char *filename) {
|
||||
WiFiStorageFile file(filename);
|
||||
file.size();
|
||||
return file;
|
||||
}
|
||||
|
||||
WiFiStorageFile WiFiStorageClass::open(String filename) {
|
||||
return open(filename.c_str());
|
||||
}
|
||||
151
lib/WiFiNINA/src/WiFiStorage.h
Normal file
151
lib/WiFiNINA/src/WiFiStorage.h
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
WiFiStorage.h - Library for Arduino boards based on NINA WiFi module.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 wifistorage_h
|
||||
#define wifistorage_h
|
||||
|
||||
#include "utility/wifi_drv.h"
|
||||
|
||||
class WiFiStorageFile;
|
||||
|
||||
class WiFiStorageClass
|
||||
{
|
||||
public:
|
||||
static bool begin();
|
||||
|
||||
static WiFiStorageFile open(const char *filename);
|
||||
static WiFiStorageFile open(String filename);
|
||||
|
||||
static bool exists(const char *filename) {
|
||||
uint32_t len;
|
||||
return (WiFiDrv::existsFile(filename, strlen(filename), &len) > 0);
|
||||
}
|
||||
static bool exists(const char *filename, uint32_t* len) {
|
||||
return (WiFiDrv::existsFile(filename, strlen(filename), len) > 0);
|
||||
}
|
||||
static bool remove(const char *filename) {
|
||||
WiFiDrv::deleteFile(filename, strlen(filename));
|
||||
return true;
|
||||
}
|
||||
static bool rename(const char * old_file_name, const char * new_file_name) {
|
||||
return (WiFiDrv::renameFile(old_file_name, strlen(old_file_name), new_file_name, strlen(new_file_name)) == 0);
|
||||
}
|
||||
static bool read(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
|
||||
WiFiDrv::readFile(filename, strlen(filename), offset, buffer, buffer_len);
|
||||
return true;
|
||||
}
|
||||
static bool write(const char *filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
|
||||
WiFiDrv::writeFile(filename, strlen(filename), offset, buffer, buffer_len);
|
||||
return true;
|
||||
}
|
||||
static bool download(const char* url, const char *filename) {
|
||||
WiFiDrv::downloadFile(url, strlen(url), filename, strlen(filename));
|
||||
return true;
|
||||
}
|
||||
static bool downloadOTA(const char * url, uint8_t * res_ota_download = NULL) {
|
||||
/* The buffer within the nina firmware allows a maximum
|
||||
* url size of 128 bytes. It's better to prevent the
|
||||
* transmission of over-sized URL as soon as possible.
|
||||
*/
|
||||
if (strlen(url) > 128)
|
||||
return false;
|
||||
|
||||
uint8_t const res = WiFiDrv::downloadOTA(url, strlen(url));
|
||||
if (res_ota_download)
|
||||
*res_ota_download = res;
|
||||
bool const success = (res == 0);
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
static bool remove(String filename) {
|
||||
return remove(filename.c_str());
|
||||
}
|
||||
static bool rename(String old_file_name, String new_file_name) {
|
||||
return rename(old_file_name.c_str(), new_file_name.c_str());
|
||||
}
|
||||
static bool read(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
|
||||
return read(filename.c_str(), offset, buffer, buffer_len);
|
||||
}
|
||||
static bool write(String filename, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
|
||||
return write(filename.c_str(), offset, buffer, buffer_len);
|
||||
}
|
||||
static bool download(String url, String filename) {
|
||||
return download(url.c_str(), filename.c_str());
|
||||
}
|
||||
static bool download(String url, uint8_t * res_ota_download = NULL) {
|
||||
return downloadOTA(url.c_str(), res_ota_download);
|
||||
}
|
||||
};
|
||||
|
||||
extern WiFiStorageClass WiFiStorage;
|
||||
|
||||
|
||||
class WiFiStorageFile
|
||||
{
|
||||
public:
|
||||
constexpr WiFiStorageFile(const char* _filename) : filename(_filename) { }
|
||||
|
||||
operator bool() {
|
||||
return WiFiStorage.exists(filename, &length);
|
||||
}
|
||||
uint32_t read(void *buf, uint32_t rdlen) {
|
||||
if (offset + rdlen > length) {
|
||||
if (offset >= length) return 0;
|
||||
rdlen = length - offset;
|
||||
}
|
||||
WiFiStorage.read(filename, offset, (uint8_t*)buf, rdlen);
|
||||
offset += rdlen;
|
||||
return rdlen;
|
||||
}
|
||||
uint32_t write(const void *buf, uint32_t wrlen) {
|
||||
WiFiStorage.write(filename, offset, (uint8_t*)buf, wrlen);
|
||||
offset += wrlen;
|
||||
return wrlen;
|
||||
}
|
||||
void seek(uint32_t n) {
|
||||
offset = n;
|
||||
}
|
||||
uint32_t position() {
|
||||
return offset;
|
||||
}
|
||||
uint32_t size() {
|
||||
WiFiStorage.exists(filename, &length);
|
||||
return length;
|
||||
}
|
||||
uint32_t available() {
|
||||
WiFiStorage.exists(filename, &length);
|
||||
return length - offset;
|
||||
}
|
||||
void erase() {
|
||||
offset = 0;
|
||||
WiFiStorage.remove(filename);
|
||||
}
|
||||
void flush();
|
||||
void close() {
|
||||
offset = 0;
|
||||
}
|
||||
protected:
|
||||
friend class WiFiStorageClass;
|
||||
uint32_t offset = 0;
|
||||
uint32_t length = 0;
|
||||
const char* filename;
|
||||
};
|
||||
|
||||
#endif
|
||||
217
lib/WiFiNINA/src/WiFiUdp.cpp
Normal file
217
lib/WiFiNINA/src/WiFiUdp.cpp
Normal file
@@ -0,0 +1,217 @@
|
||||
/*
|
||||
WiFiUdp.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 <string.h>
|
||||
|
||||
extern "C" {
|
||||
#include "utility/debug.h"
|
||||
#include "utility/wifi_spi.h"
|
||||
}
|
||||
|
||||
#include "utility/server_drv.h"
|
||||
#include "utility/wifi_drv.h"
|
||||
#include "utility/WiFiSocketBuffer.h"
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiUdp.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
WiFiUDP::WiFiUDP() : _sock(NO_SOCKET_AVAIL), _parsed(0) {}
|
||||
|
||||
/* Start WiFiUDP socket, listening at local port PORT */
|
||||
uint8_t WiFiUDP::begin(uint16_t port) {
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
uint8_t sock = ServerDrv::getSocket();
|
||||
if (sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startServer(port, sock, UDP_MODE);
|
||||
_sock = sock;
|
||||
_port = port;
|
||||
_parsed = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t WiFiUDP::beginMulticast(IPAddress ip, uint16_t port) {
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
uint8_t sock = ServerDrv::getSocket();
|
||||
if (sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startServer(ip, port, sock, UDP_MULTICAST_MODE);
|
||||
_sock = sock;
|
||||
_port = port;
|
||||
_parsed = 0;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* return number of bytes available in the current packet,
|
||||
will return zero if parsePacket hasn't been called yet */
|
||||
int WiFiUDP::available() {
|
||||
return _parsed;
|
||||
}
|
||||
|
||||
/* Release any resources being used by this WiFiUDP instance */
|
||||
void WiFiUDP::stop()
|
||||
{
|
||||
if (_sock == NO_SOCKET_AVAIL)
|
||||
return;
|
||||
|
||||
ServerDrv::stopClient(_sock);
|
||||
|
||||
WiFiSocketBuffer.close(_sock);
|
||||
_sock = NO_SOCKET_AVAIL;
|
||||
}
|
||||
|
||||
int WiFiUDP::beginPacket(const char *host, uint16_t port)
|
||||
{
|
||||
// Look up the host first
|
||||
int ret = 0;
|
||||
IPAddress remote_addr;
|
||||
if (WiFi.hostByName(host, remote_addr))
|
||||
{
|
||||
return beginPacket(remote_addr, port);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
{
|
||||
if (_sock == NO_SOCKET_AVAIL)
|
||||
_sock = ServerDrv::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(uint32_t(ip), port, _sock, UDP_MODE);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WiFiUDP::endPacket()
|
||||
{
|
||||
return ServerDrv::sendUdpData(_sock);
|
||||
}
|
||||
|
||||
size_t WiFiUDP::write(uint8_t byte)
|
||||
{
|
||||
return write(&byte, 1);
|
||||
}
|
||||
|
||||
size_t WiFiUDP::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
ServerDrv::insertDataBuf(_sock, buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int WiFiUDP::parsePacket()
|
||||
{
|
||||
while (_parsed--)
|
||||
{
|
||||
// discard previously parsed packet data
|
||||
uint8_t b;
|
||||
|
||||
WiFiSocketBuffer.read(_sock, &b, sizeof(b));
|
||||
}
|
||||
|
||||
_parsed = ServerDrv::availData(_sock);
|
||||
|
||||
return _parsed;
|
||||
}
|
||||
|
||||
int WiFiUDP::read()
|
||||
{
|
||||
if (_parsed < 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t b;
|
||||
|
||||
WiFiSocketBuffer.read(_sock, &b, sizeof(b));
|
||||
_parsed--;
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
int WiFiUDP::read(unsigned char* buffer, size_t len)
|
||||
{
|
||||
if (_parsed < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int result = WiFiSocketBuffer.read(_sock, buffer, len);
|
||||
|
||||
if (result > 0)
|
||||
{
|
||||
_parsed -= result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int WiFiUDP::peek()
|
||||
{
|
||||
if (_parsed < 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return WiFiSocketBuffer.peek(_sock);
|
||||
}
|
||||
|
||||
void WiFiUDP::flush()
|
||||
{
|
||||
// TODO: a real check to ensure transmission has been completed
|
||||
}
|
||||
|
||||
IPAddress WiFiUDP::remoteIP()
|
||||
{
|
||||
uint8_t _remoteIp[4] = {0};
|
||||
uint8_t _remotePort[2] = {0};
|
||||
|
||||
WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
|
||||
IPAddress ip(_remoteIp);
|
||||
return ip;
|
||||
}
|
||||
|
||||
uint16_t WiFiUDP::remotePort()
|
||||
{
|
||||
uint8_t _remoteIp[4] = {0};
|
||||
uint8_t _remotePort[2] = {0};
|
||||
|
||||
WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
|
||||
uint16_t port = (_remotePort[0]<<8)+_remotePort[1];
|
||||
return port;
|
||||
}
|
||||
|
||||
83
lib/WiFiNINA/src/WiFiUdp.h
Normal file
83
lib/WiFiNINA/src/WiFiUdp.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
WiFiUdp.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 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 wifiudp_h
|
||||
#define wifiudp_h
|
||||
|
||||
#include <Udp.h>
|
||||
|
||||
#define UDP_TX_PACKET_MAX_SIZE 24
|
||||
|
||||
class WiFiUDP : public UDP {
|
||||
private:
|
||||
uint8_t _sock; // socket ID for Wiz5100
|
||||
uint16_t _port; // local port to listen on
|
||||
int _parsed;
|
||||
|
||||
public:
|
||||
WiFiUDP(); // Constructor
|
||||
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual uint8_t beginMulticast(IPAddress, uint16_t); // initialize, start listening on specified multicast IP address and port. Returns 1 if successful, 0 if there are no sockets available to use
|
||||
virtual void stop(); // Finish with the UDP socket
|
||||
|
||||
// Sending UDP packets
|
||||
|
||||
// Start building up a packet to send to the remote host specific in ip and port
|
||||
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
|
||||
virtual int beginPacket(IPAddress ip, uint16_t port);
|
||||
// Start building up a packet to send to the remote host specific in host and port
|
||||
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
|
||||
virtual int beginPacket(const char *host, uint16_t port);
|
||||
// Finish off this packet and send it
|
||||
// Returns 1 if the packet was sent successfully, 0 if there was an error
|
||||
virtual int endPacket();
|
||||
// Write a single byte into the packet
|
||||
virtual size_t write(uint8_t);
|
||||
// Write size bytes from buffer into the packet
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
|
||||
using Print::write;
|
||||
|
||||
// Start processing the next available incoming packet
|
||||
// Returns the size of the packet in bytes, or 0 if no packets are available
|
||||
virtual int parsePacket();
|
||||
// Number of bytes remaining in the current packet
|
||||
virtual int available();
|
||||
// Read a single byte from the current packet
|
||||
virtual int read();
|
||||
// Read up to len bytes from the current packet and place them into buffer
|
||||
// Returns the number of bytes read, or 0 if none are available
|
||||
virtual int read(unsigned char* buffer, size_t len);
|
||||
// Read up to len characters from the current packet and place them into buffer
|
||||
// Returns the number of characters read, or 0 if none are available
|
||||
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
|
||||
// Return the next byte from the current packet without moving on to the next byte
|
||||
virtual int peek();
|
||||
virtual void flush(); // Finish reading the current packet
|
||||
|
||||
// Return the IP address of the host who sent the current incoming packet
|
||||
virtual IPAddress remoteIP();
|
||||
// Return the port of the host who sent the current incoming packet
|
||||
virtual uint16_t remotePort();
|
||||
|
||||
friend class WiFiDrv;
|
||||
};
|
||||
|
||||
#endif
|
||||
104
lib/WiFiNINA/src/utility/WiFiSocketBuffer.cpp
Normal file
104
lib/WiFiNINA/src/utility/WiFiSocketBuffer.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
This file is part of the WiFiNINA library.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "utility/server_drv.h"
|
||||
|
||||
#include "WiFiSocketBuffer.h"
|
||||
|
||||
#define WIFI_SOCKET_NUM_BUFFERS (sizeof(_buffers) / sizeof(_buffers[0]))
|
||||
|
||||
#ifdef __AVR__
|
||||
#define WIFI_SOCKET_BUFFER_SIZE 64
|
||||
#else
|
||||
#define WIFI_SOCKET_BUFFER_SIZE 1500
|
||||
#endif
|
||||
|
||||
WiFiSocketBufferClass::WiFiSocketBufferClass()
|
||||
{
|
||||
memset(&_buffers, 0x00, sizeof(_buffers));
|
||||
}
|
||||
|
||||
WiFiSocketBufferClass::~WiFiSocketBufferClass()
|
||||
{
|
||||
for (unsigned int i = 0; i < WIFI_SOCKET_NUM_BUFFERS; i++) {
|
||||
close(i);
|
||||
}
|
||||
}
|
||||
|
||||
void WiFiSocketBufferClass::close(int socket)
|
||||
{
|
||||
if (_buffers[socket].data) {
|
||||
free(_buffers[socket].data);
|
||||
_buffers[socket].data = _buffers[socket].head = NULL;
|
||||
_buffers[socket].length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
int WiFiSocketBufferClass::available(int socket)
|
||||
{
|
||||
if (_buffers[socket].length == 0) {
|
||||
if (_buffers[socket].data == NULL) {
|
||||
_buffers[socket].data = _buffers[socket].head = (uint8_t*)malloc(WIFI_SOCKET_BUFFER_SIZE);
|
||||
_buffers[socket].length = 0;
|
||||
}
|
||||
|
||||
// sizeof(size_t) is architecture dependent
|
||||
// but we need a 16 bit data type here
|
||||
uint16_t size = WIFI_SOCKET_BUFFER_SIZE;
|
||||
if (ServerDrv::getDataBuf(socket, _buffers[socket].data, &size)) {
|
||||
_buffers[socket].head = _buffers[socket].data;
|
||||
_buffers[socket].length = size;
|
||||
}
|
||||
}
|
||||
|
||||
return _buffers[socket].length;
|
||||
}
|
||||
|
||||
int WiFiSocketBufferClass::peek(int socket)
|
||||
{
|
||||
if (!available(socket)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return *_buffers[socket].head;
|
||||
}
|
||||
|
||||
int WiFiSocketBufferClass::read(int socket, uint8_t* data, size_t length)
|
||||
{
|
||||
int avail = available(socket);
|
||||
|
||||
if (!avail) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (avail < (int)length) {
|
||||
length = avail;
|
||||
}
|
||||
|
||||
memcpy(data, _buffers[socket].head, length);
|
||||
_buffers[socket].head += length;
|
||||
_buffers[socket].length -= length;
|
||||
|
||||
return length;
|
||||
}
|
||||
|
||||
WiFiSocketBufferClass WiFiSocketBuffer;
|
||||
52
lib/WiFiNINA/src/utility/WiFiSocketBuffer.h
Normal file
52
lib/WiFiNINA/src/utility/WiFiSocketBuffer.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
This file is part of the WiFiNINA library.
|
||||
Copyright (c) 2018 Arduino SA. All rights 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 Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef WiFiSocketBuffer_h
|
||||
#define WiFiSocketBuffer_h
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
}
|
||||
|
||||
class WiFiSocketBufferClass {
|
||||
|
||||
public:
|
||||
WiFiSocketBufferClass();
|
||||
~WiFiSocketBufferClass();
|
||||
|
||||
void close(int socket);
|
||||
|
||||
int available(int socket);
|
||||
int peek(int socket);
|
||||
int read(int socket, uint8_t* data, size_t length);
|
||||
|
||||
private:
|
||||
struct {
|
||||
uint8_t* data;
|
||||
uint8_t* head;
|
||||
int length;
|
||||
} _buffers[WIFI_MAX_SOCK_NUM];
|
||||
};
|
||||
|
||||
extern WiFiSocketBufferClass WiFiSocketBuffer;
|
||||
|
||||
#endif
|
||||
95
lib/WiFiNINA/src/utility/debug.h
Normal file
95
lib/WiFiNINA/src/utility/debug.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
debug.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2011-2014 Arduino. 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
|
||||
*/
|
||||
//*********************************************/
|
||||
//
|
||||
// File: debug.h
|
||||
//
|
||||
// Author: dlf (Metodo2 srl)
|
||||
//
|
||||
//********************************************/
|
||||
|
||||
|
||||
#ifndef Debug_H
|
||||
#define Debug_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PRINT_FILE_LINE() do { \
|
||||
Serial.print("[");Serial.print(__FILE__); \
|
||||
Serial.print("::");Serial.print(__LINE__);Serial.print("]");\
|
||||
}while (0);
|
||||
|
||||
#ifdef _DEBUG_
|
||||
|
||||
#define INFO(format, args...) do { \
|
||||
char buf[250]; \
|
||||
sprintf(buf, format, args); \
|
||||
Serial.println(buf); \
|
||||
} while(0);
|
||||
|
||||
#define INFO1(x) do { PRINT_FILE_LINE() Serial.print("-I-");\
|
||||
Serial.println(x); \
|
||||
}while (0);
|
||||
|
||||
|
||||
#define INFO2(x,y) do { PRINT_FILE_LINE() Serial.print("-I-");\
|
||||
Serial.print(x,16);Serial.print(",");Serial.println(y,16); \
|
||||
}while (0);
|
||||
|
||||
|
||||
#else
|
||||
#define INFO1(x) do {} while(0);
|
||||
#define INFO2(x,y) do {} while(0);
|
||||
#define INFO(format, args...) do {} while(0);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define WARN(args) do { PRINT_FILE_LINE() \
|
||||
Serial.print("-W-"); Serial.println(args); \
|
||||
}while (0);
|
||||
#else
|
||||
#define WARN(args) do {} while (0);
|
||||
#endif
|
||||
|
||||
#if _DEBUG_SPI_
|
||||
#define DBG_PIN2 5
|
||||
#define DBG_PIN 4
|
||||
|
||||
#define START() digitalWrite(DBG_PIN2, HIGH);
|
||||
#define END() digitalWrite(DBG_PIN2, LOW);
|
||||
#define SET_TRIGGER() digitalWrite(DBG_PIN, HIGH);
|
||||
#define RST_TRIGGER() digitalWrite(DBG_PIN, LOW);
|
||||
|
||||
#define INIT_TRIGGER() pinMode(DBG_PIN, OUTPUT); \
|
||||
pinMode(DBG_PIN2, OUTPUT); \
|
||||
RST_TRIGGER()
|
||||
#define TOGGLE_TRIGGER() SET_TRIGGER() \
|
||||
delayMicroseconds(2); \
|
||||
RST_TRIGGER()
|
||||
#else
|
||||
#define START()
|
||||
#define END()
|
||||
#define SET_TRIGGER()
|
||||
#define RST_TRIGGER()
|
||||
#define INIT_TRIGGER()
|
||||
#define TOGGLE_TRIGGER()
|
||||
#endif
|
||||
|
||||
#endif
|
||||
520
lib/WiFiNINA/src/utility/server_drv.cpp
Normal file
520
lib/WiFiNINA/src/utility/server_drv.cpp
Normal file
@@ -0,0 +1,520 @@
|
||||
/*
|
||||
server_drv.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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
|
||||
*/
|
||||
|
||||
//#define _DEBUG_
|
||||
|
||||
#include "utility/server_drv.h"
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "utility/spi_drv.h"
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_types.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
|
||||
// Start server TCP on port specified
|
||||
void ServerDrv::startServer(uint16_t port, uint8_t sock, uint8_t protMode)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_SERVER_TCP_CMD, PARAM_NUMS_3);
|
||||
SpiDrv::sendParam(port);
|
||||
SpiDrv::sendParam(&sock, 1);
|
||||
SpiDrv::sendParam(&protMode, 1, LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(START_SERVER_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
void ServerDrv::startServer(uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_SERVER_TCP_CMD, PARAM_NUMS_4);
|
||||
SpiDrv::sendParam((uint8_t*)&ipAddress, sizeof(ipAddress));
|
||||
SpiDrv::sendParam(port);
|
||||
SpiDrv::sendParam(&sock, 1);
|
||||
SpiDrv::sendParam(&protMode, 1, LAST_PARAM);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(START_SERVER_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
// Start server TCP on port specified
|
||||
void ServerDrv::startClient(uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_4);
|
||||
SpiDrv::sendParam((uint8_t*)&ipAddress, sizeof(ipAddress));
|
||||
SpiDrv::sendParam(port);
|
||||
SpiDrv::sendParam(&sock, 1);
|
||||
SpiDrv::sendParam(&protMode, 1, LAST_PARAM);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
void ServerDrv::startClient(const char* host, uint8_t host_len, uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_5);
|
||||
SpiDrv::sendParam((uint8_t*)host, host_len);
|
||||
SpiDrv::sendParam((uint8_t*)&ipAddress, sizeof(ipAddress));
|
||||
SpiDrv::sendParam(port);
|
||||
SpiDrv::sendParam(&sock, 1);
|
||||
SpiDrv::sendParam(&protMode, 1, LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
int commandSize = 17 + host_len;
|
||||
while (commandSize % 4) {
|
||||
SpiDrv::readChar();
|
||||
commandSize++;
|
||||
}
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady(/* feed_watchdog = */ (protMode == TLS_BEARSSL_MODE));
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
// Start server TCP on port specified
|
||||
void ServerDrv::stopClient(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(STOP_CLIENT_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, 1, LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(STOP_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
|
||||
uint8_t ServerDrv::getServerState(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_STATE_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_STATE_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint8_t ServerDrv::getClientState(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CLIENT_STATE_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_CLIENT_STATE_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint16_t ServerDrv::availData(uint8_t sock)
|
||||
{
|
||||
if (!SpiDrv::available()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
uint16_t len = 0;
|
||||
|
||||
SpiDrv::waitResponseCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1, (uint8_t*)&len, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
uint8_t ServerDrv::availServer(uint8_t sock)
|
||||
{
|
||||
if (!SpiDrv::available()) {
|
||||
return 255;
|
||||
}
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
uint16_t socket = 0;
|
||||
|
||||
SpiDrv::waitResponseCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1, (uint8_t*)&socket, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return socket;
|
||||
}
|
||||
|
||||
bool ServerDrv::getData(uint8_t sock, uint8_t *data, uint8_t peek)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_DATA_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock));
|
||||
SpiDrv::sendParam(peek, LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseData8(GET_DATA_TCP_CMD, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (_dataLen!=0)
|
||||
{
|
||||
*data = _data;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerDrv::getDataBuf(uint8_t sock, uint8_t *_data, uint16_t *_dataLen)
|
||||
{
|
||||
if (!SpiDrv::available())
|
||||
{
|
||||
*_dataLen = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_DATABUF_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendBuffer(&sock, sizeof(sock));
|
||||
SpiDrv::sendBuffer((uint8_t *)_dataLen, sizeof(*_dataLen), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
if (!SpiDrv::waitResponseData16(GET_DATABUF_TCP_CMD, _data, _dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (*_dataLen!=0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerDrv::insertDataBuf(uint8_t sock, const uint8_t *data, uint16_t _len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(INSERT_DATABUF_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendBuffer(&sock, sizeof(sock));
|
||||
SpiDrv::sendBuffer((uint8_t *)data, _len, LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
int commandSize = 9 + _len;
|
||||
while (commandSize % 4) {
|
||||
SpiDrv::readChar();
|
||||
commandSize++;
|
||||
}
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseData8(INSERT_DATABUF_CMD, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (_dataLen!=0)
|
||||
{
|
||||
return (_data == 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerDrv::sendUdpData(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SEND_DATA_UDP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseData8(SEND_DATA_UDP_CMD, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (_dataLen!=0)
|
||||
{
|
||||
return (_data == 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint16_t ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SEND_DATA_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendBuffer(&sock, sizeof(sock));
|
||||
SpiDrv::sendBuffer((uint8_t *)data, len, LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
int commandSize = 9 + len;
|
||||
while (commandSize % 4) {
|
||||
SpiDrv::readChar();
|
||||
commandSize++;
|
||||
}
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint16_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseData8(SEND_DATA_TCP_CMD, (uint8_t*)&_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
||||
uint8_t ServerDrv::checkDataSent(uint8_t sock)
|
||||
{
|
||||
const uint16_t TIMEOUT_DATA_SENT = 25;
|
||||
uint16_t timeout = 0;
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
|
||||
do {
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
// pad to multiple of 4
|
||||
SpiDrv::readChar();
|
||||
SpiDrv::readChar();
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
if (!SpiDrv::waitResponseCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse isDataSent");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
if (_data) timeout = 0;
|
||||
else{
|
||||
++timeout;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
}while((_data==0)&&(timeout<TIMEOUT_DATA_SENT));
|
||||
return (timeout==TIMEOUT_DATA_SENT)?0:1;
|
||||
}
|
||||
|
||||
uint8_t ServerDrv::getSocket()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_SOCKET_CMD, PARAM_NUMS_0);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = -1;
|
||||
uint8_t _dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_SOCKET_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return _data;
|
||||
}
|
||||
|
||||
ServerDrv serverDrv;
|
||||
69
lib/WiFiNINA/src/utility/server_drv.h
Normal file
69
lib/WiFiNINA/src/utility/server_drv.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
server_drv.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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 Server_Drv_h
|
||||
#define Server_Drv_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "utility/wifi_spi.h"
|
||||
|
||||
typedef enum eProtMode {TCP_MODE, UDP_MODE, TLS_MODE, UDP_MULTICAST_MODE, TLS_BEARSSL_MODE}tProtMode;
|
||||
|
||||
class ServerDrv
|
||||
{
|
||||
public:
|
||||
|
||||
// Start server TCP on port specified
|
||||
static void startServer(uint16_t port, uint8_t sock, uint8_t protMode=TCP_MODE);
|
||||
|
||||
static void startServer(uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode=TCP_MODE);
|
||||
|
||||
static void startClient(uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode=TCP_MODE);
|
||||
|
||||
static void startClient(const char* host, uint8_t host_len, uint32_t ipAddress, uint16_t port, uint8_t sock, uint8_t protMode=TCP_MODE);
|
||||
|
||||
static void stopClient(uint8_t sock);
|
||||
|
||||
static uint8_t getServerState(uint8_t sock);
|
||||
|
||||
static uint8_t getClientState(uint8_t sock);
|
||||
|
||||
static bool getData(uint8_t sock, uint8_t *data, uint8_t peek = 0);
|
||||
|
||||
static bool getDataBuf(uint8_t sock, uint8_t *data, uint16_t *len);
|
||||
|
||||
static bool insertDataBuf(uint8_t sock, const uint8_t *_data, uint16_t _dataLen);
|
||||
|
||||
static uint16_t sendData(uint8_t sock, const uint8_t *data, uint16_t len);
|
||||
|
||||
static bool sendUdpData(uint8_t sock);
|
||||
|
||||
static uint16_t availData(uint8_t sock);
|
||||
|
||||
static uint8_t availServer(uint8_t sock);
|
||||
|
||||
static uint8_t checkDataSent(uint8_t sock);
|
||||
|
||||
static uint8_t getSocket();
|
||||
};
|
||||
|
||||
extern ServerDrv serverDrv;
|
||||
|
||||
#endif
|
||||
605
lib/WiFiNINA/src/utility/spi_drv.cpp
Normal file
605
lib/WiFiNINA/src/utility/spi_drv.cpp
Normal file
@@ -0,0 +1,605 @@
|
||||
/*
|
||||
spi_drv.cpp - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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 <SPI.h>
|
||||
#include "utility/spi_drv.h"
|
||||
#include "pins_arduino.h"
|
||||
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
|
||||
// check if a bitstream is already included
|
||||
#if __has_include(<VidorFPGA.h>)
|
||||
// yes, so use the existing VidorFPGA include
|
||||
#include <VidorFPGA.h>
|
||||
#else
|
||||
// otherwise, fallback to VidorPeripherals and it's bitstream
|
||||
#include <VidorPeripherals.h>
|
||||
#endif
|
||||
|
||||
#define NINA_GPIO0 FPGA_NINA_GPIO0
|
||||
#define SPIWIFI_SS FPGA_SPIWIFI_SS
|
||||
#define SPIWIFI_ACK FPGA_SPIWIFI_ACK
|
||||
#define SPIWIFI_RESET FPGA_SPIWIFI_RESET
|
||||
|
||||
#define pinMode(pin, mode) FPGA.pinMode(pin, mode)
|
||||
#define digitalRead(pin) FPGA.digitalRead(pin)
|
||||
#define digitalWrite(pin, value) FPGA.digitalWrite(pin, value)
|
||||
#endif
|
||||
|
||||
//#define _DEBUG_
|
||||
extern "C" {
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
static uint8_t SLAVESELECT = 10; // ss
|
||||
static uint8_t SLAVEREADY = 7; // handshake pin
|
||||
static uint8_t SLAVERESET = 5; // reset pin
|
||||
|
||||
static bool inverted_reset = false;
|
||||
|
||||
#define DELAY_TRANSFER()
|
||||
|
||||
#ifndef SPIWIFI
|
||||
#define SPIWIFI SPI
|
||||
#endif
|
||||
|
||||
#ifndef NINA_GPIOIRQ
|
||||
#define NINA_GPIOIRQ NINA_GPIO0
|
||||
#endif
|
||||
|
||||
bool SpiDrv::initialized = false;
|
||||
|
||||
__attribute__((weak)) void wifi_nina_feed_watchdog()
|
||||
{
|
||||
/* This function can be overwritten by a "strong" implementation
|
||||
* in a higher level application, such as the ArduinoIoTCloud
|
||||
* firmware stack.
|
||||
*/
|
||||
}
|
||||
|
||||
void SpiDrv::begin()
|
||||
{
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
FPGA.begin();
|
||||
#endif
|
||||
|
||||
#ifdef SPIWIFI_SS
|
||||
SLAVESELECT = SPIWIFI_SS;
|
||||
#endif
|
||||
|
||||
#ifdef SPIWIFI_ACK
|
||||
SLAVEREADY = SPIWIFI_ACK;
|
||||
#endif
|
||||
|
||||
#ifdef SPIWIFI_RESET
|
||||
SLAVERESET = (uint8_t)SPIWIFI_RESET;
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_SAMD_MKRVIDOR4000
|
||||
inverted_reset = false;
|
||||
#else
|
||||
if (SLAVERESET > PINS_COUNT) {
|
||||
inverted_reset = true;
|
||||
SLAVERESET = ~SLAVERESET;
|
||||
}
|
||||
#endif
|
||||
|
||||
pinMode(SLAVESELECT, OUTPUT);
|
||||
pinMode(SLAVEREADY, INPUT);
|
||||
pinMode(SLAVERESET, OUTPUT);
|
||||
pinMode(NINA_GPIO0, OUTPUT);
|
||||
|
||||
digitalWrite(NINA_GPIO0, HIGH);
|
||||
digitalWrite(SLAVESELECT, HIGH);
|
||||
digitalWrite(SLAVERESET, inverted_reset ? HIGH : LOW);
|
||||
delay(10);
|
||||
digitalWrite(SLAVERESET, inverted_reset ? LOW : HIGH);
|
||||
delay(750);
|
||||
|
||||
digitalWrite(NINA_GPIO0, LOW);
|
||||
pinMode(NINA_GPIOIRQ, INPUT);
|
||||
|
||||
SPIWIFI.begin();
|
||||
|
||||
#ifdef _DEBUG_
|
||||
INIT_TRIGGER()
|
||||
#endif
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void SpiDrv::end() {
|
||||
digitalWrite(SLAVERESET, inverted_reset ? HIGH : LOW);
|
||||
|
||||
pinMode(SLAVESELECT, INPUT);
|
||||
|
||||
SPIWIFI.end();
|
||||
|
||||
initialized = false;
|
||||
}
|
||||
|
||||
void SpiDrv::spiSlaveSelect()
|
||||
{
|
||||
SPIWIFI.beginTransaction(SPISettings(8000000, MSBFIRST, SPI_MODE0));
|
||||
digitalWrite(SLAVESELECT,LOW);
|
||||
|
||||
// wait for up to 5 ms for the NINA to indicate it is not ready for transfer
|
||||
// the timeout is only needed for the case when the shield or module is not present
|
||||
for (unsigned long start = millis(); (digitalRead(SLAVEREADY) != HIGH) && (millis() - start) < 5;);
|
||||
}
|
||||
|
||||
|
||||
void SpiDrv::spiSlaveDeselect()
|
||||
{
|
||||
digitalWrite(SLAVESELECT,HIGH);
|
||||
SPIWIFI.endTransaction();
|
||||
}
|
||||
|
||||
|
||||
char SpiDrv::spiTransfer(volatile char data)
|
||||
{
|
||||
char result = SPIWIFI.transfer(data);
|
||||
DELAY_TRANSFER();
|
||||
|
||||
return result; // return the received byte
|
||||
}
|
||||
|
||||
int SpiDrv::waitSpiChar(unsigned char waitChar)
|
||||
{
|
||||
int timeout = TIMEOUT_CHAR;
|
||||
unsigned char _readChar = 0;
|
||||
do{
|
||||
_readChar = readChar(); //get data byte
|
||||
if (_readChar == ERR_CMD)
|
||||
{
|
||||
WARN("Err cmd received\n");
|
||||
return -1;
|
||||
}
|
||||
}while((timeout-- > 0) && (_readChar != waitChar));
|
||||
return (_readChar == waitChar);
|
||||
}
|
||||
|
||||
int SpiDrv::readAndCheckChar(char checkChar, char* readChar)
|
||||
{
|
||||
getParam((uint8_t*)readChar);
|
||||
|
||||
return (*readChar == checkChar);
|
||||
}
|
||||
|
||||
char SpiDrv::readChar()
|
||||
{
|
||||
uint8_t readChar = 0;
|
||||
getParam(&readChar);
|
||||
return readChar;
|
||||
}
|
||||
|
||||
#define WAIT_START_CMD(x) waitSpiChar(START_CMD)
|
||||
|
||||
#define IF_CHECK_START_CMD(x) \
|
||||
if (!WAIT_START_CMD(_data)) \
|
||||
{ \
|
||||
TOGGLE_TRIGGER() \
|
||||
WARN("Error waiting START_CMD"); \
|
||||
return 0; \
|
||||
}else \
|
||||
|
||||
#define CHECK_DATA(check, x) \
|
||||
if (!readAndCheckChar(check, &x)) \
|
||||
{ \
|
||||
TOGGLE_TRIGGER() \
|
||||
WARN("Reply error"); \
|
||||
INFO2(check, (uint8_t)x); \
|
||||
return 0; \
|
||||
}else \
|
||||
|
||||
#define waitSlaveReady() (digitalRead(SLAVEREADY) == LOW)
|
||||
#define waitSlaveSign() (digitalRead(SLAVEREADY) == HIGH)
|
||||
#define waitSlaveSignalH() while(digitalRead(SLAVEREADY) != HIGH){}
|
||||
#define waitSlaveSignalL() while(digitalRead(SLAVEREADY) != LOW){}
|
||||
|
||||
void SpiDrv::waitForSlaveSign()
|
||||
{
|
||||
while (!waitSlaveSign());
|
||||
}
|
||||
|
||||
void SpiDrv::waitForSlaveReady(bool const feed_watchdog)
|
||||
{
|
||||
unsigned long const start = millis();
|
||||
while (!waitSlaveReady())
|
||||
{
|
||||
if (feed_watchdog) {
|
||||
if ((millis() - start) < 10000) {
|
||||
wifi_nina_feed_watchdog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SpiDrv::getParam(uint8_t* param)
|
||||
{
|
||||
// Get Params data
|
||||
*param = spiTransfer(DUMMY_DATA);
|
||||
DELAY_TRANSFER();
|
||||
}
|
||||
|
||||
int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len)
|
||||
{
|
||||
char _data = 0;
|
||||
int ii = 0;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
CHECK_DATA(numParam, _data)
|
||||
{
|
||||
readParamLen8(param_len);
|
||||
for (ii=0; ii<(*param_len); ++ii)
|
||||
{
|
||||
// Get Params data
|
||||
//param[ii] = spiTransfer(DUMMY_DATA);
|
||||
getParam(¶m[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*
|
||||
int SpiDrv::waitResponse(uint8_t cmd, uint8_t numParam, uint8_t* param, uint16_t* param_len)
|
||||
{
|
||||
char _data = 0;
|
||||
int i =0, ii = 0;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
CHECK_DATA(numParam, _data);
|
||||
{
|
||||
readParamLen16(param_len);
|
||||
for (ii=0; ii<(*param_len); ++ii)
|
||||
{
|
||||
// Get Params data
|
||||
param[ii] = spiTransfer(DUMMY_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
int SpiDrv::waitResponseData16(uint8_t cmd, uint8_t* param, uint16_t* param_len)
|
||||
{
|
||||
char _data = 0;
|
||||
uint16_t ii = 0;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
uint8_t numParam = readChar();
|
||||
if (numParam != 0)
|
||||
{
|
||||
readParamLen16(param_len);
|
||||
for (ii=0; ii<(*param_len); ++ii)
|
||||
{
|
||||
// Get Params data
|
||||
param[ii] = spiTransfer(DUMMY_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SpiDrv::waitResponseData8(uint8_t cmd, uint8_t* param, uint8_t* param_len)
|
||||
{
|
||||
char _data = 0;
|
||||
int ii = 0;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
uint8_t numParam = readChar();
|
||||
if (numParam != 0)
|
||||
{
|
||||
readParamLen8(param_len);
|
||||
for (ii=0; ii<(*param_len); ++ii)
|
||||
{
|
||||
// Get Params data
|
||||
param[ii] = spiTransfer(DUMMY_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int SpiDrv::waitResponseParams(uint8_t cmd, uint8_t numParam, tParam* params)
|
||||
{
|
||||
char _data = 0;
|
||||
int i =0, ii = 0;
|
||||
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
uint8_t _numParam = readChar();
|
||||
if (_numParam != 0)
|
||||
{
|
||||
for (i=0; i<_numParam; ++i)
|
||||
{
|
||||
params[i].paramLen = readParamLen8();
|
||||
for (ii=0; ii<params[i].paramLen; ++ii)
|
||||
{
|
||||
// Get Params data
|
||||
params[i].param[ii] = spiTransfer(DUMMY_DATA);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
WARN("Error numParam == 0");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (numParam != _numParam)
|
||||
{
|
||||
WARN("Mismatch numParam");
|
||||
return 0;
|
||||
}
|
||||
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int SpiDrv::waitResponse(uint8_t cmd, tParam* params, uint8_t* numParamRead, uint8_t maxNumParams)
|
||||
{
|
||||
char _data = 0;
|
||||
int i =0, ii = 0;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
uint8_t numParam = readChar();
|
||||
|
||||
if (numParam > maxNumParams)
|
||||
{
|
||||
numParam = maxNumParams;
|
||||
}
|
||||
*numParamRead = numParam;
|
||||
if (numParam != 0)
|
||||
{
|
||||
for (i=0; i<numParam; ++i)
|
||||
{
|
||||
params[i].paramLen = readParamLen8();
|
||||
|
||||
for (ii=0; ii<params[i].paramLen; ++ii)
|
||||
{
|
||||
// Get Params data
|
||||
params[i].param[ii] = spiTransfer(DUMMY_DATA);
|
||||
}
|
||||
}
|
||||
} else
|
||||
{
|
||||
WARN("Error numParams == 0");
|
||||
Serial.println(cmd, 16);
|
||||
return 0;
|
||||
}
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
*/
|
||||
|
||||
int SpiDrv::waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, uint8_t maxNumParams)
|
||||
{
|
||||
char _data = 0;
|
||||
int i =0, ii = 0;
|
||||
|
||||
char *index[WL_SSID_MAX_LENGTH];
|
||||
|
||||
for (i = 0 ; i < WL_NETWORKS_LIST_MAXNUM ; i++)
|
||||
index[i] = (char *)params + WL_SSID_MAX_LENGTH*i;
|
||||
|
||||
IF_CHECK_START_CMD(_data)
|
||||
{
|
||||
CHECK_DATA(cmd | REPLY_FLAG, _data){};
|
||||
|
||||
uint8_t numParam = readChar();
|
||||
|
||||
if (numParam > maxNumParams)
|
||||
{
|
||||
numParam = maxNumParams;
|
||||
}
|
||||
*numParamRead = numParam;
|
||||
if (numParam != 0)
|
||||
{
|
||||
for (i=0; i<numParam; ++i)
|
||||
{
|
||||
uint8_t paramLen = readParamLen8();
|
||||
for (ii=0; ii<paramLen; ++ii)
|
||||
{
|
||||
//ssid[ii] = spiTransfer(DUMMY_DATA);
|
||||
// Get Params data
|
||||
index[i][ii] = (uint8_t)spiTransfer(DUMMY_DATA);
|
||||
|
||||
}
|
||||
index[i][ii]=0;
|
||||
}
|
||||
} else
|
||||
{
|
||||
WARN("Error numParams == 0");
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
return 0;
|
||||
}
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void SpiDrv::sendParamNoLen(uint8_t* param, size_t param_len, uint8_t lastParam)
|
||||
{
|
||||
size_t i = 0;
|
||||
// Send Spi paramLen
|
||||
sendParamLen8(0);
|
||||
|
||||
// Send Spi param data
|
||||
for (i=0; i<param_len; ++i)
|
||||
{
|
||||
spiTransfer(param[i]);
|
||||
}
|
||||
|
||||
// if lastParam==1 Send Spi END CMD
|
||||
if (lastParam == 1)
|
||||
spiTransfer(END_CMD);
|
||||
}
|
||||
|
||||
void SpiDrv::sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam)
|
||||
{
|
||||
int i = 0;
|
||||
// Send Spi paramLen
|
||||
sendParamLen8(param_len);
|
||||
|
||||
// Send Spi param data
|
||||
for (i=0; i<param_len; ++i)
|
||||
{
|
||||
spiTransfer(param[i]);
|
||||
}
|
||||
|
||||
// if lastParam==1 Send Spi END CMD
|
||||
if (lastParam == 1)
|
||||
spiTransfer(END_CMD);
|
||||
}
|
||||
|
||||
void SpiDrv::sendParamLen8(uint8_t param_len)
|
||||
{
|
||||
// Send Spi paramLen
|
||||
spiTransfer(param_len);
|
||||
}
|
||||
|
||||
void SpiDrv::sendParamLen16(uint16_t param_len)
|
||||
{
|
||||
// Send Spi paramLen
|
||||
spiTransfer((uint8_t)((param_len & 0xff00)>>8));
|
||||
spiTransfer((uint8_t)(param_len & 0xff));
|
||||
}
|
||||
|
||||
uint8_t SpiDrv::readParamLen8(uint8_t* param_len)
|
||||
{
|
||||
uint8_t _param_len = spiTransfer(DUMMY_DATA);
|
||||
if (param_len != NULL)
|
||||
{
|
||||
*param_len = _param_len;
|
||||
}
|
||||
return _param_len;
|
||||
}
|
||||
|
||||
uint16_t SpiDrv::readParamLen16(uint16_t* param_len)
|
||||
{
|
||||
uint16_t _param_len = spiTransfer(DUMMY_DATA)<<8 | (spiTransfer(DUMMY_DATA)& 0xff);
|
||||
if (param_len != NULL)
|
||||
{
|
||||
*param_len = _param_len;
|
||||
}
|
||||
return _param_len;
|
||||
}
|
||||
|
||||
|
||||
void SpiDrv::sendBuffer(uint8_t* param, uint16_t param_len, uint8_t lastParam)
|
||||
{
|
||||
uint16_t i = 0;
|
||||
|
||||
// Send Spi paramLen
|
||||
sendParamLen16(param_len);
|
||||
|
||||
// Send Spi param data
|
||||
for (i=0; i<param_len; ++i)
|
||||
{
|
||||
spiTransfer(param[i]);
|
||||
}
|
||||
|
||||
// if lastParam==1 Send Spi END CMD
|
||||
if (lastParam == 1)
|
||||
spiTransfer(END_CMD);
|
||||
}
|
||||
|
||||
|
||||
void SpiDrv::sendParam(uint16_t param, uint8_t lastParam)
|
||||
{
|
||||
// Send Spi paramLen
|
||||
sendParamLen8(2);
|
||||
|
||||
spiTransfer((uint8_t)((param & 0xff00)>>8));
|
||||
spiTransfer((uint8_t)(param & 0xff));
|
||||
|
||||
// if lastParam==1 Send Spi END CMD
|
||||
if (lastParam == 1)
|
||||
spiTransfer(END_CMD);
|
||||
}
|
||||
|
||||
/* Cmd Struct Message */
|
||||
/* _________________________________________________________________________________ */
|
||||
/*| START CMD | C/R | CMD |[TOT LEN]| N.PARAM | PARAM LEN | PARAM | .. | END CMD | */
|
||||
/*|___________|______|______|_________|_________|___________|________|____|_________| */
|
||||
/*| 8 bit | 1bit | 7bit | 8bit | 8bit | 8bit | nbytes | .. | 8bit | */
|
||||
/*|___________|______|______|_________|_________|___________|________|____|_________| */
|
||||
|
||||
void SpiDrv::sendCmd(uint8_t cmd, uint8_t numParam)
|
||||
{
|
||||
// Send Spi START CMD
|
||||
spiTransfer(START_CMD);
|
||||
|
||||
// Send Spi C + cmd
|
||||
spiTransfer(cmd & ~(REPLY_FLAG));
|
||||
|
||||
// Send Spi totLen
|
||||
//spiTransfer(totLen);
|
||||
|
||||
// Send Spi numParam
|
||||
spiTransfer(numParam);
|
||||
|
||||
// If numParam == 0 send END CMD
|
||||
if (numParam == 0)
|
||||
spiTransfer(END_CMD);
|
||||
|
||||
}
|
||||
|
||||
int SpiDrv::available()
|
||||
{
|
||||
return (digitalRead(NINA_GPIOIRQ) != LOW);
|
||||
}
|
||||
|
||||
SpiDrv spiDrv;
|
||||
109
lib/WiFiNINA/src/utility/spi_drv.h
Normal file
109
lib/WiFiNINA/src/utility/spi_drv.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
spi_drv.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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 SPI_Drv_h
|
||||
#define SPI_Drv_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "utility/wifi_spi.h"
|
||||
|
||||
#define SPI_START_CMD_DELAY 10
|
||||
|
||||
#define NO_LAST_PARAM 0
|
||||
#define LAST_PARAM 1
|
||||
|
||||
#define DUMMY_DATA 0xFF
|
||||
|
||||
#define WAIT_FOR_SLAVE_SELECT() \
|
||||
if (!SpiDrv::initialized) { \
|
||||
SpiDrv::begin(); \
|
||||
} \
|
||||
SpiDrv::waitForSlaveReady(); \
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
class SpiDrv
|
||||
{
|
||||
private:
|
||||
//static bool waitSlaveReady();
|
||||
static void waitForSlaveSign();
|
||||
static void getParam(uint8_t* param);
|
||||
public:
|
||||
static bool initialized;
|
||||
|
||||
static void begin();
|
||||
|
||||
static void end();
|
||||
|
||||
static void spiDriverInit();
|
||||
|
||||
static void spiSlaveSelect();
|
||||
|
||||
static void spiSlaveDeselect();
|
||||
|
||||
static char spiTransfer(volatile char data);
|
||||
|
||||
static void waitForSlaveReady(bool const feed_watchdog = false);
|
||||
|
||||
//static int waitSpiChar(char waitChar, char* readChar);
|
||||
|
||||
static int waitSpiChar(unsigned char waitChar);
|
||||
|
||||
static int readAndCheckChar(char checkChar, char* readChar);
|
||||
|
||||
static char readChar();
|
||||
|
||||
static int waitResponseParams(uint8_t cmd, uint8_t numParam, tParam* params);
|
||||
|
||||
static int waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len);
|
||||
|
||||
static int waitResponseData8(uint8_t cmd, uint8_t* param, uint8_t* param_len);
|
||||
|
||||
static int waitResponseData16(uint8_t cmd, uint8_t* param, uint16_t* param_len);
|
||||
/*
|
||||
static int waitResponse(uint8_t cmd, tParam* params, uint8_t* numParamRead, uint8_t maxNumParams);
|
||||
|
||||
static int waitResponse(uint8_t cmd, uint8_t numParam, uint8_t* param, uint16_t* param_len);
|
||||
*/
|
||||
static int waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, uint8_t maxNumParams);
|
||||
|
||||
static void sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendParamNoLen(uint8_t* param, size_t param_len, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendParamLen8(uint8_t param_len);
|
||||
|
||||
static void sendParamLen16(uint16_t param_len);
|
||||
|
||||
static uint8_t readParamLen8(uint8_t* param_len = NULL);
|
||||
|
||||
static uint16_t readParamLen16(uint16_t* param_len = NULL);
|
||||
|
||||
static void sendBuffer(uint8_t* param, uint16_t param_len, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendParam(uint16_t param, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendCmd(uint8_t cmd, uint8_t numParam);
|
||||
|
||||
static int available();
|
||||
};
|
||||
|
||||
extern SpiDrv spiDrv;
|
||||
|
||||
#endif
|
||||
1262
lib/WiFiNINA/src/utility/wifi_drv.cpp
Normal file
1262
lib/WiFiNINA/src/utility/wifi_drv.cpp
Normal file
File diff suppressed because it is too large
Load Diff
326
lib/WiFiNINA/src/utility/wifi_drv.h
Normal file
326
lib/WiFiNINA/src/utility/wifi_drv.h
Normal file
@@ -0,0 +1,326 @@
|
||||
/*
|
||||
wifi_drv.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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 WiFi_Drv_h
|
||||
#define WiFi_Drv_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "utility/wifi_spi.h"
|
||||
#include "IPAddress.h"
|
||||
#include "WiFiUdp.h"
|
||||
#include "WiFiClient.h"
|
||||
|
||||
// Key index length
|
||||
#define KEY_IDX_LEN 1
|
||||
// 100 msecs of delay to have the connection established
|
||||
#define WL_DELAY_START_CONNECTION 100
|
||||
// firmware version string length
|
||||
#define WL_FW_VER_LENGTH 6
|
||||
|
||||
class WiFiDrv
|
||||
{
|
||||
private:
|
||||
// settings of requested network
|
||||
static char _networkSsid[WL_NETWORKS_LIST_MAXNUM][WL_SSID_MAX_LENGTH];
|
||||
|
||||
// firmware version string in the format a.b.c
|
||||
static char fwVersion[WL_FW_VER_LENGTH];
|
||||
|
||||
// settings of current selected network
|
||||
static char _ssid[WL_SSID_MAX_LENGTH];
|
||||
static uint8_t _bssid[WL_MAC_ADDR_LENGTH];
|
||||
static uint8_t _mac[WL_MAC_ADDR_LENGTH];
|
||||
static uint8_t _localIp[WL_IPV4_LENGTH];
|
||||
static uint8_t _subnetMask[WL_IPV4_LENGTH];
|
||||
static uint8_t _gatewayIp[WL_IPV4_LENGTH];
|
||||
|
||||
/*
|
||||
* Get network Data information
|
||||
*/
|
||||
static void getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip);
|
||||
|
||||
static uint8_t reqHostByName(const char* aHostname);
|
||||
|
||||
static int getHostByName(IPAddress& aResult);
|
||||
|
||||
/*
|
||||
* Get remote Data information on UDP socket
|
||||
*/
|
||||
static void getRemoteData(uint8_t sock, uint8_t *ip, uint8_t *port);
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
* Driver initialization
|
||||
*/
|
||||
static void wifiDriverInit();
|
||||
|
||||
static void wifiDriverDeinit();
|
||||
|
||||
/*
|
||||
* Set the desired network which the connection manager should try to
|
||||
* connect to.
|
||||
*
|
||||
* The ssid of the desired network should be specified.
|
||||
*
|
||||
* param ssid: The ssid of the desired network.
|
||||
* param ssid_len: Length of ssid string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t wifiSetNetwork(const char* ssid, uint8_t ssid_len);
|
||||
|
||||
/* Start WiFi connection with passphrase
|
||||
* the most secure supported mode will be automatically selected
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param ssid_len: Length of ssid string.
|
||||
* param passphrase: Passphrase. Valid characters in a passphrase
|
||||
* must be between ASCII 32-126 (decimal).
|
||||
* param len: Length of passphrase string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t wifiSetPassphrase(const char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len);
|
||||
|
||||
/* Start WiFi connection with WEP encryption.
|
||||
* Configure a key into the device. The key type (WEP-40, WEP-104)
|
||||
* is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104).
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param ssid_len: Length of ssid string.
|
||||
* param key_idx: The key index to set. Valid values are 0-3.
|
||||
* param key: Key input buffer.
|
||||
* param len: Length of key string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t wifiSetKey(const char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
|
||||
|
||||
static int8_t wifiSetApNetwork(const char* ssid, uint8_t ssid_len);
|
||||
static int8_t wifiSetApPassphrase(const char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len);
|
||||
|
||||
/* Set ip configuration disabling dhcp client
|
||||
*
|
||||
* param validParams: set the number of parameters that we want to change
|
||||
* i.e. validParams = 1 means that we'll change only ip address
|
||||
* validParams = 3 means that we'll change ip address, gateway and netmask
|
||||
* param local_ip: Static ip configuration
|
||||
* param gateway: Static gateway configuration
|
||||
* param subnet: Static subnet mask configuration
|
||||
*/
|
||||
static void config(uint8_t validParams, uint32_t local_ip, uint32_t gateway, uint32_t subnet);
|
||||
|
||||
/* Set DNS ip configuration
|
||||
*
|
||||
* param validParams: set the number of parameters that we want to change
|
||||
* i.e. validParams = 1 means that we'll change only dns_server1
|
||||
* validParams = 2 means that we'll change dns_server1 and dns_server2
|
||||
* param dns_server1: Static DNS server1 configuration
|
||||
* param dns_server2: Static DNS server2 configuration
|
||||
*/
|
||||
static void setDNS(uint8_t validParams, uint32_t dns_server1, uint32_t dns_server2);
|
||||
|
||||
static void setHostname(const char* hostname);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t disconnect();
|
||||
|
||||
static uint8_t getReasonCode();
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: one value of wl_status_t enum
|
||||
*/
|
||||
static uint8_t getConnectionStatus();
|
||||
|
||||
/*
|
||||
* Get the interface MAC address.
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
static uint8_t* getMacAddress();
|
||||
|
||||
/*
|
||||
* Get the interface IP address.
|
||||
*
|
||||
* return: copy the ip address value in IPAddress object
|
||||
*/
|
||||
static void getIpAddress(IPAddress& ip);
|
||||
|
||||
/*
|
||||
* Get the interface subnet mask address.
|
||||
*
|
||||
* return: copy the subnet mask address value in IPAddress object
|
||||
*/
|
||||
static void getSubnetMask(IPAddress& mask);
|
||||
|
||||
/*
|
||||
* Get the gateway ip address.
|
||||
*
|
||||
* return: copy the gateway ip address value in IPAddress object
|
||||
*/
|
||||
static void getGatewayIP(IPAddress& ip);
|
||||
|
||||
/*
|
||||
* Return the current SSID associated with the network
|
||||
*
|
||||
* return: ssid string
|
||||
*/
|
||||
static const char* getCurrentSSID();
|
||||
|
||||
/*
|
||||
* Return the current BSSID associated with the network.
|
||||
* It is the MAC address of the Access Point
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
static uint8_t* getCurrentBSSID();
|
||||
|
||||
/*
|
||||
* Return the current RSSI /Received Signal Strength in dBm)
|
||||
* associated with the network
|
||||
*
|
||||
* return: signed value
|
||||
*/
|
||||
static int32_t getCurrentRSSI();
|
||||
|
||||
/*
|
||||
* Return the Encryption Type associated with the network
|
||||
*
|
||||
* return: one value of wl_enc_type enum
|
||||
*/
|
||||
static uint8_t getCurrentEncryptionType();
|
||||
|
||||
/*
|
||||
* Start scan WiFi networks available
|
||||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
static int8_t startScanNetworks();
|
||||
|
||||
/*
|
||||
* Get the networks available
|
||||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
static uint8_t getScanNetworks();
|
||||
|
||||
/*
|
||||
* Return the SSID discovered during the network scan.
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: ssid string of the specified item on the networks scanned list
|
||||
*/
|
||||
static const char* getSSIDNetoworks(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the RSSI of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: signed value of RSSI of the specified item on the networks scanned list
|
||||
*/
|
||||
static int32_t getRSSINetoworks(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the encryption type of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
|
||||
*/
|
||||
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
|
||||
|
||||
static uint8_t* getBSSIDNetowrks(uint8_t networkItem, uint8_t* bssid);
|
||||
|
||||
static uint8_t getChannelNetowrks(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Resolve the given hostname to an IP address.
|
||||
* param aHostname: Name to be resolved
|
||||
* param aResult: IPAddress structure to store the returned IP address
|
||||
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||
* else error code
|
||||
*/
|
||||
static int getHostByName(const char* aHostname, IPAddress& aResult);
|
||||
|
||||
/*
|
||||
* Get the firmware version
|
||||
* result: version as string with this format a.b.c
|
||||
*/
|
||||
static const char* getFwVersion();
|
||||
|
||||
static uint32_t getTime();
|
||||
|
||||
static void setPowerMode(uint8_t mode);
|
||||
|
||||
static int8_t wifiSetApNetwork(const char* ssid, uint8_t ssid_len, uint8_t channel);
|
||||
static int8_t wifiSetApPassphrase(const char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len, uint8_t channel);
|
||||
static int8_t wifiSetEnterprise(uint8_t eapType,
|
||||
const char* ssid, uint8_t ssid_len,
|
||||
const char *username, const uint8_t username_len,
|
||||
const char *password, const uint8_t password_len,
|
||||
const char *identity, const uint8_t identity_len,
|
||||
const char* ca_cert, uint16_t ca_cert_len);
|
||||
|
||||
|
||||
static int16_t ping(uint32_t ipAddress, uint8_t ttl);
|
||||
|
||||
static void debug(uint8_t on);
|
||||
static float getTemperature();
|
||||
static void pinMode(uint8_t pin, uint8_t mode);
|
||||
static void digitalWrite(uint8_t pin, uint8_t value);
|
||||
static void analogWrite(uint8_t pin, uint8_t value);
|
||||
|
||||
static int8_t downloadFile(const char* url, uint8_t url_len, const char *filename, uint8_t filename_len);
|
||||
static int8_t downloadOTA(const char* url, uint8_t url_len);
|
||||
static int8_t renameFile(const char * old_file_name, uint8_t const old_file_name_len, const char * new_file_name, uint8_t const new_file_name_len);
|
||||
|
||||
static int8_t fileOperation(uint8_t operation, const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t len);
|
||||
|
||||
static int8_t readFile(const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
|
||||
return fileOperation(READ_FILE, filename, filename_len, offset, buffer, buffer_len);
|
||||
};
|
||||
static int8_t writeFile(const char *filename, uint8_t filename_len, uint32_t offset, uint8_t* buffer, uint32_t buffer_len) {
|
||||
return fileOperation(WRITE_FILE, filename, filename_len, offset, buffer, buffer_len);
|
||||
};
|
||||
static int8_t deleteFile(const char *filename, uint8_t filename_len) {
|
||||
return fileOperation(DELETE_FILE, filename, filename_len, 0, NULL, 0);
|
||||
};
|
||||
static int8_t existsFile(const char *filename, uint8_t filename_len, uint32_t* len) {
|
||||
int32_t length = 0;
|
||||
fileOperation(EXISTS_FILE, filename, filename_len, 0, (uint8_t*)&length, sizeof(length));
|
||||
*len = length;
|
||||
return length >= 0;
|
||||
};
|
||||
|
||||
static void applyOTA();
|
||||
|
||||
friend class WiFiUDP;
|
||||
friend class WiFiClient;
|
||||
};
|
||||
|
||||
extern WiFiDrv wiFiDrv;
|
||||
|
||||
#endif
|
||||
203
lib/WiFiNINA/src/utility/wifi_spi.h
Normal file
203
lib/WiFiNINA/src/utility/wifi_spi.h
Normal file
@@ -0,0 +1,203 @@
|
||||
/*
|
||||
wifi_spi.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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 WiFi_Spi_h
|
||||
#define WiFi_Spi_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "utility/wl_definitions.h"
|
||||
|
||||
#define CMD_FLAG 0
|
||||
#define REPLY_FLAG 1<<7
|
||||
#define DATA_FLAG 0x40
|
||||
|
||||
#define WIFI_SPI_ACK 1
|
||||
#define WIFI_SPI_ERR 0xFF
|
||||
|
||||
#define TIMEOUT_CHAR 1000
|
||||
|
||||
//#define MAX_SOCK_NUM 4 /**< Maxmium number of socket */
|
||||
#define NO_SOCKET_AVAIL 255
|
||||
|
||||
#define START_CMD 0xE0
|
||||
#define END_CMD 0xEE
|
||||
#define ERR_CMD 0xEF
|
||||
#define CMD_POS 1 // Position of Command OpCode on SPI stream
|
||||
#define PARAM_LEN_POS 2 // Position of Param len on SPI stream
|
||||
|
||||
|
||||
enum {
|
||||
SET_NET_CMD = 0x10,
|
||||
SET_PASSPHRASE_CMD = 0x11,
|
||||
SET_KEY_CMD = 0x12,
|
||||
// TEST_CMD = 0x13,
|
||||
SET_IP_CONFIG_CMD = 0x14,
|
||||
SET_DNS_CONFIG_CMD = 0x15,
|
||||
SET_HOSTNAME_CMD = 0x16,
|
||||
SET_POWER_MODE_CMD = 0x17,
|
||||
SET_AP_NET_CMD = 0x18,
|
||||
SET_AP_PASSPHRASE_CMD = 0x19,
|
||||
SET_DEBUG_CMD = 0x1A,
|
||||
GET_TEMPERATURE_CMD = 0x1B,
|
||||
GET_REASON_CODE_CMD = 0x1F,
|
||||
|
||||
GET_CONN_STATUS_CMD = 0x20,
|
||||
GET_IPADDR_CMD = 0x21,
|
||||
GET_MACADDR_CMD = 0x22,
|
||||
GET_CURR_SSID_CMD = 0x23,
|
||||
GET_CURR_BSSID_CMD = 0x24,
|
||||
GET_CURR_RSSI_CMD = 0x25,
|
||||
GET_CURR_ENCT_CMD = 0x26,
|
||||
SCAN_NETWORKS = 0x27,
|
||||
START_SERVER_TCP_CMD= 0x28,
|
||||
GET_STATE_TCP_CMD = 0x29,
|
||||
DATA_SENT_TCP_CMD = 0x2A,
|
||||
AVAIL_DATA_TCP_CMD = 0x2B,
|
||||
GET_DATA_TCP_CMD = 0x2C,
|
||||
START_CLIENT_TCP_CMD= 0x2D,
|
||||
STOP_CLIENT_TCP_CMD = 0x2E,
|
||||
GET_CLIENT_STATE_TCP_CMD= 0x2F,
|
||||
DISCONNECT_CMD = 0x30,
|
||||
// GET_IDX_SSID_CMD = 0x31,
|
||||
GET_IDX_RSSI_CMD = 0x32,
|
||||
GET_IDX_ENCT_CMD = 0x33,
|
||||
REQ_HOST_BY_NAME_CMD= 0x34,
|
||||
GET_HOST_BY_NAME_CMD= 0x35,
|
||||
START_SCAN_NETWORKS = 0x36,
|
||||
GET_FW_VERSION_CMD = 0x37,
|
||||
// GET_TEST_CMD = 0x38,
|
||||
SEND_DATA_UDP_CMD = 0x39,
|
||||
GET_REMOTE_DATA_CMD = 0x3A,
|
||||
GET_TIME_CMD = 0x3B,
|
||||
GET_IDX_BSSID = 0x3C,
|
||||
GET_IDX_CHANNEL_CMD = 0x3D,
|
||||
PING_CMD = 0x3E,
|
||||
GET_SOCKET_CMD = 0x3F,
|
||||
|
||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||
SET_ENT_CMD = 0x40,
|
||||
|
||||
SEND_DATA_TCP_CMD = 0x44,
|
||||
GET_DATABUF_TCP_CMD = 0x45,
|
||||
INSERT_DATABUF_CMD = 0x46,
|
||||
|
||||
// regular format commands
|
||||
SET_PIN_MODE = 0x50,
|
||||
SET_DIGITAL_WRITE = 0x51,
|
||||
SET_ANALOG_WRITE = 0x52,
|
||||
|
||||
// regular format commands
|
||||
WRITE_FILE = 0x60,
|
||||
READ_FILE = 0x61,
|
||||
DELETE_FILE = 0x62,
|
||||
EXISTS_FILE = 0x63,
|
||||
DOWNLOAD_FILE = 0x64,
|
||||
APPLY_OTA_COMMAND = 0x65,
|
||||
RENAME_FILE = 0x66,
|
||||
DOWNLOAD_OTA = 0x67,
|
||||
};
|
||||
|
||||
|
||||
enum wl_tcp_state {
|
||||
CLOSED = 0,
|
||||
LISTEN = 1,
|
||||
SYN_SENT = 2,
|
||||
SYN_RCVD = 3,
|
||||
ESTABLISHED = 4,
|
||||
FIN_WAIT_1 = 5,
|
||||
FIN_WAIT_2 = 6,
|
||||
CLOSE_WAIT = 7,
|
||||
CLOSING = 8,
|
||||
LAST_ACK = 9,
|
||||
TIME_WAIT = 10
|
||||
};
|
||||
|
||||
|
||||
enum numParams{
|
||||
PARAM_NUMS_0,
|
||||
PARAM_NUMS_1,
|
||||
PARAM_NUMS_2,
|
||||
PARAM_NUMS_3,
|
||||
PARAM_NUMS_4,
|
||||
PARAM_NUMS_5,
|
||||
PARAM_NUMS_6,
|
||||
MAX_PARAM_NUMS
|
||||
};
|
||||
|
||||
#define MAX_PARAMS MAX_PARAM_NUMS-1
|
||||
#define PARAM_LEN_SIZE 1
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
char* param;
|
||||
}tParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint16_t dataLen;
|
||||
char* data;
|
||||
}tDataParam;
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char nParam;
|
||||
tParam params[MAX_PARAMS];
|
||||
}tSpiMsg;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char nParam;
|
||||
tDataParam params[MAX_PARAMS];
|
||||
}tSpiMsgData;
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
//unsigned char totLen;
|
||||
unsigned char nParam;
|
||||
}tSpiHdr;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint32_t param;
|
||||
}tLongParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint16_t param;
|
||||
}tIntParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint8_t param;
|
||||
}tByteParam;
|
||||
|
||||
#endif
|
||||
77
lib/WiFiNINA/src/utility/wl_definitions.h
Normal file
77
lib/WiFiNINA/src/utility/wl_definitions.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
wl_definitions.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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
|
||||
*/
|
||||
/*
|
||||
* wl_definitions.h
|
||||
*
|
||||
* Created on: Mar 6, 2011
|
||||
* Author: dlafauci
|
||||
*/
|
||||
|
||||
#ifndef WL_DEFINITIONS_H_
|
||||
#define WL_DEFINITIONS_H_
|
||||
|
||||
// Maximum size of a SSID
|
||||
#define WL_SSID_MAX_LENGTH 32
|
||||
// Length of passphrase. Valid lengths are 8-63.
|
||||
#define WL_WPA_KEY_MAX_LENGTH 63
|
||||
// Length of key in bytes. Valid values are 5 and 13.
|
||||
#define WL_WEP_KEY_MAX_LENGTH 13
|
||||
// Size of a MAC-address or BSSID
|
||||
#define WL_MAC_ADDR_LENGTH 6
|
||||
// Size of a MAC-address or BSSID
|
||||
#define WL_IPV4_LENGTH 4
|
||||
// Maximum size of a SSID list
|
||||
#define WL_NETWORKS_LIST_MAXNUM 10
|
||||
// Maxmium number of socket
|
||||
#define WIFI_MAX_SOCK_NUM 10
|
||||
// Socket not available constant
|
||||
#define SOCK_NOT_AVAIL 255
|
||||
// Default state value for WiFi state field
|
||||
#define NA_STATE -1
|
||||
|
||||
typedef enum {
|
||||
WL_NO_SHIELD = 255,
|
||||
WL_NO_MODULE = WL_NO_SHIELD,
|
||||
WL_IDLE_STATUS = 0,
|
||||
WL_NO_SSID_AVAIL,
|
||||
WL_SCAN_COMPLETED,
|
||||
WL_CONNECTED,
|
||||
WL_CONNECT_FAILED,
|
||||
WL_CONNECTION_LOST,
|
||||
WL_DISCONNECTED,
|
||||
WL_AP_LISTENING,
|
||||
WL_AP_CONNECTED,
|
||||
WL_AP_FAILED
|
||||
} wl_status_t;
|
||||
|
||||
/* Encryption modes */
|
||||
enum wl_enc_type { /* Values map to 802.11 encryption suites... */
|
||||
ENC_TYPE_WEP = 5,
|
||||
ENC_TYPE_TKIP = 2,
|
||||
ENC_TYPE_CCMP = 4,
|
||||
/* ... except these two, 7 and 8 are reserved in 802.11-2007 */
|
||||
ENC_TYPE_NONE = 7,
|
||||
ENC_TYPE_AUTO = 8,
|
||||
|
||||
ENC_TYPE_UNKNOWN = 255
|
||||
};
|
||||
|
||||
|
||||
#endif /* WL_DEFINITIONS_H_ */
|
||||
57
lib/WiFiNINA/src/utility/wl_types.h
Normal file
57
lib/WiFiNINA/src/utility/wl_types.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
wl_types.h - Library for Arduino Wifi shield.
|
||||
Copyright (c) 2018 Arduino SA. All rights reserved.
|
||||
Copyright (c) 2011-2014 Arduino. 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
|
||||
*/
|
||||
/*
|
||||
* wl_types.h
|
||||
*
|
||||
* Created on: Jul 30, 2010
|
||||
* Author: dlafauci
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _WL_TYPES_H_
|
||||
#define _WL_TYPES_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef enum {
|
||||
WL_FAILURE = -1,
|
||||
WL_SUCCESS = 1,
|
||||
} wl_error_code_t;
|
||||
|
||||
/* Authentication modes */
|
||||
enum wl_auth_mode {
|
||||
AUTH_MODE_INVALID,
|
||||
AUTH_MODE_AUTO,
|
||||
AUTH_MODE_OPEN_SYSTEM,
|
||||
AUTH_MODE_SHARED_KEY,
|
||||
AUTH_MODE_WPA,
|
||||
AUTH_MODE_WPA2,
|
||||
AUTH_MODE_WPA_PSK,
|
||||
AUTH_MODE_WPA2_PSK
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
WL_PING_DEST_UNREACHABLE = -1,
|
||||
WL_PING_TIMEOUT = -2,
|
||||
WL_PING_UNKNOWN_HOST = -3,
|
||||
WL_PING_ERROR = -4
|
||||
} wl_ping_result_t;
|
||||
|
||||
#endif //_WL_TYPES_H_
|
||||
Reference in New Issue
Block a user