Wifi not working

josmunpav
Posts: 14
Joined: Tue Sep 20, 2016 5:39 am

Wifi not working

Postby josmunpav » Mon Dec 19, 2016 7:17 pm

Hi all,

I tested my ESP32 with basic WiFi samples and everything was allright. I then moved on and started playing with NVS to store some info which was working great too. Problem is I think I managed to break/corrupt something on the ESP32. When I flash another of those WiFi basic samples, e.g. this one:

Code: Select all

void app_main(void)
{
    nvs_flash_init();
    tcpip_adapter_init();
    ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
    wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
    ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
    ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
    ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
    wifi_config_t sta_config = {
        .sta = {
            .ssid = "********",
            .password = "*******",
            .bssid_set = 0
        }
    };
    ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
    ESP_ERROR_CHECK( esp_wifi_start() );
    ESP_ERROR_CHECK( esp_wifi_connect() );

    gpio_set_direction(GPIO_NUM_4, GPIO_MODE_OUTPUT);
    int level = 0;
    while (1) {
        gpio_set_level(GPIO_NUM_4, level);
        level = !level;
        vTaskDelay(2000 / portTICK_PERIOD_MS);


    }

}
Flash works ok but ESP32 keeps continuosly rebooting. I made menuconfig and turned on any verbosity setting I could see and this is what I am getting:

Code: Select all

I (2545) heap_alloc_caps: Region 19: 3FFC0EA8 len 0001F158 tag 0
I (2555) heap_alloc_caps: Region 25: 3FFE8000 len 00018000 tag 1
I (2565) cpu_start: Pro cpu up.
I (2571) cpu_start: Single core mode
I (2577) cpu_start: Pro cpu start user code
I (2602) rtc: rtc v160 Nov 22 2016 19:00:05
I (2613) rtc: XTAL 40M
D (2628) nvs: nvs_flash_init_custom start=9 count=6
D (2694) phy_init: loading PHY init data from application binary
D (2695) nvs: nvs_open phy 0
D (2696) nvs: nvs_get cal_version 4
D (2716) phy_init: load_cal_data_from_nvs_handle: failed to get cal_version (4354)
D (2786) nvs: nvs_close 1
W (2811) cpu_start: failed to load RF calibration data, falling back to full calibration
V (2892) phy_init: register_chipv7_phy, init_data=0x3f400d5c, cal_data=0x3ffc1f14, mode=2
After that no more logs, just ESP32 rebooting all the time.

Any ideas? I am lost at the moment.

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Wifi not working

Postby kolban » Mon Dec 19, 2016 7:24 pm

It is within the realms of possibility that you have corrupted Non Volatile Storage (NVS) ... this is an area of flash memory that is reserved for the NVS APIs. Since you said you were playing in that area, it is a possibility. The fix is pretty simple. What we will do is reset ALL of SPI flash to its erased state effectively zeroing NVS as well.

The esptool.py is what want to use.

For example:

python esptool.py -p /dev/ttyUSB0 -b 115200 erase_flash

(or something very similar) should work. After that, re-flash your application back into it and try again. Please report back one way or another.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

josmunpav
Posts: 14
Joined: Tue Sep 20, 2016 5:39 am

Re: Wifi not working

Postby josmunpav » Mon Dec 19, 2016 7:56 pm

Thanks for the prompt answer. I tried your command and executed ok:

Code: Select all

$ python esptool.py -p COM3 -b 115200 erase_flash
esptool.py v2.0-dev
Connecting...
Detecting chip type... ESP32
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 2.5s
Unfortunately I still keep getting the same issue after reflashing

josmunpav
Posts: 14
Joined: Tue Sep 20, 2016 5:39 am

Re: Wifi not working

Postby josmunpav » Mon Dec 19, 2016 9:05 pm

Ok some updates. I think the erase flash command did actually work because I can see now the ESP32 connected to my router. However I can hear on Windows how the device restarts twice before connecting to the WiFi, thanks to the annoying Windows notification sound. Not sure why this happens though.

Problem now is I lose Serial connection as soon as the first restart happens so I cannot check what's going on. Any idea on this?

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Wifi not working

Postby ESP_Angus » Mon Dec 19, 2016 10:48 pm

josmunpav wrote:However I can hear on Windows how the device restarts twice before connecting to the WiFi, thanks to the annoying Windows notification sound. Not sure why this happens though.

Problem now is I lose Serial connection as soon as the first restart happens so I cannot check what's going on. Any idea on this?
So, you mean the USB/Serial device is de-enumerating and re-enumerating in Windows? This shouldn't happen based on just the ESP32 restarting, it implies some kind of power stability or USB connectivity problem.

What hardware are you using?

If it's a premade USB development board, try swapping a different USB cable and/or port on your computer.

If it's a bare module, check how it's powered - it may not be getting sufficient power to keep it up during RF calibration and/or WiFi transmission.

josmunpav
Posts: 14
Joined: Tue Sep 20, 2016 5:39 am

Re: Wifi not working

Postby josmunpav » Tue Dec 20, 2016 12:48 am

ESP_Angus wrote:
josmunpav wrote:However I can hear on Windows how the device restarts twice before connecting to the WiFi, thanks to the annoying Windows notification sound. Not sure why this happens though.

Problem now is I lose Serial connection as soon as the first restart happens so I cannot check what's going on. Any idea on this?
So, you mean the USB/Serial device is de-enumerating and re-enumerating in Windows? This shouldn't happen based on just the ESP32 restarting, it implies some kind of power stability or USB connectivity problem.

What hardware are you using?

If it's a premade USB development board, try swapping a different USB cable and/or port on your computer.

If it's a bare module, check how it's powered - it may not be getting sufficient power to keep it up during RF calibration and/or WiFi transmission.
Wow I can't *** believe it :shock: . It was the damn USB cable. I just changed to another one I had around and it is working like a charm. Thanks for pointing me on the right direction I was going mad! To be honest never thought of that, I though my board (official Dev Kit from Espressif) was just mental.

How can a 1 meter USB cable not deliver enough current? How much current does ESP32 need? From what I recall is about 160mA at full power. Any decent USB port should deliver about 500mA at 5V right?

Anyway it is fixed now thanks to you guys. Great community ;-)

ESP_Sprite
Posts: 9708
Joined: Thu Nov 26, 2015 4:08 am

Re: Wifi not working

Postby ESP_Sprite » Tue Dec 20, 2016 1:07 am

It peaks to 500mA during calibration; with an USB cable that has a high resistance (due to eg thin wiring or a bad connection on one of the ends) this can lead to a brownout causing the ESP32 not to work anymore. It's not very common to have a cable that does this, but it does happen, as you noticed.

Who is online

Users browsing this forum: No registered users and 38 guests