Core 1 loop slow down, when WiFi connects
Posted: 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);
}
}