ESP8266 – Lessons Learned
I’ve gotten enough ESP8266 projects under my belt to have a few lessons learned to share with you. The ESP comes in many flavors. One of my favorites is the NodeMCU. I also like the Adafruit Huzzah
WDT Reset Error:
This error was the bane of my existence for quite some time. When experiencing this, you typically see your sketch run and fail. Using the Serial Monitor and carefully placed Serial.println statements, you can usually find the offending loop. The failure is the Watchdog timer. In lay terms, the ESP needs time to perform wifi duties, and often code you write may take up too much CPU time and not allow the ESP to perform these duties.
Although there are likely other causes, I find this issue is almost always fixed by finding the offending loop (for, or other while loops) and ensuring I throw a yield(); statement in there. The general concept is to ensure that no loop runs without calling yield(); every-so-often.
One thing I have learned is to not even try to run the ESP off USB alone. USB at best will give you 500mA of current. Most ESP’s require 300-500mA but it’s the spikes that will cause issues/crashes. It may connect, and may even work, but it will likely cause issues as you add features and functions to your device through code iterations. The ESP won’t tell you it doesn’t have enough power. Instead you will receive all sorts of different errors that are typically unrelated and make you think something else is wrong. The trend I have seen is I typically have project working on USB and start adding features. Then, for no reason, I start getting WDT reset errors, but did nothing more than change the way an LED or other sensor works. The issue is, the sensor/LED would have already been working (all powered by USB), but it must be at the threshold of the USB output current limits. The first thing I do with any of my ESP projects is hook up a 5 (or 3v3) 3A switching power supply up to it.
I haven’t quite figured this one out yet, but a common trend I see with my projects is random freezes. Seemingly for no apparent reason. To date, I cannot find any common reason for it. What I typically do is force the device to restart itself every few hours or so. That tends to clean things up and allow it to keep ticking along. I have done this with my outdoor transmitter part of my Weather Project. The device has been running for 4 months now on solar power without a crash.
If you are not sure what this is, then no need to read on. Otherwise, you have likely discovered Blynk. I love this product! However, one thing I have found is that it can be a bit temperamental with complex projects. My Weather IoT project is the most complex I have done so far. It uses Blynk to pass data from an outdoor (temp/humidity) transmitter as well as my garage door monitor, and hot tub temperature monitor to the master unit – and they talk back-and-forth. What I find however is that the process Blynk uses for updating data (BLYNK_WRITE) on the receiving device fails – but for only some features. It also crashes in such a way that you get no messaging. However, removing the BLYNK_WRITE corrects it. To date, I am still dealing with this. Oddly it works fine for data being received from my weather transmitter unit, but using the same approach (getting temp from my hot tub) fails. I’ll update this once I find the solution.
As I continue to use ESP devices, I will update this post with new information with hopes that it helps others, as well as myself (given I will forget!).