mirror of https://github.com/noisymime/Arduino.git
Merge remote branch 'origin/hd_2.7'
This commit is contained in:
commit
2db3686501
|
@ -34,6 +34,11 @@ uint8_t WiFiClass::getSocket()
|
|||
return NO_SOCKET_AVAIL;
|
||||
}
|
||||
|
||||
char* WiFiClass::firmwareVersion()
|
||||
{
|
||||
return WiFiDrv::getFwVersion();
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
|
@ -150,9 +155,20 @@ uint8_t WiFiClass::encryptionType()
|
|||
}
|
||||
|
||||
|
||||
uint8_t WiFiClass::scanNetworks()
|
||||
int8_t WiFiClass::scanNetworks()
|
||||
{
|
||||
return WiFiDrv::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;
|
||||
}
|
||||
|
||||
char* WiFiClass::SSID(uint8_t networkItem)
|
||||
|
|
|
@ -28,6 +28,12 @@ public:
|
|||
*/
|
||||
static uint8_t getSocket();
|
||||
|
||||
/*
|
||||
* Get firmware version
|
||||
*/
|
||||
static char* firmwareVersion();
|
||||
|
||||
|
||||
/* Start Wifi connection for OPEN networks
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
|
@ -123,7 +129,7 @@ public:
|
|||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
uint8_t scanNetworks();
|
||||
int8_t scanNetworks();
|
||||
|
||||
/*
|
||||
* Return the SSID discovered during the network scan.
|
||||
|
|
|
@ -35,8 +35,19 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
|
|||
{
|
||||
ServerDrv::startClient(uint32_t(ip), port, _sock);
|
||||
WiFiClass::_state[_sock] = _sock;
|
||||
while(!connected());
|
||||
|
||||
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;
|
||||
|
@ -59,12 +70,17 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size) {
|
|||
}
|
||||
|
||||
|
||||
if ((!ServerDrv::sendData(_sock, buf, size)) ||
|
||||
(!ServerDrv::checkDataSent(_sock)))
|
||||
if (!ServerDrv::sendData(_sock, buf, size))
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
if (!ServerDrv::checkDataSent(_sock))
|
||||
{
|
||||
setWriteError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
@ -94,8 +110,12 @@ int WiFiClient::read(uint8_t* buf, size_t size) {
|
|||
}
|
||||
|
||||
int WiFiClient::peek() {
|
||||
//TODO to be implemented
|
||||
return 0;
|
||||
uint8_t b;
|
||||
if (!available())
|
||||
return -1;
|
||||
|
||||
ServerDrv::getData(_sock, &b, 1);
|
||||
return b;
|
||||
}
|
||||
|
||||
void WiFiClient::flush() {
|
||||
|
@ -112,10 +132,10 @@ void WiFiClient::stop() {
|
|||
|
||||
unsigned long start = millis();
|
||||
|
||||
|
||||
// wait a second for the connection to close
|
||||
while (status() != CLOSED && millis() - start < 1000)
|
||||
delay(1);
|
||||
|
||||
_sock = 255;
|
||||
}
|
||||
|
||||
|
@ -128,6 +148,7 @@ uint8_t WiFiClient::connected() {
|
|||
|
||||
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
|
||||
s == FIN_WAIT_2 || s == TIME_WAIT ||
|
||||
s == SYN_SENT || s== SYN_RCVD ||
|
||||
(s == CLOSE_WAIT && !available()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 29 Feb 2012
|
||||
by Scott Fitzgerald
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
|
||||
|
@ -18,26 +18,34 @@ char ssid[] = "yourNetwork"; // the name of your network
|
|||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// attempt to connect to an open network:
|
||||
Serial.print("Attempting to connect to open network: ");
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to open SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid);
|
||||
|
||||
// if you're not connected, stop here:
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
while(true);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// if you are connected :
|
||||
else {
|
||||
|
||||
// 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:
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 4 Mar 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
|
@ -30,26 +30,34 @@ int keyIndex = 0; // your network key Index numbe
|
|||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// attempt to connect to an open network:
|
||||
Serial.print("Attempting to connect to WEP network: ");
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WEP network, SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, keyIndex, key);
|
||||
|
||||
// if you're not connected, stop here:
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
while(true);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// if you are connected :
|
||||
else {
|
||||
|
||||
// once you are connected :
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
|
@ -115,3 +123,4 @@ void printCurrentNet() {
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -9,35 +9,45 @@
|
|||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 29 Feb 2012
|
||||
by Scott Fitzgerald
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "networkName"; // your network SSID (name)
|
||||
char pass[] = "yourPassword"; // your network password
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
|
||||
void setup() {
|
||||
// initialize serial:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// attempt to connect to an open network:
|
||||
Serial.print("Attempting to connect to WPA network: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// if you're not connected, stop here:
|
||||
if ( status != WL_CONNECTED) {
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
// if you are connected :
|
||||
else {
|
||||
|
||||
// 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() {
|
||||
|
|
|
@ -10,8 +10,8 @@
|
|||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 22 April 2012
|
||||
by Tom Igoe
|
||||
modified 21 Junn 2012
|
||||
by Tom Igoe and Jaymes Dec
|
||||
*/
|
||||
|
||||
|
||||
|
@ -19,11 +19,20 @@
|
|||
#include <WiFi.h>
|
||||
|
||||
void setup() {
|
||||
// initialize serial and wait for the port to open:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// attempt to connect using WEP encryption:
|
||||
Serial.println("Initializing Wifi...");
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// Print WiFi MAC address:
|
||||
printMacAddress();
|
||||
|
||||
// scan for existing networks:
|
||||
|
@ -61,7 +70,12 @@ void printMacAddress() {
|
|||
void listNetworks() {
|
||||
// scan for nearby networks:
|
||||
Serial.println("** Scan Networks **");
|
||||
byte numSsid = WiFi.scanNetworks();
|
||||
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:");
|
||||
|
@ -76,7 +90,28 @@ void listNetworks() {
|
|||
Serial.print(WiFi.RSSI(thisNet));
|
||||
Serial.print(" dBm");
|
||||
Serial.print("\tEncryption: ");
|
||||
Serial.println(WiFi.encryptionType(thisNet));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 23 Apr 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
@ -22,8 +22,8 @@
|
|||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "YourNetwork"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
|
||||
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
|
@ -34,14 +34,26 @@ WiFiServer server(23);
|
|||
boolean alreadyConnected = false; // whether or not the client was connected previously
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 13 Mar 2012
|
||||
modified 14 May 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
modified 8 Sept 2012
|
||||
by Scott Fitzgerald
|
||||
|
@ -48,14 +48,26 @@ boolean lastConnected = false; // state of the connection last t
|
|||
const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
@ -71,7 +83,7 @@ void loop() {
|
|||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
if (client.available()) {
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 16 Mar 2012
|
||||
modified 14 May 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
modified 8 Sept 2012
|
||||
by Scott Fitzgerald
|
||||
|
@ -53,14 +53,26 @@ boolean lastConnected = false; // state of the connection last t
|
|||
const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
@ -85,7 +97,7 @@ void loop() {
|
|||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
if (client.available()) {
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* WiFi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 23 apr 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
|
@ -22,7 +23,7 @@
|
|||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "YourNetwork"; // your network SSID (name)
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
|
@ -49,14 +50,26 @@ void setup() {
|
|||
// reserve space for the strings:
|
||||
currentLine.reserve(256);
|
||||
tweet.reserve(150);
|
||||
// start serial port:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 23 Apr 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
|
@ -24,8 +24,8 @@
|
|||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "YourNetwork"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // 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;
|
||||
|
@ -40,13 +40,26 @@ IPAddress server(173,194,73,105); // numeric IP for Google (no DNS)
|
|||
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 Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
|
|
@ -7,7 +7,8 @@
|
|||
Circuit:
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 23 Apr 2012
|
||||
created 23 April 2012
|
||||
modifide 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/WifiWebClientRepeating
|
||||
|
@ -35,14 +36,26 @@ boolean lastConnected = false; // state of the connection last
|
|||
const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 23 Apr 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
#include <SPI.h>
|
||||
|
@ -29,14 +29,26 @@ int status = WL_IDLE_STATUS;
|
|||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
// start serial port:
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#define WARN(args) do {} while (0);
|
||||
#endif
|
||||
|
||||
#if _DEBUG_SPI_
|
||||
#define DBG_PIN2 5
|
||||
#define DBG_PIN 4
|
||||
|
||||
|
@ -64,5 +65,13 @@
|
|||
#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
|
||||
|
|
|
@ -146,12 +146,13 @@ uint8_t ServerDrv::availData(uint8_t sock)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool ServerDrv::getData(uint8_t sock, uint8_t *data)
|
||||
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_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
SpiDrv::sendCmd(GET_DATA_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock));
|
||||
SpiDrv::sendParam(peek, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
@ -225,8 +226,8 @@ bool ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
|
|||
|
||||
uint8_t ServerDrv::checkDataSent(uint8_t sock)
|
||||
{
|
||||
const uint16_t TIMEOUT_DATA_SENT = 250;
|
||||
static uint16_t timeout = 0;
|
||||
const uint16_t TIMEOUT_DATA_SENT = 25;
|
||||
uint16_t timeout = 0;
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
|
||||
|
@ -249,14 +250,10 @@ uint8_t ServerDrv::checkDataSent(uint8_t sock)
|
|||
if (_data) timeout = 0;
|
||||
else{
|
||||
++timeout;
|
||||
if (timeout > TIMEOUT_DATA_SENT)
|
||||
{
|
||||
timeout = 0;
|
||||
INFO1("Timeout wainting for data sent");
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
}while((_data==0)&&(timeout<TIMEOUT_DATA_SENT));
|
||||
|
||||
}while((_data==0)&&(timeout<TIMEOUT_DATA_SENT));
|
||||
return (timeout==TIMEOUT_DATA_SENT)?0:1;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ public:
|
|||
|
||||
static uint8_t getClientState(uint8_t sock);
|
||||
|
||||
static bool getData(uint8_t sock, uint8_t *data);
|
||||
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);
|
||||
|
||||
|
|
|
@ -11,9 +11,12 @@ extern "C" {
|
|||
#define DATAIN 12 // MISO
|
||||
#define SPICLOCK 13 // sck
|
||||
#define SLAVESELECT 10 // ss
|
||||
#define SLAVEREADY 3
|
||||
#define SLAVEREADY 7 // handshake pin
|
||||
#define WIFILED 9 // led on wifi shield
|
||||
|
||||
#define DELAY_100NS asm volatile("nop")
|
||||
#define DELAY_100NS do { asm volatile("nop"); }while(0);
|
||||
#define DELAY_SPI(X) { int ii=0; do { asm volatile("nop"); }while(++ii<X);}
|
||||
#define DELAY_TRANSFER() DELAY_SPI(10)
|
||||
|
||||
void SpiDrv::begin()
|
||||
{
|
||||
|
@ -28,11 +31,13 @@ void SpiDrv::begin()
|
|||
pinMode(SS, OUTPUT);
|
||||
pinMode(SLAVESELECT, OUTPUT);
|
||||
pinMode(SLAVEREADY, INPUT);
|
||||
pinMode(WIFILED, OUTPUT);
|
||||
|
||||
digitalWrite(SCK, LOW);
|
||||
digitalWrite(MOSI, LOW);
|
||||
digitalWrite(SS, HIGH);
|
||||
digitalWrite(SLAVESELECT, HIGH);
|
||||
digitalWrite(WIFILED, LOW);
|
||||
|
||||
#ifdef _DEBUG_
|
||||
INIT_TRIGGER()
|
||||
|
@ -78,9 +83,8 @@ char SpiDrv::spiTransfer(volatile char data)
|
|||
{
|
||||
};
|
||||
char result = SPDR;
|
||||
DELAY_100NS;
|
||||
DELAY_100NS;
|
||||
//delayMicroseconds(SPI_TX_DELAY);
|
||||
DELAY_TRANSFER();
|
||||
|
||||
return result; // return the received byte
|
||||
}
|
||||
|
||||
|
@ -99,25 +103,8 @@ int SpiDrv::waitSpiChar(unsigned char waitChar)
|
|||
return (_readChar == waitChar);
|
||||
}
|
||||
|
||||
//int SpiDrv::waitSpiChar(char waitChar, char* readChar)
|
||||
//{
|
||||
// int timeout = TIMEOUT_CHAR;
|
||||
// do{
|
||||
// *readChar = spiTransfer(DUMMY_DATA); //get data byte
|
||||
// if (*readChar == WAIT_CMD)
|
||||
// {
|
||||
// INFO1("WAIT");
|
||||
// delayMicroseconds(WAIT_CHAR_DELAY);
|
||||
// }
|
||||
// }while((timeout-- > 0) && (*readChar != waitChar));
|
||||
//
|
||||
// return (*readChar == waitChar);
|
||||
//}
|
||||
|
||||
|
||||
int SpiDrv::readAndCheckChar(char checkChar, char* readChar)
|
||||
{
|
||||
//*readChar = spiTransfer(DUMMY_DATA); //get data byte
|
||||
getParam((uint8_t*)readChar);
|
||||
|
||||
return (*readChar == checkChar);
|
||||
|
@ -128,11 +115,8 @@ char SpiDrv::readChar()
|
|||
uint8_t readChar = 0;
|
||||
getParam(&readChar);
|
||||
return readChar;
|
||||
//return spiTransfer(DUMMY_DATA); //get data byte
|
||||
}
|
||||
|
||||
//#define WAIT_START_CMD(x) waitSpiChar(START_CMD, &x)
|
||||
//#define WAIT_START_CMD(x) readAndCheckChar(START_CMD, &x)
|
||||
#define WAIT_START_CMD(x) waitSpiChar(START_CMD)
|
||||
|
||||
#define IF_CHECK_START_CMD(x) \
|
||||
|
@ -171,10 +155,7 @@ void SpiDrv::getParam(uint8_t* param)
|
|||
{
|
||||
// Get Params data
|
||||
*param = spiTransfer(DUMMY_DATA);
|
||||
DELAY_100NS;
|
||||
DELAY_100NS;
|
||||
DELAY_100NS;
|
||||
DELAY_100NS;
|
||||
DELAY_TRANSFER();
|
||||
}
|
||||
|
||||
int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len)
|
||||
|
@ -399,6 +380,7 @@ int SpiDrv::waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, u
|
|||
} else
|
||||
{
|
||||
WARN("Error numParams == 0");
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
return 0;
|
||||
}
|
||||
readAndCheckChar(END_CMD, &_data);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <inttypes.h>
|
||||
#include "wifi_spi.h"
|
||||
|
||||
#define SPI_START_CMD_DELAY 10
|
||||
#define SPI_START_CMD_DELAY 12
|
||||
|
||||
#define NO_LAST_PARAM 0
|
||||
#define LAST_PARAM 1
|
||||
|
|
|
@ -26,6 +26,8 @@ uint8_t WiFiDrv::_mac[] = {0};
|
|||
uint8_t WiFiDrv::_localIp[] = {0};
|
||||
uint8_t WiFiDrv::_subnetMask[] = {0};
|
||||
uint8_t WiFiDrv::_gatewayIp[] = {0};
|
||||
// Firmware version
|
||||
char WiFiDrv::fwVersion[] = {0};
|
||||
|
||||
|
||||
// Private Methods
|
||||
|
@ -59,7 +61,7 @@ void WiFiDrv::wifiDriverInit()
|
|||
SpiDrv::begin();
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
||||
int8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
|
@ -75,13 +77,14 @@ uint8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
|||
if (!SpiDrv::waitResponseCmd(SET_NET_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return(_data == WIFI_SPI_ACK) ? WL_SUCCESS : WL_FAILURE;
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len)
|
||||
int8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
|
@ -98,13 +101,14 @@ uint8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *pas
|
|||
if (!SpiDrv::waitResponseCmd(SET_PASSPHRASE_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
||||
uint8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len)
|
||||
int8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
|
@ -122,12 +126,13 @@ uint8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const
|
|||
if (!SpiDrv::waitResponseCmd(SET_KEY_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::disconnect()
|
||||
int8_t WiFiDrv::disconnect()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
|
@ -142,7 +147,7 @@ uint8_t WiFiDrv::disconnect()
|
|||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
uint8_t result = SpiDrv::waitResponseCmd(DISCONNECT_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
int8_t result = SpiDrv::waitResponseCmd(DISCONNECT_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
|
@ -160,7 +165,7 @@ uint8_t WiFiDrv::getConnectionStatus()
|
|||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _data = -1;
|
||||
uint8_t _dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
|
||||
|
@ -299,7 +304,33 @@ uint8_t WiFiDrv::getCurrentEncryptionType()
|
|||
return encType;
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::scanNetworks()
|
||||
int8_t WiFiDrv::startScanNetworks()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_SCAN_NETWORKS, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
|
||||
if (!SpiDrv::waitResponseCmd(START_SCAN_NETWORKS, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return (_data == WL_FAILURE)? _data : WL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
uint8_t WiFiDrv::getScanNetworks()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
|
@ -438,4 +469,23 @@ int WiFiDrv::getHostByName(const char* aHostname, IPAddress& aResult)
|
|||
return (retry>0);
|
||||
}
|
||||
|
||||
char* WiFiDrv::getFwVersion()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_FW_VERSION_CMD, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_FW_VERSION_CMD, PARAM_NUMS_1, (uint8_t*)fwVersion, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return fwVersion;
|
||||
}
|
||||
|
||||
WiFiDrv wiFiDrv;
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#define KEY_IDX_LEN 1
|
||||
// 5 secs of delay to have the connection established
|
||||
#define WL_DELAY_START_CONNECTION 5000
|
||||
// firmware version string length
|
||||
#define WL_FW_VER_LENGTH 6
|
||||
|
||||
class WiFiDrv
|
||||
{
|
||||
|
@ -18,6 +20,9 @@ private:
|
|||
static int32_t _networkRssi[WL_NETWORKS_LIST_MAXNUM];
|
||||
static uint8_t _networkEncr[WL_NETWORKS_LIST_MAXNUM];
|
||||
|
||||
// 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];
|
||||
|
@ -52,7 +57,7 @@ public:
|
|||
* param ssid_len: Lenght of ssid string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static uint8_t wifiSetNetwork(char* ssid, uint8_t ssid_len);
|
||||
static int8_t wifiSetNetwork(char* ssid, uint8_t ssid_len);
|
||||
|
||||
/* Start Wifi connection with passphrase
|
||||
* the most secure supported mode will be automatically selected
|
||||
|
@ -64,7 +69,7 @@ public:
|
|||
* param len: Lenght of passphrase string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static uint8_t wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len);
|
||||
static int8_t wifiSetPassphrase(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)
|
||||
|
@ -77,14 +82,14 @@ public:
|
|||
* param len: Lenght of key string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static uint8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
|
||||
static int8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static uint8_t disconnect();
|
||||
static int8_t disconnect();
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
|
@ -156,7 +161,14 @@ public:
|
|||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
static uint8_t scanNetworks();
|
||||
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.
|
||||
|
@ -194,6 +206,12 @@ public:
|
|||
*/
|
||||
static int getHostByName(const char* aHostname, IPAddress& aResult);
|
||||
|
||||
/*
|
||||
* Get the firmware version
|
||||
* result: version as string with this format a.b.c
|
||||
*/
|
||||
static char* getFwVersion();
|
||||
|
||||
};
|
||||
|
||||
extern WiFiDrv wiFiDrv;
|
||||
|
|
|
@ -47,6 +47,8 @@ enum {
|
|||
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,
|
||||
|
||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
#define WL_MAX_ATTEMPT_CONNECTION 10
|
||||
|
||||
typedef enum {
|
||||
WL_IDLE_STATUS,
|
||||
WL_NO_SHIELD = 255,
|
||||
WL_IDLE_STATUS = 0,
|
||||
WL_NO_SSID_AVAIL,
|
||||
WL_SCAN_COMPLETED,
|
||||
WL_CONNECTED,
|
||||
|
|
Loading…
Reference in New Issue