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