gbfans / afterlife-lightkit

This is the code repository for the Afterlife Light Kit, coming soon!
GNU General Public License v3.0
1 stars 0 forks source link

[FEATURE] Migration to PlatformIO #17

Open prodestrian opened 1 year ago

prodestrian commented 1 year ago

This has already mostly been implemented in #14 however it is important enough of a change to require its own Issue.

A new platformio.ini file has been created in the repository, containing the settings needed to compile/upload to the ESP8266 D1 Mini Clone on the GBFans Lightkit.

Instructions

  1. Install PlatformIO (either IDE or CLI)
  2. Compile the firmware
  3. Upload firmware to board
  4. Upload Filesystem

Compiling Firmware

cd SOFTWARE/AfterlifeLightKit
pio run

Uploading Firmware to board Connect board via USB

cd SOFTWARE/AfterlifeLightKit
pio run --target upload

Uploading Filesystem to Board Connect board via USB

cd SOFTWARE/AfterlifeLightKit
pio run --target uploadfs
prodestrian commented 1 year ago

GitHub Actions

I now have a working demo of using GitHub Actions to run CI scripts and compile the firmware binary automatically.

Output from last run:

Run pio ci --project-conf=platformio.ini .
********************************************************************************
If you like PlatformIO, please:
- follow us on Twitter to stay up-to-date on the latest project news > https://twitter.com/PlatformIO_Org
- star it on GitHub > https://github.com/platformio/platformio
- try PlatformIO IDE for embedded development > https://platformio.org/platformio-ide
********************************************************************************

Project has been successfully updated!
Processing d1_mini (platform: espressif8266; framework: arduino; board: d1_mini)
--------------------------------------------------------------------------------

(Truncated)

CONFIGURATION: https://docs.platformio.org/page/boards/espressif8266/d1_mini.html
PLATFORM: Espressif 8266 (4.2.0) > WeMos D1 R2 and mini
HARDWARE: ESP8266 160MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 @ 3.30102.0 (3.1.2) 
 - tool-esptool @ 1.413.0 (4.13) 
 - tool-esptoolpy @ 1.30000.201119 (3.0.0) 
 - toolchain-xtensa @ 2.100300.220621 (10.3.0)
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ deep+, Compatibility ~ soft
Library Manager: Installing WiFiManager
Downloading 0% 10% 20% 30%
Unpacking
Library Manager: WiFiManager@0.16.0 has been installed!
Found 41 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Ramp @ 0.6.1
|-- FastLED @ 3.5.0
|-- ArduinoJson @ 6.21.1
|-- WiFiManager @ 0.16.0
|   |-- ESP8266WiFi @ 1.0
|   |-- ESP8266WebServer @ 1.0
|   |-- DNSServer @ 1.1.1
|   |   |-- ESP8266WiFi @ 1.0
|-- LittleFS @ 0.1.0
|-- EEPROM @ 1.0
|-- ESP8266WiFi @ 1.0
|-- ESP8266WebServer @ 1.0
|-- DNSServer @ 1.1.1
|   |-- ESP8266WiFi @ 1.0
Building in release mode

(Truncated)

Retrieving maximum program size .pio/build/d1_mini/firmware.elf
Checking size .pio/build/d1_mini/firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [====      ]  42.6% (used 34876 bytes from 81920 bytes)
Flash: [===       ]  32.3% (used 337191 bytes from 1044464 bytes)
Building .pio/build/d1_mini/firmware.bin
Creating BIN file ".pio/build/d1_mini/firmware.bin" using "/home/runner/.platformio/packages/framework-arduinoespressif8266/bootloaders/eboot/eboot.elf" and ".pio/build/d1_mini/firmware.elf"
========================= [SUCCESS] Took 65.92 seconds =========================

The next step is to store the firmware.bin file as an artifact so that it can be included in a release.

prodestrian commented 1 year ago

Firmware Artifacts

We now store the compiled firmware as an artifact at the end of each build, and the list of build environments is defined in the platformio.ini file.

Currently we only have gbfans_d1_mini_v1, however if newer hardware is ever released we can also include firmware for this (building both at the same time).

Firmware is attached as an Artifact to each Build: 2023-04-08_13-21

For now we can download these firmware files and attach them to releases manually, however we can automate this process later if needed (with each new Git Tag creating a new Draft Release).

prodestrian commented 1 year ago

Update

It looks like it's not easy/possible to include the LittleFS Web assets (HTML, JS, CSS) in the compiled firmware file.

This means that users would need to upload both the firmware AND the filesystem, which is much more complex.

So to simplify this, we will need to compile the filesystem data into the firmware directly.

WLED achieves this by compiling their data directory (web assets) into C header files, which are then loaded into memory. We can do something similar, it just means any changes to those web assets will need to be recompiled before being included in the release. See: https://github.com/Aircoookie/WLED/pull/921

We may be able to include this as part of the GitHub Actions pipelines, ideally so that these class files do not need to be tracked in Git. But this may cause additional issues, so it requires investigation.