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

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • 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.savj...
    (no more than once a month)

ความคิดเห็น • 40

  • @kellyanderson7115
    @kellyanderson7115 2 ปีที่แล้ว +2

    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 2 ปีที่แล้ว

      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.

  • @raspberrypi2475
    @raspberrypi2475 2 ปีที่แล้ว +8

    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.

  • @darktherapy
    @darktherapy 5 หลายเดือนก่อน

    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.

  • @tamnguyenac1268
    @tamnguyenac1268 ปีที่แล้ว +1

    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.

  • @agah7885
    @agah7885 2 ปีที่แล้ว

    Bro, You are the king!

  • @fernandoi8958
    @fernandoi8958 2 ปีที่แล้ว

    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 9 หลายเดือนก่อน

    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".

  • @MI-bm2yy
    @MI-bm2yy ปีที่แล้ว

    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?

  • @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?

  • @svenfischer4557
    @svenfischer4557 ปีที่แล้ว +1

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

    • @syahmiizani757
      @syahmiizani757 ปีที่แล้ว

      I also had this problem when connecting to WiFi blynk, do you find any solution on how to solve the guru errors?

    • @marceloaguilarsanchez9414
      @marceloaguilarsanchez9414 ปีที่แล้ว

      The code worked perfectly in my esp32 NODEMCU

  • @ipatman
    @ipatman ปีที่แล้ว

    Is there anywhere to DL the code?

  • @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.

  • @piconano
    @piconano 3 ปีที่แล้ว +5

    Loved your ESP32 FreeRTOS playlist.

  • @QAYWSXEDCCXYDSAEWQ
    @QAYWSXEDCCXYDSAEWQ 9 วันที่ผ่านมา +1

    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

    • @JanDahl
      @JanDahl 9 วันที่ผ่านมา

      The example working here is in VSCode with PlatformIO and ESP-IDF.

    • @QAYWSXEDCCXYDSAEWQ
      @QAYWSXEDCCXYDSAEWQ 9 วันที่ผ่านมา

      @@JanDahl PlatformIO and ESP-IDF do the same thing?

    • @JanDahl
      @JanDahl 9 วันที่ผ่านมา

      @@QAYWSXEDCCXYDSAEWQ You can use ESP-IDF without PlatformIO but not the other way 'round. They're different tools.

  • @robertb7003
    @robertb7003 3 ปีที่แล้ว +2

    @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 ปีที่แล้ว +2

      Yes, PlatformIO. Check the earlier videos in this series on how to set it up ;)

    • @robertb7003
      @robertb7003 3 ปีที่แล้ว +1

      @@simplyexplained Ok, thanks. You have my sub with notifications

  • @steveread4090
    @steveread4090 7 หลายเดือนก่อน

    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?

  • @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?

  • @SamirRAMDANI-g6j
    @SamirRAMDANI-g6j ปีที่แล้ว

    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.

  • @younesjeihouni
    @younesjeihouni ปีที่แล้ว

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

  • @hansratzingerselbstandiger9786
    @hansratzingerselbstandiger9786 6 หลายเดือนก่อน

    Thank you! Super explained and useful!

  • @kleindavid9416
    @kleindavid9416 5 หลายเดือนก่อน

    Thanks, great explanation!

  • @pellax
    @pellax 2 ปีที่แล้ว

    This video was great, I subscribe inmediately.

  • @mychannel-cm1ce
    @mychannel-cm1ce 3 ปีที่แล้ว +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