Skip to content

Commit b6490ad

Browse files
committed
Fix ScanNetworks list
1 parent e3749c2 commit b6490ad

File tree

5 files changed

+45
-5
lines changed

5 files changed

+45
-5
lines changed

WiFi/WiFi.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,17 @@ uint8_t WiFiClass::encryptionType()
152152

153153
uint8_t WiFiClass::scanNetworks()
154154
{
155-
return WiFiDrv::scanNetworks();
155+
uint8_t attempts = 10;
156+
uint8_t numOfNetworks = 0;
157+
158+
WiFiDrv::startScanNetworks();
159+
do
160+
{
161+
delay(2000);
162+
numOfNetworks = WiFiDrv::getScanNetworks();
163+
}
164+
while (( numOfNetworks == 0)&&(--attempts>0));
165+
return numOfNetworks;
156166
}
157167

158168
char* WiFiClass::SSID(uint8_t networkItem)

WiFi/utility/spi_drv.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ int SpiDrv::waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, u
399399
} else
400400
{
401401
WARN("Error numParams == 0");
402+
readAndCheckChar(END_CMD, &_data);
402403
return 0;
403404
}
404405
readAndCheckChar(END_CMD, &_data);

WiFi/utility/wifi_drv.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,28 @@ uint8_t WiFiDrv::getCurrentEncryptionType()
299299
return encType;
300300
}
301301

302-
uint8_t WiFiDrv::scanNetworks()
302+
uint8_t WiFiDrv::startScanNetworks()
303+
{
304+
WAIT_FOR_SLAVE_SELECT();
305+
306+
// Send Command
307+
SpiDrv::sendCmd(START_SCAN_NETWORKS, PARAM_NUMS_0);
308+
309+
//Wait the reply elaboration
310+
SpiDrv::waitForSlaveReady();
311+
312+
// Wait for reply
313+
uint8_t _data = 0;
314+
uint8_t _dataLen = 0;
315+
uint8_t result = SpiDrv::waitResponseCmd(START_SCAN_NETWORKS, PARAM_NUMS_1, &_data, &_dataLen);
316+
317+
SpiDrv::spiSlaveDeselect();
318+
319+
return result;
320+
}
321+
322+
323+
uint8_t WiFiDrv::getScanNetworks()
303324
{
304325
WAIT_FOR_SLAVE_SELECT();
305326

WiFi/utility/wifi_drv.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class WiFiDrv
3838
public:
3939

4040
/*
41-
* Driver initialization
41+
* Driver initialization
4242
*/
4343
static void wifiDriverInit();
4444

@@ -82,7 +82,7 @@ class WiFiDrv
8282
/*
8383
* Disconnect from the network
8484
*
85-
* return: WL_SUCCESS or WL_FAILURE
85+
* return: WL_SUCCESS or WL_FAILURE
8686
*/
8787
static uint8_t disconnect();
8888

@@ -156,7 +156,14 @@ class WiFiDrv
156156
*
157157
* return: Number of discovered networks
158158
*/
159-
static uint8_t scanNetworks();
159+
static uint8_t startScanNetworks();
160+
161+
/*
162+
* Get the networks available
163+
*
164+
* return: Number of discovered networks
165+
*/
166+
static uint8_t getScanNetworks();
160167

161168
/*
162169
* Return the SSID discovered during the network scan.

WiFi/utility/wifi_spi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ enum {
4747
GET_IDX_ENCT_CMD = 0x33,
4848
REQ_HOST_BY_NAME_CMD= 0x34,
4949
GET_HOST_BY_NAME_CMD= 0x35,
50+
START_SCAN_NETWORKS = 0x36,
5051

5152
// All command with DATA_FLAG 0x40 send a 16bit Len
5253

0 commit comments

Comments
 (0)