ESP32 with ArduinoIOTCloud throws ''GPIO0: ESP_ERR_TIMEOUT: ADC2 is in use by Wi-Fi''

I´m doing a small project with Arduino iot cloud. I only use a simply code for relays control with an esp32 repo:
My esp32 controller is giving this error:

[430093][E][esp32-hal-adc.c:170] __analogRead(): GPIO0: ESP_ERR_TIMEOUT: ADC2 is in use by Wi-Fi. Please see https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/adc.html#adc-limitations for more info

I found this thread closed a time ago but it diden´t helps me.

I'm not using analog pins. I tried to remove my realys control code and leave only the connection code and still is giving this error.

Please post the entire listing, not just a snippet.

titled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

1 Like

Hi @jhonnyfc
I have posted on this forum before for this bug and I hope this helps you.
The bug is in ...\ArduinoIoTCloud\src\utility\time\NTPUtils.cpp in the function

int NTPUtils::getRandomPort(int const min_port, int const max_port)
{
#ifdef BOARD_HAS_ECCX08
return ECCX08.random(min_port, max_port);
#else
randomSeed(__analogRead(0));
return random(min_port, max_port);
#endif
}

If I am correct, the line randomSeed(__analogRead(0)); is intended to read a random/floating voltage from GIO0 and simply use it as a seed in the next line that returns a random port number.

This is an issue on all my ES32 programs that talk to ArduinoIOCloud.
My work-around is to modify the line to randomSeed(0);
This stops it throwing the error. Since I am not using time functions it doesn't appear to create a problem. However the 'random number' generated will always be the same as it reseeds with the same value every call and takes the first value in the random number sequence.
If that worries you you could comment out the whole line and the random number will be taken as the next value in the sequence.
I use PlatformIO as my IDE which makes finding and 'fixing' this easy. I am not sure how you would do it in Arduino IDE.

Good luck

https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/random.html?highlight=random%20seed

I've made a PR to fix othe ESP related issues and also this will be solved.

Hi @mick3000,
I have the same problem but i cannot locate the file in question. I'm using platform io, could you help with some more detailed instructions on where exactly this file is located?
Thanks!

In your project in Platform IO you should navigate to
Your Project.pio\libdeps\esp32dev\ArduinoIoTCloud\src\utility\time\NTPUtils.cpp
The following code starts at row 93

int NTPUtils::getRandomPort(int const min_port, int const max_port)

{

#ifdef BOARD_HAS_ECCX08

return ECCX08.random(min_port, max_port);

#else

randomSeed(analogRead(0));

return random(min_port, max_port);

#endif

}

I don't know what else I can tell you!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.