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

  Рет қаралды 33,691

Simply Explained

Simply Explained

3 жыл бұрын

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:
• ESP32 + Arduino
(Everything you need to know about programming the ESP32 by using the Arduino Framework)
🌍 Social
Twitter: / savjee
Facebook: / savjee
Blog: savjee.be
❤️ Become a Simply Explained member: / @simplyexplained
💌 Newsletter: newsletter.savjee.be
(no more than once a month)

Пікірлер: 36
@piconano
@piconano 3 жыл бұрын
Loved your ESP32 FreeRTOS playlist.
@raspberrypi2475
@raspberrypi2475 2 жыл бұрын
Move the localIP() to a separate print statement (because its not actually a string) Serial.print("WiFi connected "); Serial.println(WiFi.localIP()); The demo works in the video because it never uses this bit of the code, since its already connected.
@younesjeihouni
@younesjeihouni Жыл бұрын
Appreciate it, fantastic. Also thank you for your excellent explanation in an easily understandable manner.
@pellax
@pellax 2 жыл бұрын
This video was great, I subscribe inmediately.
@hansratzingerselbstandiger9786
@hansratzingerselbstandiger9786 2 ай бұрын
Thank you! Super explained and useful!
@kellyanderson7115
@kellyanderson7115 Жыл бұрын
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(); }
@kellyanderson7115
@kellyanderson7115 Жыл бұрын
Where I did find a separate thread to be very useful was in controlling the color/blink rate of a NeoPixel that I use for status information. The NeoPixel color/blink is set based on an indoor air quality value which I set from the main loop and the NeoPixel control thread uses that to determine what to do. In this case the IAQ getter/setter uses a mutex.
@kleindavid9416
@kleindavid9416 Ай бұрын
Thanks, great explanation!
@agah7885
@agah7885 2 жыл бұрын
Bro, You are the king!
@darktherapy
@darktherapy Ай бұрын
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.
@user-xp3go3zz4g
@user-xp3go3zz4g Жыл бұрын
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.
@tcl78
@tcl78 2 жыл бұрын
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?
@robertb7003
@robertb7003 3 жыл бұрын
@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
@simplyexplained
@simplyexplained 3 жыл бұрын
Yes, PlatformIO. Check the earlier videos in this series on how to set it up ;)
@robertb7003
@robertb7003 3 жыл бұрын
@@simplyexplained Ok, thanks. You have my sub with notifications
@pottingermusic
@pottingermusic 2 жыл бұрын
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
@pottingermusic 2 жыл бұрын
OK, got it: you must do a WiFi.reconnect() then the active AP is not disconnected. Only the STATION is reconnected.
@andrisetianabrata
@andrisetianabrata 2 жыл бұрын
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?
@tamnguyenac1268
@tamnguyenac1268 11 ай бұрын
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.
@steveread4090
@steveread4090 3 ай бұрын
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?
@MI-bm2yy
@MI-bm2yy 8 ай бұрын
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?
@ipatman
@ipatman Жыл бұрын
Is there anywhere to DL the code?
@fernandoi8958
@fernandoi8958 Жыл бұрын
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...
@bestofkings9793
@bestofkings9793 5 ай бұрын
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".
@svenfischer4557
@svenfischer4557 11 ай бұрын
Does anyone else also have problem to get this code running on an esp32-s3? I always get ESP Guru errors.
@syahmiizani757
@syahmiizani757 10 ай бұрын
I also had this problem when connecting to WiFi blynk, do you find any solution on how to solve the guru errors?
@marceloaguilarsanchez9414
@marceloaguilarsanchez9414 8 ай бұрын
The code worked perfectly in my esp32 NODEMCU
@mychannel-cm1ce
@mychannel-cm1ce 3 жыл бұрын
Esp idf already has a task that takes care of reconnection.
@Hercules159
@Hercules159 3 жыл бұрын
What if you have multi wifi - home network, mobile hotspot. will esp idf do it
Adjustable IR Proximity Sensor (ESP32 + Arduino series)
2:58
Simply Explained
Рет қаралды 23 М.
КАРМАНЧИК 2 СЕЗОН 5 СЕРИЯ
27:21
Inter Production
Рет қаралды 552 М.
How many pencils can hold me up?
00:40
A4
Рет қаралды 17 МЛН
How to Multitask with FreeRTOS (ESP32 + Arduino series)
6:25
Simply Explained
Рет қаралды 78 М.
What is FreeRTOS? (ESP32 + Arduino series)
2:36
Simply Explained
Рет қаралды 70 М.
WiFiManager - An Essential ESP32 library!
12:50
Brian Lough
Рет қаралды 29 М.
Why ESP32's Are The Best Microcontrollers (ESP32 + Arduino series)
2:36
Simply Explained
Рет қаралды 245 М.
Deep Sleep & Other Power Modes (ESP32 + Arduino Series)
3:30
Simply Explained
Рет қаралды 20 М.
Nokia 3310 versus Red Hot Ball
0:37
PressTube
Рет қаралды 3,6 МЛН
Samsung vs Apple Vision Pro🤯
0:31
FilmBytes
Рет қаралды 1,4 МЛН
Трагичная История Девушки 😱🔥
0:58
Смотри Под Чаёк
Рет қаралды 373 М.
wyłącznik
0:50
Panele Fotowoltaiczne
Рет қаралды 21 МЛН
Дени против умной колонки😁
0:40
Deni & Mani
Рет қаралды 8 МЛН