Skip to content

Commit 2db3686

Browse files
committed
Merge remote branch 'origin/hd_2.7'
2 parents 0b05660 + 156c102 commit 2db3686

File tree

23 files changed

+414
-163
lines changed

23 files changed

+414
-163
lines changed

WiFi/WiFi.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ uint8_t WiFiClass::getSocket()
3434
return NO_SOCKET_AVAIL;
3535
}
3636

37+
char* WiFiClass::firmwareVersion()
38+
{
39+
return WiFiDrv::getFwVersion();
40+
}
41+
3742
int WiFiClass::begin(char* ssid)
3843
{
3944
uint8_t status = WL_IDLE_STATUS;
@@ -150,9 +155,20 @@ uint8_t WiFiClass::encryptionType()
150155
}
151156

152157

153-
uint8_t WiFiClass::scanNetworks()
158+
int8_t WiFiClass::scanNetworks()
154159
{
155-
return WiFiDrv::scanNetworks();
160+
uint8_t attempts = 10;
161+
uint8_t numOfNetworks = 0;
162+
163+
if (WiFiDrv::startScanNetworks() == WL_FAILURE)
164+
return WL_FAILURE;
165+
do
166+
{
167+
delay(2000);
168+
numOfNetworks = WiFiDrv::getScanNetworks();
169+
}
170+
while (( numOfNetworks == 0)&&(--attempts>0));
171+
return numOfNetworks;
156172
}
157173

158174
char* WiFiClass::SSID(uint8_t networkItem)

WiFi/WiFi.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class WiFiClass
2828
*/
2929
static uint8_t getSocket();
3030

31+
/*
32+
* Get firmware version
33+
*/
34+
static char* firmwareVersion();
35+
36+
3137
/* Start Wifi connection for OPEN networks
3238
*
3339
* param ssid: Pointer to the SSID string.
@@ -123,7 +129,7 @@ class WiFiClass
123129
*
124130
* return: Number of discovered networks
125131
*/
126-
uint8_t scanNetworks();
132+
int8_t scanNetworks();
127133

128134
/*
129135
* Return the SSID discovered during the network scan.

WiFi/WiFiClient.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,19 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
3535
{
3636
ServerDrv::startClient(uint32_t(ip), port, _sock);
3737
WiFiClass::_state[_sock] = _sock;
38-
while(!connected());
38+
39+
unsigned long start = millis();
40+
41+
// wait 4 second for the connection to close
42+
while (!connected() && millis() - start < 10000)
43+
delay(1);
44+
45+
if (!connected())
46+
{
47+
return 0;
48+
}
3949
}else{
50+
Serial.println("No Socket available");
4051
return 0;
4152
}
4253
return 1;
@@ -59,12 +70,17 @@ size_t WiFiClient::write(const uint8_t *buf, size_t size) {
5970
}
6071

6172

62-
if ((!ServerDrv::sendData(_sock, buf, size)) ||
63-
(!ServerDrv::checkDataSent(_sock)))
73+
if (!ServerDrv::sendData(_sock, buf, size))
6474
{
6575
setWriteError();
6676
return 0;
6777
}
78+
if (!ServerDrv::checkDataSent(_sock))
79+
{
80+
setWriteError();
81+
return 0;
82+
}
83+
6884
return size;
6985
}
7086

@@ -94,8 +110,12 @@ int WiFiClient::read(uint8_t* buf, size_t size) {
94110
}
95111

96112
int WiFiClient::peek() {
97-
//TODO to be implemented
98-
return 0;
113+
uint8_t b;
114+
if (!available())
115+
return -1;
116+
117+
ServerDrv::getData(_sock, &b, 1);
118+
return b;
99119
}
100120

101121
void WiFiClient::flush() {
@@ -112,10 +132,10 @@ void WiFiClient::stop() {
112132

113133
unsigned long start = millis();
114134

135+
115136
// wait a second for the connection to close
116137
while (status() != CLOSED && millis() - start < 1000)
117138
delay(1);
118-
119139
_sock = 255;
120140
}
121141

@@ -128,6 +148,7 @@ uint8_t WiFiClient::connected() {
128148

129149
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
130150
s == FIN_WAIT_2 || s == TIME_WAIT ||
151+
s == SYN_SENT || s== SYN_RCVD ||
131152
(s == CLOSE_WAIT && !available()));
132153
}
133154
}

WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,42 @@
99
1010
created 13 July 2010
1111
by dlf (Metodo2 srl)
12-
modified 29 Feb 2012
13-
by Scott Fitzgerald
12+
modified 31 May 2012
13+
by Tom Igoe
1414
*/
1515
#include <WiFi.h>
1616

1717
char ssid[] = "yourNetwork"; // the name of your network
1818
int status = WL_IDLE_STATUS; // the Wifi radio's status
1919

