Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
m2m_wifi_get_num_ap_found

Synchronous function to retrieve the number of AP's found in the last scan request, The function read the number of AP's from global variable which updated in the wi-fi callback fucntion through the M2M_WIFI_RESP_SCAN_DONE event.

Function used only in STA mode only.

Functions

NMI_API uint8 m2m_wifi_get_num_ap_found (void)
 Reads the number of AP's found in the last Scan Request, The function read the number of AP's from global variable which updated in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE. More...
 

NMI_API uint8 m2m_wifi_get_num_ap_found ( void  )

Reads the number of AP's found in the last Scan Request, The function read the number of AP's from global variable which updated in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE.

Synchronous function to retrieve the number of AP's found during the last scan operation.

See Also
m2m_wifi_request_scan
Returns
Return the number of AP's found in the last Scan Request.
Precondition
m2m_wifi_request_scan need to be called first
Warning
That function need to be called in the wifi_cb in M2M_WIFI_RESP_SCAN_DONE, calling that function in any other place will return undefined/undated numbers. Function used only in STA mode only.
See Also
m2m_wifi_request_scan M2M_WIFI_RESP_SCAN_DONE M2M_WIFI_RESP_SCAN_RESULT
Precondition
m2m_wifi_request_scan need to be called first
  • A Wi-Fi notification callback of type tpfAppWifiCb MUST be implemented and registered at intialization. Registering the callback is done through passing it to the m2m_wifi_init.
  • The event M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested connection information.
Warning
This function must be called only in the wi-fi callback function when the events M2M_WIFI_RESP_SCAN_DONE or M2M_WIFI_RESP_SCAN_RESULT are received. Calling this function in any other place will result in undefined/outdated numbers.
Returns
Return the number of AP's found in the last Scan Request.

Example

The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of the events received in response.

#include "m2m_wifi.h"
#include "m2m_types.h"
void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
static uint8 u8ScanResultIdx = 0;
switch(u8WiFiEvent)
{
{
tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
if(pstrInfo->s8ScanState == M2M_SUCCESS)
{
u8ScanResultIdx = 0;
if(pstrInfo->u8NumofCh >= 1)
{
m2m_wifi_req_scan_result(u8ScanResultIdx);
u8ScanResultIdx ++;
}
else
{
printf("No AP Found Rescan\n");
}
}
else
{
printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
}
}
break;
{
tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
pstrScanResult->u8index,pstrScanResult->s8rssi,
pstrScanResult->u8AuthType,
pstrScanResult->u8ch,
pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
pstrScanResult->au8SSID);
if(u8ScanResultIdx < u8NumFoundAPs)
{
// Read the next scan result
u8ScanResultIdx ++;
}
}
break;
default:
break;
}
}
int main()
{
param.pfAppWifiCb = wifi_event_cb;
if(!m2m_wifi_init(&param))
{
// Scan all channels
while(1)
{
}
}
}
The function reads the number of APs from global variable which was updated in the Wi-Fi 
callback function through the @ref M2M_WIFI_RESP_SCAN_DONE event.
Function used only in STA mode only. 
See Also
m2m_wifi_request_scan M2M_WIFI_RESP_SCAN_DONE M2M_WIFI_RESP_SCAN_RESULT
Precondition
m2m_wifi_request_scan must be called first to ensure up to date results are available.
  • A Wi-Fi notification callback of type tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback is done through passing it to the m2m_wifi_init.
  • The event M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested scan information.
Warning
This function must be called only in the wi-fi callback function when the events M2M_WIFI_RESP_SCAN_DONE or M2M_WIFI_RESP_SCAN_RESULT are received. Calling this function in any other place will result in undefined/outdated numbers.
Returns
Return the number of AP's found in the last Scan Request.

Example

The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of the events received in response.

