Keep WiFi Connection Alive with FreeRTOS Task (ESP32 + Arduino series)

preview_player
Показать описание
Does your ESP32 need a constant WiFi connection? Use a FreeRTOS task to constantly check your connection, and re-establish it when needed.

This code has been super robust for me. I've been using it for my Home Energy Monitor, and it has been running reliably for years.

⚡️Other videos in this series:
(Everything you need to know about programming the ESP32 by using the Arduino Framework)

🌍 Social

(no more than once a month)
Рекомендации по теме
Комментарии
Автор

Move the localIP() to a separate print statement (because its not actually a string)

Serial.print("WiFi connected ");


The demo works in the video because it never uses this bit of the code, since its already connected.

raspberrypi
Автор

Good demo. Always good to see examples of FreeRTOS. It helps convert the beginner to a more advanced level. In my case I can't see where breaking out the WiFi check into a thread would have any advantage and maybe has some disadvantages. At the top of my loop() I call an ensureNetworkConnection() and ensureMqttConnection(). That way I know the the connection should be good after those calls.

void ensureNetworkConnection(void)
{
if ( WiFi.status() != WL_CONNECTED )
connectNetwork();
}

kellyanderson
Автор

It's a very good video ... but i have another point, i think the best way is to create registers for wifi connection.... when wifi connected we suspend the task (to free resources ...etc) and when the wifi is disconnected we resume our task.... i think it's better than keeping the task running for long time and event the wifi is connected.

SamirRAMDANI-gj
Автор

Appreciate it, fantastic. Also thank you for your excellent explanation in an easily understandable manner.

younesjeihouni
Автор

Thank you! Super explained and useful!

hansratzingerselbstandiger
Автор

One thing to note. There’s 2 ADC’s on the esp32. ADC1 and ADC2. ADC2 cannot be used at the same time as using WiFi as they share resources. I found this out the hard way. Continuous spurious results using that ADC2 and WiFi.

darktherapy
Автор

This video was great, I subscribe inmediately.

pellax
Автор

Great video, many thanx. But i have one question. It seems that WiFi.begin() ends an active Wifi AP connection. In my case i want to have the AP of the ESP32 ALWAYS available and only if connection to Router gets lost, reconnect the STATION part. Is this possible or does Wifi.begin() automatically disconnect the active AP?

pottingermusic
Автор

Why to use the WiFi Library do i have to run it on the same core of the Arduino library? Is it true for every library that uses the Arduino framework? For instance, if i use, say, an LCD display with a library developed for Arduino, do i have to make sure it works on the same core? How do i know if a library requires me to do this? Will this not be a problem if i have to use a single core everytime i use libraries from the Arduino framework even though my ESP32 has more cores? Is there a way to bypass this limitation? Is the Arduino framework even necessary? Aren't there native libraries for ESP32 that let me use the cores i like?

tcl
Автор

@Simply Explained You were using VS Code right? How are you uploading to the board without the Arduino ide? Is there some extension that does this? Thanks

robertb
Автор

why use 'continue' instead of just going for an if-else approach? you even explained it like this... I think it would be better for readability purposes, but I might be wrong...

fernandoi
Автор

Why does'nt it print out "Connected! and the IP address", you did not explain that. it just jumps straight to the "WiFi Still Connected".

bestofkings
Автор

For some reason my ESP32 does not boot rather it continuously reboots and I do not know why? I have watched the video many times, started over and recreated the code from the video three times and tried multiple ESP32 boards. Oh, and I tried fixing the core to 0 then one with no change. I really want to use this but how do I fix this?

steveread
Автор

Ouuhhh i see. When i try before i see this video, i trying code some blynk connection without xTaskPinnedToCore its will stacked error. So if i put thats syntaks won't it crash again?

andrisetianabrata
Автор

I uploaded and found Guru Meditation Error: Core 0 panic'ed (LoadProhibited)Exception was unhandled, i tried to fix it but not success. Please help me fix it. I am very appreciate that.

tamnguyenac
Автор

I am having an issue with the wifi:
E (3446) wifi:Expected to init 4 rx buffer, actual is 1
What to do in this case? I used xTaskCreatePinnedToCore but it made the whole code slow and it didn't connect to wifi either?

MI-bmyy
Автор

Does anyone else also have problem to get this code running on an esp32-s3? I always get ESP Guru errors.

svenfischer
Автор

Esp idf already has a task that takes care of reconnection.

mychannel-vo
Автор

Ok, late to the party; but copied this on a Seeed Studio and it simply crashes again and again complaining about a StackOverflow. I am not enjoying freeRTOS

QAYWSXEDCCXYDSAEWQ
visit shbcf.ru