Skip to content

Commit 520157a

Browse files
authored
Merge branch 'master' into set_pins
2 parents ef6c1a8 + cc0563e commit 520157a

12 files changed

+97
-25
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ env:
55
matrix:
66
- BOARD="arduino:samd:mkrwifi1010"
77
- BOARD="arduino:samd_beta:mkrvidor4000"
8-
- BOARD="arduino:megaavr:uno2018"
8+
- BOARD="arduino:megaavr:uno2018:mode=on"
99
before_install:
1010
- wget http://downloads.arduino.cc/arduino-$IDE_VERSION-linux64.tar.xz
1111
- tar xf arduino-$IDE_VERSION-linux64.tar.xz

CHANGELOG

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
WiFiNINA ?.?.? - ????.??.??
22

3+
WiFiNINA 1.4.0 - 2019.03.27
4+
5+
* Improved connection time, by increasing poll time of checking connection status to 100ms on begin
6+
* Added WiFiClass::setTimeout(...) API to set timeout of begin
7+
* Fixed issue of WiFiServer:available() only reporting the first byte in the WiFiChatServer example
8+
39
WiFiNINA 1.3.0 - 2018.11.13
410

511
* Added Tools/CheckFirmwareVersion example to check NINA firmware version

keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ WiFiUDP KEYWORD1
2121

2222
firmwareVersion KEYWORD2
2323
status KEYWORD2
24+
reasonCode KEYWORD2
2425
connect KEYWORD2
2526
write KEYWORD2
2627
available KEYWORD2
@@ -54,6 +55,7 @@ lowPowerMode KEYWORD2
5455
noLowPowerMode KEYWORD2
5556
ping KEYWORD2
5657
beginMulticast KEYWORD2
58+
setTimeout KEYWORD2
5759

5860

5961
#######################################

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=WiFiNINA
2-
version=1.3.0
2+
version=1.4.0
33
author=Arduino
44
maintainer=Arduino <[email protected]>
55
sentence=Enables network connection (local and Internet) with the Arduino MKR WiFi 1010, Arduino MKR VIDOR 4000 and Arduino UNO WiFi Rev.2.

src/WiFi.cpp

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extern "C" {
3030
#include "utility/debug.h"
3131
}
3232

33-
WiFiClass::WiFiClass()
33+
WiFiClass::WiFiClass() : _timeout(50000)
3434
{
3535
}
3636

