A quick post regarding updating platforms and libraries for projects, specifically projects for the ESP8266 platforms:
The PZEM004T is device available on eBay and other sites, that allows to measure energy consumption. The PZEM004T has a serial output port and when connecting it to, for example, an ESP8266, we can access the collected data trough WIFI and process it for finding out how much electricity we are using, and so on.
Anyway, when using the ESP8266 WEMOS D1 mini, to be able to still use the USB serial port, we need to use Software serial emulation. In fact the Arduino PZEM004T library available on Github and on the Platformio library registry allows the use of the Software Serial to communicate with the PZEM004T (and it works just fine).
So what is the issue?
I’m using Platformio to develop the ESP8266 application, and normally when running, it checks and offers any updates that might be available. So, I’ve updated to the latest Espressif ESP8266 platform and ESPSoftwareSerial, and then everything just break down:
- ESPSoftwareSerial last version just completely breaks the previous existing API which made the PZEM004T library also broken.
- The new ESP8266 platform removes Esp8266 a SDK attachInterruptArg function which renders the ESPSoftwareSerial library unbuildable
The solution with Platformio is quite easy: use semantic versioning.
In fact something like this on the platformio.ini file:
[env:d1_mini] platform = espressif8266 ... ...
can be locked to a working previous version:
[env:d1_mini] platform = firstname.lastname@example.org ... ...
The same can be done with the project libraries. While the ESPSoftwareSerial (the PZEM004T dependency loads it) does not need to be defined, specifying it allows to use a specific version:
[env:d1_mini] platform = email@example.com board = d1_mini_lite framework = arduino upload_speed = 921600 monitor_speed = 115200 lib_deps = ESPSoftwareSerial@5.0.3 PZEM004T MQTT LiquidCrystal_I2C SimpleTimer ESPAsyncTCP ESP Async WebServer Time
And with this, the ESP8266 platform and ESPSoftwareSerial versions locked, the issues with the newer versions are avoided, and the code compiles and works as it should.
So, updating is fine, but when it breaks it can be an issue. Fortunately Platformio allows the usage of specific version for building our projects, and even allows to deploy our specific library version under the project lib directory.