ESP32 Unleashed – Course update 

 February 17, 2022

By  Peter

We have published an update to ESP32 Unleashed that aim to improve the overall reliability of the gadget.

Here’s the list of improvements:

  • Prevent competition for the TFT screen by implementing a simple semaphore system.
  • Replaced the original timer-based watchdog with the native ESP32 Task Watchdog Timer.
  • Added a cloud logger so that operational data are recorded in my Adafruit IO dashboard.
  • Bumped Espressif32 framework version to 3.5.0

Here’s some details about these changes.

TFT screen call conflicts

Semaphores is a simple way to prevent conflicting calls to a shared resource in multi-tasking systems. The ESP32 32 runs user sketches in a single core, so it is practically a single-tasking system. Therefore, I admit that implementing a semaphore is a bit of an overkill. But still, this was an opportunity to become familiar with semaphores via a trivial implementation that depends on a single “access variable”.

Once you understand the semaphore principle of use, you will be able to use it to control access to any shared resource, such as a network connection, a file, a screen, or a sensor.

Task Watchdog Timer

Originally, I used a timer-based watchdog from the Arduino framework (see base example) that would reset the ESP32 if the timer was not reset within a certain time limit. In practice, I found that this type of watchdog did not work as expected. The timer-based watchdog depends on the timer (in the sketch, I used Timer 0) to continue to operate, and to be able to call an interrupt service routine (ISR) if it expired. The ISR contained a call to esp_restart() which would reset the ESP32.

I found that when certain conditions occur, usually relating to WiFi, the timer-based watchdog seems to “hang”, along with everything else, and as a result it is unable to reset the ESP32.

I found a better way to do this: use the ESP-IDF dedicated watchdog. The ESP-IDF framework provides two different ways to use this watchdog. I chose the Task Watchdog Timer (TWDT) because it can be controlled programmatically. This watchdog will work even when WiFi “hangs”. It’s implementation is even simpler then the original timer-based interrupt method, which is an extra bonus of this approach.

My test ESP32 gadget running the new firmware with the task watchdog timer has been running without any problems for more than two weeks now. Cloud log data show that the TWDT did in fact reset the gadget a couple of times during these two weeks. I did not need to reset the device manually, which is the goal of the watchdog approach.

Cloud logger

I power my ESP32 test gadget from a USB power supply instead of a computer. As a result, I can’t see any serial port output to help me with debugging. In addition, glitches (like a “hanged” WiFi connection) may happen at random times.

Device operations log in my cloud dashboard.

I thought it would be nice to keep a log of basics operational statistics on the Cloud, and to be able to export as a CSV file for later analysis.

I already have the tools to do this, so I used them. In this iteration of the firmware, I added a logger feed that reports the gadget’s current report cycle to my Adafruit IO dashboard. From there, I can record several days worth of data, and export as CSV or JSON.

I can export the cloud log as a CSV file for analysis. This log contains report cycle numbers and timestamps.

Espressif32 framework version 3.5.0

While I worked on the above updates, I also upgraded the project Espressif32 framework from 3.4.0 to 3.5.0. It seems solid, and there are no issues to report.

You will find the new lectures in section 31, “Updates” (you will need to login first). If you are not enrolled to this course, you can do so here.


Course update

You may also like

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

In this Maker Mind Meld summit presentation, Dal Gemmell talks about a new generation of wireless networks, based on cutting-edge blockchain technology, that delivers a new kind of open, decentralized wireless network built by individuals

Read More
Dal Gemmell – A blockchain-powered decentralized network owned by you

Happy New Year! The turn of a year is an opportunity to reflect (look back) and plan (look forward). 2022 was another challenging year in many respects, and 2023 will be no less challenging. However,

Read More
Start 2023 with Tech Explorations