esp_wifi_scan_get_ap_num shows scan count as 0

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

esp_wifi_scan_get_ap_num shows scan count as 0

Postby Ritesh » Thu Aug 17, 2023 5:21 am

Hello Team,

We have developed one code to scan all list of Wi-Fi Access points and trying to connect specific Access points based on RSSI.

It was working fine till few days and able to connect successfully in case of device disconnected.

But, Suddenly, we are getting esp_wifi_scan_get_ap_num as 0 count and not able to scan any AP list.
esp_wifi_scan_start success
Scan count 0
Stop scan success

Code: Select all

 err = esp_wifi_scan_start(NULL, true);
           if(err != ESP_OK)
            {
                ESP_LOGE(TAG, "esp_wifi_scan_start: fail");
                break;
            } else {
                ESP_LOGI(TAG, "esp_wifi_scan_start: success");
                
      uint16_t number = SCAN_DEFUALT_LIST_SIZE;
                wifi_ap_record_t ap_info[SCAN_DEFUALT_LIST_SIZE];
                uint16_t ap_count = 0;
                memset(ap_info, 0, sizeof(ap_info));

                err = esp_wifi_scan_get_ap_records(&number, ap_info);
                if(err != ESP_OK)
                {
                    ESP_LOGE(TAG, "esp_wifi_scan_get_ap_records: fail");
                }

                err = esp_wifi_scan_get_ap_num(&ap_count);

                ESP_LOGE(TAG, "Scan count %d", ap_count);          
So, Anyone has idea like what can be the issue if we get Access Point as 0 even though there are almost 10 APs are running?

Can it be due to memory issue or any other issue?

ESP32 IDF Version - 5.1 we are using.

Let me know if need anything else from my end regarding this issue
Regards,
Ritesh Prajapati

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: esp_wifi_scan_get_ap_num shows scan count as 0

Postby Ritesh » Thu Aug 17, 2023 1:47 pm

Hello Team,

Let me know if need any more information regarding this issue as it is really critical at our end and we are also not able to reproduce issue easily like it is taking almost 4 to 5 days to reproduce issue at our end.
Regards,
Ritesh Prajapati

Ritesh
Posts: 1383
Joined: Tue Sep 06, 2016 9:37 am
Location: India
Contact:

Re: esp_wifi_scan_get_ap_num shows scan count as 0

Postby Ritesh » Fri Aug 18, 2023 5:37 pm

Hello Team,

Is this correct flow for scanning Access Point while ESP32 is configured as STA mode?

Code: Select all

err = esp_wifi_disconnect();
        if(err != ESP_OK)
        {
            ESP_LOGE(TAG, "esp_wifi_disconnect: fail");
        } else {
            ESP_LOGI(TAG, "esp_wifi_disconnect: success");
        }

        while(true)
        {
			sys_uptime = (uint32_t) system_up_time();
			ESP_LOGI(TAG, "0 Internal Memory = %d  ---- Total Memory = %d", heap_caps_get_free_size(MALLOC_CAP_INTERNAL), xPortGetFreeHeapSize());
			ESP_LOGI(TAG, "------ System Up Time : %ld Seconds ---------\n\r", sys_uptime);
            err = esp_wifi_scan_start(NULL, true);
            if(err != ESP_OK)
            {
                ESP_LOGE(TAG, "esp_wifi_scan_start: fail");
                break;
            } else {
                ESP_LOGI(TAG, "esp_wifi_scan_start: success");

                for (int i=0;i<SSID_LOG_LEN;i++) {
                    knownSSIDs[i].current = false;
                }
				
                memset(ap_info, 0, sizeof(ap_info));
				
		err = esp_wifi_scan_get_ap_num(&ap_count);

		ESP_LOGI(TAG, "1 Internal Memory = %d  ---- Total Memory = %d \n\r", heap_caps_get_free_size(MALLOC_CAP_INTERNAL), xPortGetFreeHeapSize());
                ESP_LOGE(TAG, "Scan count %d", ap_count);

		if(ap_count > 0) {
			err = esp_wifi_scan_get_ap_records(&number, ap_info);
			if(err != ESP_OK)
			{
				ESP_LOGE(TAG, "esp_wifi_scan_get_ap_records: fail");
			} else {
				ESP_LOGI(TAG, "esp_wifi_scan_get_ap_records: success");
			}
		}
	}
		
	err = esp_wifi_scan_stop();
        if(err != ESP_OK)
        {
                ESP_LOGE(TAG, "Stop scan failed");
        } else {
                ESP_LOGI(TAG, "Stop scan success");
        }
				
	err = esp_wifi_clear_ap_list();
	if(err != ESP_OK)
        {
              ESP_LOGE(TAG, "esp_wifi_clear_ap_list failed");
        } else {
              ESP_LOGI(TAG, "esp_wifi_clear_ap_list success");
         }
}
Regards,
Ritesh Prajapati

Who is online

Users browsing this forum: No registered users and 84 guests