@@ -64,16 +64,17 @@ const char* WiFiClass::firmwareVersion()
6464
int WiFiClass::begin(const char* ssid)
6565
{
6666
uint8_t status = WL_IDLE_STATUS;
67-
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
6867

6968
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
7069
{
71-
do
70+
for (unsigned long start = millis(); (millis() - start) < _timeout;)
7271
{
7372
delay(WL_DELAY_START_CONNECTION);
7473
status = WiFiDrv::getConnectionStatus();
74+
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
75+
break;
76+
}
7577
}
76-
while (((status == WL_IDLE_STATUS)||(status == WL_NO_SSID_AVAIL)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
7778
}else
7879
{
7980
status = WL_CONNECT_FAILED;
@@ -84,16 +85,18 @@ int WiFiClass::begin(const char* ssid)
8485
int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
8586
{
8687
uint8_t status = WL_IDLE_STATUS;
87-
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
8888

8989
// set encryption key
9090
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
9191
{
92-
do
92+
for (unsigned long start = millis(); (millis() - start) < _timeout;)
9393
{
9494
delay(WL_DELAY_START_CONNECTION);
9595
status = WiFiDrv::getConnectionStatus();
96-
}while ((( status == WL_IDLE_STATUS)||(status == WL_NO_SSID_AVAIL)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
96+
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
97+
break;
98+
}
99+
}
97100
}else{
98101
status = WL_CONNECT_FAILED;
99102
}
@@ -103,17 +106,18 @@ int WiFiClass::begin(const char* ssid, uint8_t key_idx, const char *key)
103106
int WiFiClass::begin(const char* ssid, const char *passphrase)
104107
{
105108
uint8_t status = WL_IDLE_STATUS;
106-
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
107109

108110
// set passphrase
109111
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
110112
{
111-
do
113+
for (unsigned long start = millis(); (millis() - start) < _timeout;)
112114
{
113115
delay(WL_DELAY_START_CONNECTION);
114116
status = WiFiDrv::getConnectionStatus();
117+
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
118+
break;
119+
}
115120
}
116-
while ((( status == WL_IDLE_STATUS)||(status == WL_NO_SSID_AVAIL)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
117121
}else{
118122
status = WL_CONNECT_FAILED;
119123
}
@@ -128,16 +132,17 @@ uint8_t WiFiClass::beginAP(const char *ssid)
128132
uint8_t WiFiClass::beginAP(const char *ssid, uint8_t channel)
129133
{
130134
uint8_t status = WL_IDLE_STATUS;
131-
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
132135

133136
if (WiFiDrv::wifiSetApNetwork(ssid, strlen(ssid), channel) != WL_FAILURE)
134137
{
135-
do
138+
for (unsigned long start = millis(); (millis() - start) < _timeout;)
136139
{
137140
delay(WL_DELAY_START_CONNECTION);
138141
status = WiFiDrv::getConnectionStatus();
142+
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
143+
break;
144+
}
139145
}
140-
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
141146
}else
142147
{
143148
status = WL_AP_FAILED;
@@ -153,17 +158,18 @@ uint8_t WiFiClass::beginAP(const char *ssid, const char* passphrase)
153158
uint8_t WiFiClass::beginAP(const char *ssid, const char* passphrase, uint8_t channel)
154159
{
155160
uint8_t status = WL_IDLE_STATUS;
156-
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
157161

158162
// set passphrase
159163
if (WiFiDrv::wifiSetApPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase), channel)!= WL_FAILURE)
160164
{
161-
do
162-
{
165+
for (unsigned long start = millis(); (millis() - start) < _timeout;)
166+
{
163167
delay(WL_DELAY_START_CONNECTION);
164168
status = WiFiDrv::getConnectionStatus();
169+
if ((status != WL_IDLE_STATUS) && (status != WL_NO_SSID_AVAIL) && (status != WL_SCAN_COMPLETED)) {
170+
break;
171+
}
165172
}
166-
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
167173
}else{
168174
status = WL_AP_FAILED;
169175
}
@@ -315,6 +321,11 @@ uint8_t WiFiClass::status()
315321
return WiFiDrv::getConnectionStatus();
316322
}
317323

324+
uint8_t WiFiClass::reasonCode()
325+
{
326+
return WiFiDrv::getReasonCode();
327+
}
328+
318329
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
319330
{
320331
return WiFiDrv::getHostByName(aHostname, aResult);
@@ -356,4 +367,8 @@ int WiFiClass::ping(IPAddress host, uint8_t ttl)
356367
return WiFiDrv::ping(host, ttl);
357368
}
358369

370+
void WiFiClass::setTimeout(unsigned long timeout)
371+
{
372+
_timeout = timeout;
373+
}
359374
WiFiClass WiFi;

src/WiFi.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class WiFiClass
4242
private:
4343

4444
static void init();
45+
unsigned long _timeout;
4546
public:
4647
WiFiClass();
4748

@@ -244,6 +245,13 @@ class WiFiClass
244245
*/
245246
uint8_t status();
246247

248+
/*
249+
* Return The deauthentication reason code.
250+
*
251+
* return: the deauthentication reason code
252+
*/
253+
uint8_t reasonCode();
254+
247255
/*
248256
* Resolve the given hostname to an IP address.
249257
* param aHostname: Name to be resolved
@@ -262,8 +270,10 @@ class WiFiClass
262270
int ping(const String &hostname, uint8_t ttl = 128);
263271
int ping(IPAddress host, uint8_t ttl = 128);
264272

273+
265274
void setPins(int8_t cs=10, int8_t ready=7, int8_t reset=5, int8_t gpio0=6, SPIClass *spi = &SPI);
266275
void setLEDs(uint8_t red, uint8_t green, uint8_t blue);
276+
void setTimeout(unsigned long timeout);
267277
};
268278

269279
extern WiFiClass WiFi;

src/WiFiServer.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ extern "C" {
3030
#include "WiFiServer.h"
3131

3232
WiFiServer::WiFiServer(uint16_t port) :
33-
_sock(NO_SOCKET_AVAIL)
33+
_sock(NO_SOCKET_AVAIL),
34+
_lastSock(NO_SOCKET_AVAIL)
3435
{
3536
_port = port;
3637
}
@@ -49,7 +50,19 @@ WiFiClient WiFiServer::available(byte* status)
4950
int sock = NO_SOCKET_AVAIL;
5051

5152
if (_sock != NO_SOCKET_AVAIL) {
52-
sock = ServerDrv::availServer(_sock);
53+
// check previous received client socket
54+
if (_lastSock != NO_SOCKET_AVAIL) {
55+
WiFiClient client(_lastSock);
56+
57+
if (client.connected() && client.available()) {
58+
sock = _lastSock;
59+
}
60+
}
61+
62+
if (sock == NO_SOCKET_AVAIL) {
63+
// check for new client socket
64+
sock = ServerDrv::availServer(_sock);
65+
}
5366
}
5467

5568
if (sock != NO_SOCKET_AVAIL) {
@@ -59,6 +72,8 @@ WiFiClient WiFiServer::available(byte* status)
5972
*status = client.status();
6073
}
6174

75+
_lastSock = sock;
76+
6277
return client;
6378
}
6479

src/WiFiServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class WiFiClient;
3232
class WiFiServer : public Server {
3333
private:
3434
uint8_t _sock;
35+
uint8_t _lastSock;
3536
uint16_t _port;
3637
void* pcb;
3738
public:

src/utility/wifi_drv.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,28 @@ int8_t WiFiDrv::disconnect()
328328
return result;
329329
}
330330

331+
uint8_t WiFiDrv::getReasonCode()
332+
{
333+
WAIT_FOR_SLAVE_SELECT();
334+
335+
// Send Command
336+
SpiDrv::sendCmd(GET_REASON_CODE_CMD, PARAM_NUMS_0);
337+
338+
SpiDrv::spiSlaveDeselect();
339+
//Wait the reply elaboration
340+
SpiDrv::waitForSlaveReady();
341+
SpiDrv::spiSlaveSelect();
342+
343+
// Wait for reply
344+
uint8_t _data = 1;
345+
uint8_t _dataLen = 0;
346+
SpiDrv::waitResponseCmd(GET_REASON_CODE_CMD, PARAM_NUMS_1, &_data, &_dataLen);
347+
348+
SpiDrv::spiSlaveDeselect();
349+
350+
return _data;
351+
}
352+
331353
uint8_t WiFiDrv::getConnectionStatus()
332354
{
333355
WAIT_FOR_SLAVE_SELECT();

src/utility/wifi_drv.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
// Key index length
3131
#define KEY_IDX_LEN 1
32-
// 5 secs of delay to have the connection established
33-
#define WL_DELAY_START_CONNECTION 5000
32+
// 100 msecs of delay to have the connection established
33+
#define WL_DELAY_START_CONNECTION 100
3434
// firmware version string length
3535
#define WL_FW_VER_LENGTH 6
3636

@@ -144,6 +144,8 @@ class WiFiDrv
144144
*/
145145
static int8_t disconnect();
146146

147+
static uint8_t getReasonCode();
148+
147149
/*
148150
* Disconnect from the network
149151
*

src/utility/wifi_spi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ enum {
5656
SET_AP_PASSPHRASE_CMD = 0x19,
5757
SET_DEBUG_CMD = 0x1A,
5858
GET_TEMPERATURE_CMD = 0x1B,
59+
GET_REASON_CODE_CMD = 0x1F,
5960

6061
GET_CONN_STATUS_CMD = 0x20,
6162
GET_IPADDR_CMD = 0x21,

src/utility/wl_definitions.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
#define SOCK_NOT_AVAIL 255
4646
// Default state value for Wifi state field
4747
#define NA_STATE -1
48-
//Maximum number of attempts to establish wifi connection
49-
#define WL_MAX_ATTEMPT_CONNECTION 10
5048

5149
typedef enum {
5250
WL_NO_SHIELD = 255,

0 commit comments

Comments
 (0)