2020
void setup() {
21-
// initialize serial:
22-
Serial.begin(9600);
23-
24-
// attempt to connect to an open network:
25-
Serial.print("Attempting to connect to open network: ");
26-
Serial.println(ssid);
27-
status = WiFi.begin(ssid);
28-
29-
// if you're not connected, stop here:
30-
if ( status != WL_CONNECTED) {
31-
Serial.println("Couldn't get a wifi connection");
21+
//Initialize serial and wait for port to open:
22+
Serial.begin(9600);
23+
while (!Serial) {
24+
; // wait for serial port to connect. Needed for Leonardo only
25+
}
26+
27+
// check for the presence of the shield:
28+
if (WiFi.status() == WL_NO_SHIELD) {
29+
Serial.println("WiFi shield not present");
30+
// don't continue:
3231
while(true);
3332
}
34-
// if you are connected :
35-
else {
36-
Serial.print("You're connected to the network");
37-
printCurrentNet();
38-
printWifiData();
33+
34+
// attempt to connect to Wifi network:
35+
while ( status != WL_CONNECTED) {
36+
Serial.print("Attempting to connect to open SSID: ");
37+
Serial.println(ssid);
38+
status = WiFi.begin(ssid);
39+
40+
// wait 10 seconds for connection:
41+
delay(10000);
3942
}
43+
44+
// you're connected now, so print out the data:
45+
Serial.print("You're connected to the network");
46+
printCurrentNet();
47+
printWifiData();
4048
}
4149

4250
void loop() {

WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
created 13 July 2010
2121
by dlf (Metodo2 srl)
22-
modified 4 Mar 2012
22+
modified 31 May 2012
2323
by Tom Igoe
2424
*/
2525
#include <WiFi.h>
@@ -30,25 +30,33 @@ int keyIndex = 0; // your network key Index numbe
3030
int status = WL_IDLE_STATUS; // the Wifi radio's status
3131

3232
void setup() {
33-
// initialize serial:
34-
Serial.begin(9600);
35-
36-
// attempt to connect to an open network:
37-
Serial.print("Attempting to connect to WEP network: ");
38-
Serial.println(ssid);
39-
status = WiFi.begin(ssid, keyIndex, key);
33+
//Initialize serial and wait for port to open:
34+
Serial.begin(9600);
35+
while (!Serial) {
36+
; // wait for serial port to connect. Needed for Leonardo only
37+
}
4038

41-
// if you're not connected, stop here:
42-
if ( status != WL_CONNECTED) {
43-
Serial.println("Couldn't get a wifi connection");
39+
// check for the presence of the shield:
40+
if (WiFi.status() == WL_NO_SHIELD) {
41+
Serial.println("WiFi shield not present");
42+
// don't continue:
4443
while(true);
4544
}
46-
// if you are connected :
47-
else {
48-
Serial.print("You're connected to the network");
49-
printCurrentNet();
50-
printWifiData();
45+
46+
// attempt to connect to Wifi network:
47+
while ( status != WL_CONNECTED) {
48+
Serial.print("Attempting to connect to WEP network, SSID: ");
49+
Serial.println(ssid);
50+
status = WiFi.begin(ssid, keyIndex, key);
51+
52+
// wait 10 seconds for connection:
53+
delay(10000);
5154
}
55+
56+
// once you are connected :
57+
Serial.print("You're connected to the network");
58+
printCurrentNet();
59+
printWifiData();
5260
}
5361

5462
void loop() {
@@ -60,7 +68,7 @@ void loop() {
6068
void printWifiData() {
6169
// print your WiFi shield's IP address:
6270
IPAddress ip = WiFi.localIP();
63-
Serial.print("IP Address: ");
71+
Serial.print("IP Address: ");
6472
Serial.println(ip);
6573
Serial.println(ip);
6674

@@ -115,3 +123,4 @@ void printCurrentNet() {
115123
}
116124

117125

126+

WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,45 @@
99
1010
created 13 July 2010
1111
by dlf (Metodo2 srl)
12-
modified 29 Feb 2012
13-
by Scott Fitzgerald
12+
modified 31 May 2012
13+
by Tom Igoe
1414
*/
1515
#include <WiFi.h>
1616

17-
char ssid[] = "networkName"; // your network SSID (name)
18-
char pass[] = "yourPassword"; // your network password
17+
char ssid[] = "yourNetwork"; // your network SSID (name)
18+
char pass[] = "secretPassword"; // your network password
1919
int status = WL_IDLE_STATUS; // the Wifi radio's status
2020

2121
void setup() {
22-
// initialize serial:
23-
Serial.begin(9600);
24-
25-
// attempt to connect to an open network:
26-
Serial.print("Attempting to connect to WPA network: ");
27-
Serial.println(ssid);
28-
status = WiFi.begin(ssid, pass);
22+
//Initialize serial and wait for port to open:
23+
Serial.begin(9600);
24+
while (!Serial) {
25+
; // wait for serial port to connect. Needed for Leonardo only
26+
}
2927

30-
// if you're not connected, stop here:
31-
if ( status != WL_CONNECTED) {
32-
Serial.println("Couldn't get a wifi connection");
28+
// check for the presence of the shield:
29+
if (WiFi.status() == WL_NO_SHIELD) {
30+
Serial.println("WiFi shield not present");
31+
// don't continue:
3332
while(true);
3433
}
35-
// if you are connected :
36-
else {
37-
Serial.print("You're connected to the network");
38-
printCurrentNet();
39-
printWifiData();
34+
35+
// attempt to connect to Wifi network:
36+
while ( status != WL_CONNECTED) {
37+
Serial.print("Attempting to connect to WPA SSID: ");
38+
Serial.println(ssid);
39+
// Connect to WPA/WPA2 network:
40+
status = WiFi.begin(ssid, pass);
41+
42+
// wait 10 seconds for connection:
43+
delay(10000);
4044
}
45+
46+
// you're connected now, so print out the data:
47+
Serial.print("You're connected to the network");
48+
printCurrentNet();
49+
printWifiData();
50+
4151
}
4252

4353
void loop() {

0 commit comments

Comments
 (0)