This post is part of a series
- 1/3 PlatfomIO overview & compiling + uploading locally and on a Raspberry Pi
- 2/3: Continuous testing and auto release binary generation using PlatformIO & TravisCI
- 3/3: Continuous Deployment (OTA to ESP8266)
Groan…I know I just used the clichéd ‘C’ word, however there are many advantages to compiling and testing the code in the cloud. At least I didn’t mention ‘IoT’…whoops, just doing my bit for SEO!
In this instance when we say ‘compile in the cloud’ I mean use GitHub, Travis IO and PlatfromIO to compile the firmware and if the branch is tagged with a ‘Git Release’ auto-generate a compiled binary and upload it back to GitHub release page.
The motivation behind this automated-build and testing is working towards creating a robust infrastructure to push OTA updates to ESP8266 connected nodes (EmonESP dev) inspired by this blog post by Daniel Eichhorn (@squix78).
The advantages of continuous testing have been long established in the software industry. The test we are performing is ‘does this firmware compile?’; obviously this is not a comprehensive test but it will at least give us confidence that there are no syntax errors etc. To actually test operation of embedded firmware, physical hardware (or simulation) would be required.
How it works
- A commit or pull request is made to the firmware repository on GitHub
- To date emonPi, emonTx and EmonESP repositories have been enabled for continuous build & test
This triggers Travis CI to start a ‘build’
- Code compilation is generated using platformIO in the same way as when compiling locally, See blog post. The
.travis.ymlfile in the repo configures the Travis CI build using platformIO:
language: python python: - '2.7' sudo: false cache: directories: - "~/.platformio" install: - pip install -U platformio script: - platformio run -d firmware -e emonpi_deploy deploy: on: repo: openenergymonitor/emonpi all_branches: true condition: $TRAVIS_TAG =~ ^[0-9]+\.[0-9]+\.[0-9]+$ skip_cleanup: true provider: releases overwrite: true api_key: secure: OzNwxsQEVlSj2e4sOqKNYlNXqPqc5myL0nOBtY1FYD+sbxslHMixmlRASWuFMCjHdpFYQST2IuR3UMCPCjfPzMDVCVtsJ8VPd299fgDGzmEnL3P5Z8wCAv1CfHURcfXzFJDM7prevGx9cfz8uAiwIaNOhbTL7kL2GfSatV5PERzr2ytVh6WUj650Rd7bLKKhj8YHOzO9wOBoKDadYDFF99XYQbDDoHj9pAv+OPG76X0kWrdrq/0w26jh7JZaxrwhF/xD7maGaEjLOa/FcXbyZlVy/JIFjyrKp79swzVNSFNox/CbF7e6tzBf3NhZsoQyEchnCrgWw8IB7j/Ja7Ypetn6IG7C5rT/h46rWrZshbVdw7ZBUzhNJIUVLHFBy7hi2hxMw9Bn+oCt0UWLt8SnQnRfAbjw+z3XQ2/6MccUAINKGDqd4fm9M85sN6drpXySeJ/ZyRkdlUN0xsDpARI05mYLLlCutRzlSCkglbsKJr5XM7h7pXHLUQY5dfw9LrA788w25OBoO9U8vCKtoV8UCXWh6og/364CRl9Uih958f1t7kHIvfwLJjwSDFYVxUsyvSFyjfY+pIfuGEXtgIqMZ87nK3O1vAb9udbPErp0q5kJBeks9Df6wVsvjI7O++7YwiSuWlJBD0x45ZV9pxOFLnWb1hetHpPH5kFgBlTDqsY= file: "firmware/.pioenvs/emonpi_deploy/firmware.hex"
- If the build fails for whatever reason (syntax error, library error etc) then the green
build passingicon changes to a ominous red
build Failedand we get an alert email. For a full build log example see the emonPi Travis CI build page.
- If the GitHub branch is tagged with a ‘release tag’ and compilation is successful then the generated
.binis uploaded to the GitHub release page:
Stay tuned for part 3/3 of the PlatformIO firmware work-flow post series, which will cover auto deploying (OTA) the compiled firmware release onto an ESP8266. For a sneak peak checkout this excellent blog post which was a source of inspiration and information.
To engage in discussion regarding this post, please post on our Community Forum.