Sitelet https://github.com/vortigont/espem/blob/master/docs/BUILD.md
Skip to content

Latest commit

 

History

History
98 lines (74 loc) · 4.16 KB

File metadata and controls

98 lines (74 loc) · 4.16 KB

How to build

The project could be build with PlatformIO. Before building make a hardware connection to PZEM. All the details could be found here.

Steps to run:

  • Configuring and building firmware
  • Making a LittleFS image file with web resources
  • Uploading firmware
  • Uploading LittleFS image

External Libs used to build/use the firmware

  • EmbUI framework is used to construct Web interface, manage WiFi, store configuration, etc
  • pzem-edl event-driven library to interact with PZEM power meter
  • FTPClientServer to access ESP's file system (optional)
  • AmCharts JavaScript Charts & Maps to draw gauges and charts

Configuring and Building

Most of the setup is done via WebUI. Once fw is flashed and FS image uploaded it is required to connect to the WiFI HotSpot and set WiFi options, TimeZone, and PZEM serial port/pins settings. Two platformio env's are provided to build:

To build regular fw for esp32, just run:

platformio run

To build fw with debugging enabled, run:

platformio run -e espem_debug

Remember, you can't use serial0 for PZEM comm if build debug version. Default uart port is port_1. Any available esp32 pins could be mapped to port_1

To build fw with Dummy PZEM emulator, run:

platformio run -e espem_dummy

To upload firmware to MCU, run

platformio run -t upload

or, to upload debug version

platformio run -e espem_debug -t upload

Uploading LittleFS image file with web resources

Firmware needs an FS with web resources to be uploaded to controller before first use. Files to build an FS image from are located under /data folder. Upload FS image with command

platformio run -t uploadfs

That's it. Controller should reboot and enable WiFi. Look for the open Access point names like EmbUI-xxxx, connect to it and open WebUI http://192.168.4.1/, proceed with settings via WebUI. Check USAGE page for more details.

Making a LittleFS image file with web resources (optional)

To handle WebUI it is required to build a LittleFS image and upload it to the controller. The image contains files from the EmbUI framework and js/css files for the ESPEM project. There is a shell script that downloads required files from github, repacks it and places under /data directory. That directory is used to create and upload LittleFS image to the controller. Run

cd resources
./respack.sh

It should populate /data dir with js, css, index.html.gz, etc...

If you are "Windows" user, just install Git for Windows, it will provide you with a Git-bash, run bash ./respack.sh via it's console. Or better learn what is WSL, how to install it and run.

Compressed OTA updates

Uploading updated firmware could be done either via WebUI or curl CLI tool. It is possible to compress images with zlib to reduce upload size, decompression is handled via esp32-flashz lib.

OTA could be intergated to Platformio's scritping, check supplied platformio.ini for OTA template. It needs following options:

  • upload_protocol = custom - enable custom fw uploader
  • upload_port - upload url to access espem
  • upload_flags = compress - use zlib compression on upload

uploading fw with curl CLI

for firmware image

curl -v http://$ESPHOST/update -F "img=fw" -F 'name=@.pio/build/espem/firmware.bin.zz'

for fs image

curl -v http://$ESPHOST/update -F "img=fs" -F 'name=@.pio/build/espem/littlefs.bin.zz'

to compress and upload image on-the-fly with pigz tool

pigz -9kzc .pio/build/espem/firmware.bin | curl -v http://$ESPHOST/update -F "img=fw" -F file=@-
pigz -9kzc .pio/build/espem/littlefs.bin | curl -v http://$ESPHOST/update -F "img=fs" -F file=@-