Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- name: Set configs
run: |
cp config_default.h config.h
cp secret_default.h secret.h

- name: Compile Arduino project
run: |
Expand Down
43 changes: 40 additions & 3 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,47 @@ jobs:

- name: Set configs (Windows)
shell: powershell
run: |
$env:CONFIG_H | Out-File -Encoding ascii config.h
env:
CONFIG_H: ${{ secrets.CONFIG_H }}
SECRETS_SHARE_PATH: ${{ secrets.SECRETS_SHARE_PATH }}
SECRETS_SHARE_USER: ${{ secrets.SECRETS_SHARE_USER }}
SECRETS_SHARE_PASS: ${{ secrets.SECRETS_SHARE_PASS }}
SECRETS_REPO_NAME: ${{ secrets.SECRETS_REPO_NAME }}
DEVICE_NAME: LSSensor
run: |
$ErrorActionPreference = 'Stop'
$secretsDir = Join-Path $env:RUNNER_TEMP 'secrets'
$mounted = $false

try {
# Mount SMB share with read-only credentials
& net.exe use 'Z:' $env:SECRETS_SHARE_PATH /user:$env:SECRETS_SHARE_USER $env:SECRETS_SHARE_PASS | Out-Null
if ($LASTEXITCODE -ne 0) { throw "Failed to mount SMB share (exit $LASTEXITCODE)" }
$mounted = $true

# Clone Configuration repo from the share
if (Test-Path $secretsDir) { Remove-Item $secretsDir -Recurse -Force }
$repoSource = if ($env:SECRETS_REPO_NAME) { "Z:\$env:SECRETS_REPO_NAME" } else { 'Z:\' }
git clone --depth=1 $repoSource $secretsDir
if ($LASTEXITCODE -ne 0) { throw "git clone failed (exit $LASTEXITCODE)" }

# Run per-device deploy script
$deployScript = Join-Path $secretsDir "$env:DEVICE_NAME\deploy.ps1"
if (-not (Test-Path $deployScript)) { throw "deploy.ps1 not found at $deployScript" }

& $deployScript -OutputDir $env:GITHUB_WORKSPACE
if ($LASTEXITCODE -ne 0) { throw "deploy.ps1 failed (exit $LASTEXITCODE)" }
}
finally {
# Always clean up - whether the try block succeeded, threw, or was interrupted
if (Test-Path $secretsDir) {
Remove-Item $secretsDir -Recurse -Force -ErrorAction SilentlyContinue
}
if ($mounted) {
& net.exe use 'Z:' /delete /yes | Out-Null
}
# cleanup is best-effort; do not fail the step on a stale exit code
$global:LASTEXITCODE = 0
}

- name: Compile Arduino project
run: |
Expand Down
1 change: 1 addition & 0 deletions LSSensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <MQTTClient.h>
#include <SoftwareSerial.h>
#include "config.h"
#include "secret.h"
#include <avr/wdt.h>

#define LSSensorPIN1 2
Expand Down
10 changes: 1 addition & 9 deletions config_default.h
Original file line number Diff line number Diff line change
@@ -1,9 +1 @@
#define WifiSSID "WifiSSID"
#define WifiPassword "WifiPassword"
#define MQTTUsername "MQTTUsername"

#define MQTTPassword "MQTTPassword"

#define MQTTHost "MQTTHost"

#define ELCONSUMPTION "ELCONSUMPTION"
#define ELCONSUMPTION "ELCONSUMPTION"
5 changes: 5 additions & 0 deletions secret_default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define WifiSSID "WifiSSID"
#define WifiPassword "WifiPassword"
#define MQTTUsername "MQTTUsername"
#define MQTTPassword "MQTTPassword"
#define MQTTHost "MQTTHost"
Loading