Core 1 loop slow down, when WiFi connects

flamy69
Posts: 7
Joined: Fri Sep 10, 2021 7:08 am

Core 1 loop slow down, when WiFi connects

Postby flamy69 » Sun Sep 12, 2021 12:39 pm

Hi, I found issue in my code and I can not find reason, why it is happening. I reduced my project to bare minimum and it still happening. I call WiFi.begin(ssid, password); and after second or two, when wifi connections is established (ESP32 is STA and connect to my home AP) Main loop lasts 1930 us, normaly it last about 1us. I have -D WIFI_TASK_CORE_ID=0 and I do not know and can`t find anything else, what I should do to prevent this behaviour. Thank you very much in advance for any advice.

Code: Select all

// Import required libraries
#include <iostream>
#include <string>
#include <WiFi.h>

// Replace with your network credentials
static const char* ssid = "ssid";
static const char* password = "password";

void setup()
{
  pinMode(2, OUTPUT);

  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
 }


static uint64_t _next_led_blink = 0;
static bool _last_state_of_led = false;
static volatile uint32_t _longest_main_loop = 0;
void loop()
{
  uint64_t main_loop_start_us = micros();

  if (main_loop_start_us > _next_led_blink)
  {
    _next_led_blink = main_loop_start_us + 1000000;
    digitalWrite(2, !_last_state_of_led);
    _last_state_of_led = !_last_state_of_led;
  }

  uint32_t length_of_main_us = micros() - main_loop_start_us;
  if (length_of_main_us > _longest_main_loop)
  {
    _longest_main_loop = length_of_main_us;
    printf("Longest main loop %lu us\n", _longest_main_loop);
  }
}

flamy69
Posts: 7
Joined: Fri Sep 10, 2021 7:08 am

Re: Core 1 loop slow down, when WiFi connects

Postby flamy69 » Mon Sep 13, 2021 8:35 am

Now I suspecting
https://docs.espressif.com/projects/esp ... dling.html
->
https://docs.espressif.com/projects/esp ... p_handle_t

But I didnt find any possibility, how to pin even handling to different CORE. And 2ms for me is not problem, but sometimes when wifi connects main loop lasts 30ms, and that is problem for me. And I can not tell, when it will be 2ms and when it will be 30ms. If I restart esp32 10 times, 8 times it takes 2 ms, 2 times it takes 30ms.

And I know, that it happens when WiFi connects, because I tested it as well with

Code: Select all

WiFi.onEvent(Get_IPAddress, SYSTEM_EVENT_STA_GOT_IP);

and main loop last longer almost exactly at the moment of calling this event.

flamy69
Posts: 7
Joined: Fri Sep 10, 2021 7:08 am

Re: Core 1 loop slow down, when WiFi connects

Postby flamy69 » Mon Sep 13, 2021 9:05 am

And I changed in sdkconfig.h this. And it did not help as well:

Code: Select all

#define CONFIG_ARDUINO_EVENT_RUNNING_CORE 1  -> 0
#define CONFIG_ARDUINO_EVENT_RUN_CORE1 1 -> #define CONFIG_ARDUINO_EVENT_RUN_CORE0 1
#define CONFIG_ARDUINO_UDP_RUN_CORE1 1 -> #define CONFIG_ARDUINO_UDP_RUN_CORE0 1
#define CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT -1 -> #define CONFIG_ESP32_PTHREAD_TASK_CORE_DEFAULT 0
#define CONFIG_ARDUINO_UDP_RUNNING_CORE 1 -> 0

alpignolo
Posts: 1
Joined: Fri Sep 02, 2022 1:55 pm

Re: Core 1 loop slow down, when WiFi connects

Postby alpignolo » Fri Sep 02, 2022 1:56 pm

Hi,
i have the same problem when connecting wifi. Were you able to solve?

Who is online

Users browsing this forum: No registered users and 88 guests