Skip to content

Commit

Permalink
add /reset and ota updates workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmarcano committed Aug 9, 2023
1 parent 56592c1 commit 93b32f4
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 15 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ jobs:
- name: Checkout
uses: actions/checkout@v2

# - name: Load environment variables
# run: |
# mv src/env-template.h src/env.h

- name: Installing platformio
run: pip3 install -U platformio

Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/ota-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: ESP32 OTA update

on:
# push:
# branches:
# - 'master'
workflow_dispatch:

jobs:
build:
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Connecting the GitHub workflow to Husarnet VPN network
uses: husarnet/husarnet-action@v2
with:
join-code: ${{ secrets.HUSARNET_JOIN_CODE }}

- name: ESP32 software reset
run: curl -X POST 'http://${{ secrets.HUSARNET_HOSTNAME }}:80/reset'

- name: Installing platformio
run: pip3 install -U platformio

- name: Building a firmware for ESP32
run: |
export SSID=${{ secrets.WIFI_SSID }}
export PASS=${{ secrets.WIFI_PASS }}
export JOINCODE=${{ secrets.HUSARNET_JOIN_CODE }}
export HOSTNAME=${{ secrets.HUSARNET_HOSTNAME }}
pio lib install
pio run
- name: Uploading a firmware to ESP32
run: >
curl --http0.9 -# -v
-H 'Accept: */*'
-H 'Accept-Encoding: gzip, deflate'
-H 'Connection: keep-alive'
-F "MD5="$(md5sum "${{ github.workspace }}/.pio/build/esp32doit-devkit-v1/firmware.bin" | cut -d ' ' -f 1)""
-F 'firmware=@${{ github.workspace }}/.pio/build/esp32doit-devkit-v1/firmware.bin'
'http://${{ secrets.HUSARNET_HOSTNAME }}:80/update'
- name: Stop Husarnet
run: sudo systemctl stop husarnet
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
</p>
<p align="center">
<a href="https://github.com/gabrielmarcano/esp32-roaster/blob/master/.github/workflows/build.yml">
<img alt="Build" src="https://img.shields.io/github/actions/workflow/status/gabrielmarcano/esp32-roaster/build.yml">
<img alt="Build" src="https://img.shields.io/github/actions/workflow/status/gabrielmarcano/esp32-roaster/build.yml?logo=github">
</a>
<a href="https://github.com/gabrielmarcano/esp32-roaster/blob/master/.github/workflows/ota-update.yml">
<img alt="OTA Update" src="https://img.shields.io/github/actions/workflow/status/gabrielmarcano/esp32-roaster/ota-update.yml?logo=github&label=OTA">
</a>
<a href="https://github.com/gabrielmarcano/esp32-roaster/releases">
<img alt="GitHub release" src="https://img.shields.io/github/v/release/gabrielmarcano/esp32-roaster?filter=*alpha&logo=github">
Expand Down Expand Up @@ -49,18 +52,18 @@ There will also be two buttons, one will add +1min to the time (and start the ti

The project structure is as follows:

| Resource | Description |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [src/](src) | The [main.cpp](/src/main.cpp) file with the code to be uploaded to esp32 |
| [data/](data) | Static files written directly to the SPI flash file storage (SPIFFS) |
| [lib/](lib) | All additional libraries. Core libraries are installed via PlatformIO or written in **lib_deps** using the [platformio.ini](platformio.ini) file |
| [server/](server) | [Express](https://expressjs.com/) server for debugging |
| [platformio.ini](platformio.ini) | PlatformIO project configuration file |
| [env.h](src/env.h) | Env vars file used to get the credentials for WiFi & VPN |
| Resource | Description |
| ------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| [src/](src) | The [main.cpp](/src/main.cpp) file with the code to be uploaded to esp32 |
| [data/](data) | Static files written directly to the SPI flash file storage (SPIFFS) |
| [lib/](lib) | All additional libraries. Core libraries are installed via PlatformIO or written in **lib_deps** using the [platformio.ini](platformio.ini) file |
| [server/](server) | [Express](https://expressjs.com/) server for debugging |
| [platformio.ini](platformio.ini) | PlatformIO project configuration file |
| [env-template.h](src/env-template.h) | Env vars template file used to get the credentials for WiFi & VPN |

### Envionment Variables

Use env vars to store your credentials.
Use env vars to store your credentials and build the firmware locally.

1 - Run the command: `mv src/env-template.h src/env.h`

Expand Down Expand Up @@ -105,9 +108,12 @@ OTA updates are available thanks to [ElegantOTA](https://github.com/ayushsharma8
| /data | **GET** - Request to update the temperature & humidity readings, timer remaining time and motors states on the web interface |
| /motors | **POST** - Request to control the state of the motors throught the web interface |
| /update | Firmware & Filesystem OTA updates |
| /reset | Perform a remote software reset of the ESP32 |
### VPN
> TODO: This is not implemented yet
The ESP32 is connected to a VPN using [Husarnet](https://github.com/husarnet/husarnet-esp32). With this, the web interface can be accessed remotely, and it also enables simple remote OTA updates.
## Wiring
Expand Down
8 changes: 7 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#else

// For GitHub Actions OTA deployment
// For GitHub Actions

// WiFi credentials
#define WIFI_SSID WSSID
Expand Down Expand Up @@ -174,6 +174,12 @@ void initServer()

server.serveStatic("/", SPIFFS, "/");

// HTTP API for remote reset
server.on("/reset", HTTP_POST, [](AsyncWebServerRequest *request)
{
request->send(200, "text/plain", "Reseting ESP32...");
ESP.restart(); });

// Request for the latest sensor readings
server.on("/data", HTTP_GET, [](AsyncWebServerRequest *request)
{
Expand Down

0 comments on commit 93b32f4

Please sign in to comment.