#include "m2m_wifi.h"
#include "m2m_types.h"
void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
static uint8 u8ScanResultIdx = 0;
switch(u8WiFiEvent)
{
{
tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
if(pstrInfo->s8ScanState == M2M_SUCCESS)
{
u8ScanResultIdx = 0;
if(pstrInfo->u8NumofCh >= 1)
{
m2m_wifi_req_scan_result(u8ScanResultIdx);
u8ScanResultIdx ++;
}
else
{
printf("No AP Found Rescan\n");
}
}
else
{
printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
}
}
break;
{
tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
pstrScanResult->u8index,pstrScanResult->s8rssi,
pstrScanResult->u8AuthType,
pstrScanResult->u8ch,
pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
pstrScanResult->au8SSID);
if(u8ScanResultIdx < u8NumFoundAPs)
{
// Read the next scan result
u8ScanResultIdx ++;
}
}
break;
default:
break;
}
}
int main()
{
param.pfAppWifiCb = wifi_event_cb;
if(!m2m_wifi_init(&param))
{
// Scan all channels
while(1)
{
}
}
}
This function allows the application to recover the number of access points discovered during
the most recent scan activity. This is achieved via a global variable in the WINC driver that
is populated when receiving the @ref M2M_WIFI_RESP_SCAN_DONE event.
Function to be used in STA mode only.
See Also
m2m_wifi_request_scan M2M_WIFI_RESP_SCAN_DONE M2M_WIFI_RESP_SCAN_RESULT
Precondition
m2m_wifi_request_scan must be called first to ensure up to date results are available.
  • A Wi-Fi notification callback of type tpfAppWifiCb MUST be implemented and registered at initialization. Registering the callback is done through passing it to the m2m_wifi_init.
  • The event M2M_WIFI_RESP_SCAN_DONE must be handled in the callback to receive the requested scan information.
Warning
This function must be called only in the wi-fi callback function when the events M2M_WIFI_RESP_SCAN_DONE or M2M_WIFI_RESP_SCAN_RESULT are received. Calling this function in any other place will result in undefined/outdated numbers.
Returns
Returns the number of AP's found in the last Scan Request.

Example

The code snippet demonstrates an example of how the scan request is called from the application's main function and the handling of the events received in response.

#include "m2m_wifi.h"
#include "m2m_types.h"
void wifi_event_cb(uint8 u8WiFiEvent, void * pvMsg)
{
static uint8 u8ScanResultIdx = 0;
switch(u8WiFiEvent)
{
{
tstrM2mScanDone *pstrInfo = (tstrM2mScanDone*)pvMsg;
printf("Num of AP found %d\n",pstrInfo->u8NumofCh);
if(pstrInfo->s8ScanState == M2M_SUCCESS)
{
u8ScanResultIdx = 0;
if(pstrInfo->u8NumofCh >= 1)
{
m2m_wifi_req_scan_result(u8ScanResultIdx);
u8ScanResultIdx ++;
}
else
{
printf("No AP Found Rescan\n");
}
}
else
{
printf("(ERR) Scan fail with error <%d>\n",pstrInfo->s8ScanState);
}
}
break;
{
tstrM2mWifiscanResult *pstrScanResult =(tstrM2mWifiscanResult*)pvMsg;
uint8 u8NumFoundAPs = m2m_wifi_get_num_ap_found();
printf(">>%02d RI %d SEC %s CH %02d BSSID %02X:%02X:%02X:%02X:%02X:%02X SSID %s\n",
pstrScanResult->u8index,pstrScanResult->s8rssi,
pstrScanResult->u8AuthType,
pstrScanResult->u8ch,
pstrScanResult->au8BSSID[0], pstrScanResult->au8BSSID[1], pstrScanResult->au8BSSID[2],
pstrScanResult->au8BSSID[3], pstrScanResult->au8BSSID[4], pstrScanResult->au8BSSID[5],
pstrScanResult->au8SSID);
if(u8ScanResultIdx < u8NumFoundAPs)
{
// Read the next scan result
u8ScanResultIdx ++;
}
}
break;
default:
break;
}
}
int main()
{
param.pfAppWifiCb = wifi_event_cb;
if(!m2m_wifi_init(&param))
{
// Scan all channels
while(1)
{
}
}
}