Fix ScanNetworks list

This commit is contained in:
Mimmo La Fauci 2012-05-24 08:57:46 +02:00
parent e3749c2dbf
commit b6490ad458
5 changed files with 45 additions and 5 deletions

View File

@ -152,7 +152,17 @@ uint8_t WiFiClass::encryptionType()
uint8_t WiFiClass::scanNetworks()
{
return WiFiDrv::scanNetworks();
uint8_t attempts = 10;
uint8_t numOfNetworks = 0;
WiFiDrv::startScanNetworks();
do
{
delay(2000);
numOfNetworks = WiFiDrv::getScanNetworks();
}
while (( numOfNetworks == 0)&&(--attempts>0));
return numOfNetworks;
}
char* WiFiClass::SSID(uint8_t networkItem)

View File

@ -399,6 +399,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);

View File

@ -299,7 +299,28 @@ uint8_t WiFiDrv::getCurrentEncryptionType()
return encType;
}
uint8_t WiFiDrv::scanNetworks()
uint8_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;
uint8_t result = SpiDrv::waitResponseCmd(START_SCAN_NETWORKS, PARAM_NUMS_1, &_data, &_dataLen);
SpiDrv::spiSlaveDeselect();
return result;
}
uint8_t WiFiDrv::getScanNetworks()
{
WAIT_FOR_SLAVE_SELECT();

View File

@ -38,7 +38,7 @@ private:
public:
/*
* Driver initialization
* Driver initialization
*/
static void wifiDriverInit();
@ -82,7 +82,7 @@ public:
/*
* Disconnect from the network
*
* return: WL_SUCCESS or WL_FAILURE
* return: WL_SUCCESS or WL_FAILURE
*/
static uint8_t disconnect();
@ -156,7 +156,14 @@ public:
*
* return: Number of discovered networks
*/
static uint8_t scanNetworks();
static uint8_t startScanNetworks();
/*
* Get the networks available
*
* return: Number of discovered networks
*/
static uint8_t getScanNetworks();
/*
* Return the SSID discovered during the network scan.

View File

@ -47,6 +47,7 @@ enum {
GET_IDX_ENCT_CMD = 0x33,
REQ_HOST_BY_NAME_CMD= 0x34,
GET_HOST_BY_NAME_CMD= 0x35,
START_SCAN_NETWORKS = 0x36,
// All command with DATA_FLAG 0x40 send a 16bit Len