ESP32 WiFi Scan doesn't work on Wrover-IB

__vnv__
Posts: 17
Joined: Sat Feb 16, 2019 9:42 pm

ESP32 WiFi Scan doesn't work on Wrover-IB

Postby __vnv__ » Mon Jun 01, 2020 1:00 pm

Hi all!

I am trying to use ESP32 to scan networks. While my code running on ESP32-Wrover-kit works without problem and returns lots of networks, same code od ESP32 Wrover-IB doesn't do that, it only returns one.

What would be the reason that old ESP32 on kit works and new one doesn't.

New ESP32 datasheet: https://hr.mouser.com/datasheet/2/891/e ... 384674.pdf

ESP32 Wrover kit: https://docs.espressif.com/projects/esp ... r-kit.html

Any hint would be great! Tnx in advance.

Here is the code:

Code: Select all

#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/event_groups.h"
#include "esp_wifi.h"
#include "esp_log.h"
#include "esp_event.h"
#include "nvs_flash.h"

/* UART */
#include "driver/uart.h"
#include "driver/gpio.h"
#define BUF_SIZE (1024)
/* UART */

#define DEFAULT_SCAN_LIST_SIZE CONFIG_EXAMPLE_SCAN_LIST_SIZE

#define ECHO_TEST_TXD  (GPIO_NUM_4)
#define ECHO_TEST_RXD  (GPIO_NUM_5)
#define ECHO_TEST_RTS  (UART_PIN_NO_CHANGE)
#define ECHO_TEST_CTS  (UART_PIN_NO_CHANGE)


static const char *TAG = "scan";


void uart_init() {
    const uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE,
        .source_clk = UART_SCLK_APB,
    };
    uart_param_config(UART_NUM_1, &uart_config);
    // - development kit - for testing - //
    uart_set_pin(UART_NUM_1, GPIO_NUM_25, GPIO_NUM_27, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    //uart_set_pin(UART_NUM_1, ECHO_TEST_TXD, ECHO_TEST_RXD, ECHO_TEST_RTS, ECHO_TEST_CTS);
    //uart_set_pin(UART_NUM_1, GPIO_NUM_9, GPIO_NUM_10, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    // We won't use a buffer for sending data.
    uart_driver_install(UART_NUM_1, BUF_SIZE * 2, 0, 0, NULL, 0);
}

int sendData(const char* logName, const char* data)
{
    const int len = strlen(data);
    const int txBytes = uart_write_bytes(UART_NUM_1, data, len);
    //ESP_LOGI(logName, "Wrote %d bytes", txBytes);
    return txBytes;
}


/* Initialize Wi-Fi as sta and set scan method */
static void wifi_scan(void)
{

    char buffer[64];

    ESP_ERROR_CHECK(esp_netif_init());
    ESP_ERROR_CHECK(esp_event_loop_create_default());
    esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
    assert(sta_netif);

    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK(esp_wifi_init(&cfg));

    uint16_t number = DEFAULT_SCAN_LIST_SIZE;
    wifi_ap_record_t ap_info[DEFAULT_SCAN_LIST_SIZE];
    uint16_t ap_count = 0;
    memset(ap_info, 0, sizeof(ap_info));

    ESP_ERROR_CHECK(esp_wifi_set_mode(WIFI_MODE_STA));
    ESP_ERROR_CHECK(esp_wifi_start());

    while(1){
        ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, true));
        ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&number, ap_info));
        ESP_ERROR_CHECK(esp_wifi_scan_get_ap_num(&ap_count));

        ESP_LOGI(TAG, "Total APs scanned = %u", ap_count);
        ESP_LOGI(TAG, "-------------------------------");
        for (int i = 0; (i < DEFAULT_SCAN_LIST_SIZE) && (i < ap_count); i++) {
        
            ESP_LOGI(TAG, "{\"macAddress\":\"%x:%x:%x:%x:%x:%x\",\"signalStrength\": %d}",ap_info[i].bssid[0],
                                                    ap_info[i].bssid[1],            
                                                    ap_info[i].bssid[2],
                                                    ap_info[i].bssid[3],
                                                    ap_info[i].bssid[4],
                                                    ap_info[i].bssid[5],
                                                    ap_info[i].rssi);
        }
        ESP_LOGI(TAG, "-------------------------------");

        vTaskDelay(4000 / portTICK_PERIOD_MS);
    }


}

void app_main(void)
{
   

    // Initialize NVS
    esp_err_t ret = nvs_flash_init();
    if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
        ESP_ERROR_CHECK(nvs_flash_erase());
        ret = nvs_flash_init();
    }
    ESP_ERROR_CHECK( ret );

    
    uart_init();
    wifi_scan();

}

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: ESP32 WiFi Scan doesn't work on Wrover-IB

Postby WiFive » Mon Jun 01, 2020 1:55 pm

Do you have external antenna connected?

__vnv__
Posts: 17
Joined: Sat Feb 16, 2019 9:42 pm

Re: ESP32 WiFi Scan doesn't work on Wrover-IB

Postby __vnv__ » Mon Jun 01, 2020 2:28 pm

Hi,

no I don't, should I have one?

Big tnx for helping out!

__vnv__
Posts: 17
Joined: Sat Feb 16, 2019 9:42 pm

Re: ESP32 WiFi Scan doesn't work on Wrover-IB

Postby __vnv__ » Mon Jun 01, 2020 2:33 pm

BIG THANK YOU!

That's it... added uFL antenna .... instantly all worked fine!

Who is online

Users browsing this forum: No registered users and 154 guests