In this post I’m going to show you how you can monitor the power consumption of your battery driven (ESP8266/ ESP32) device. Measuring the power consumption over a full activity/ sleep cycle is the precondition to optimize your code for a longer battery runtime. Only with a reliable tool you can decide which code changes lead to less consumption. In a later post we’ll look at some tweaks we can apply to the code to get a few more days out of the battery.
As a long time professional Java developer I’m used to write applications that run on servers with lots of resources: RAM, disk space and energy consumption are rarely a limiting factor for the software we write. Developing software for embedded devices is a totally different story: memory both for flash and heap is very limited. And if you want to run your device from battery every second you are staying online counts towards the total energy bill of your battery. In our big server applications we usually say that you should first write reliable and readable code.
If your application is not fast enough or consumes too much memory you start tuning the hot spots of your code until you get the desired results. Of course, it’s really hard to turn a bad decision in your architecture into a fast performing application. I would say that these rules are also true for embedded devices: first write reliable and readable code, then start tuning. And avoid costly dead ends which are later hard to fix.
In my opinion you can’t tune a system if you don’t have reliable measurements before and after you change any factor. So how do you collect this information in an embedded device? That of course depends on what aspect you would like to improve: memory, battery runtime, connection speed, etc. In this post I’m interested in prolonging the battery life of the ESPaper.
Read more: ESP8266: Monitoring Power Consumption