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
11 changes: 7 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ jobs:

- name: Set configs
run: |
cp config_default.h config.h
cp secret_default.h secret.h
cp ./src/Arduino/config_default.h ./src/Arduino/config.h
cp ./src/Arduino/secret_default.h ./src/Arduino/secret.h
cp ./src/ESP32/config_default.h ./src/ESP32/config.h
cp ./src/ESP32/secret_default.h ./src/ESP32/secret.h

- name: Compile Arduino project
- name: Compile
run: |
arduino-cli compile --profile LSSensor_Uno ./
arduino-cli compile ./src/Arduino
arduino-cli compile ./src/ESP32
8 changes: 4 additions & 4 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy LS Sensor on Environment
name: Deploy Arduino LS Sensor on Environment

on:
workflow_dispatch:
Expand All @@ -18,10 +18,10 @@ permissions:

jobs:
deployment:
uses: Zefek/GithubActions/.github/workflows/arduino-build-deploy.yml@v1
uses: Zefek/GithubActions/.github/workflows/arduino-build-deploy.yml@c2872a07ea6ff49f3105cf3b8faef0e7169236c7
with:
environment: ${{ inputs.environment }}
serial_port: ${{ inputs.serial_port }}
device_name: LSSensor
source_dir: "."
device_name: LSSensorArduino
source_dir: "./src/Arduino"
secrets: inherit
98 changes: 98 additions & 0 deletions .github/workflows/deployment_esp32.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Deploy LS Sensor ESP32 on Environment

on:
workflow_dispatch:
inputs:
serial_port:
required: false
type: string
environment:
required: true
type: choice
options:
- Home

permissions:
contents: read

jobs:
deployment:
runs-on: [self-hosted, iot]
environment: ${{ inputs.environment }}
env:
REPO: ${{ vars.REPO }}
steps:

- name: Checkout repository
uses: actions/checkout@v7

- name: Install required board core
run: |
& "$Env:RUNNER_TOOL_CACHE\arduino-cli\arduino-cli.exe" --config-file config.yaml core update-index


- uses: zefek/GithubActions/Actions/deployConfig@c2872a07ea6ff49f3105cf3b8faef0e7169236c7
with:
repo: ${{ env.REPO }}
auth: ${{ secrets.REPO_TOKEN }}
dest: ${{ runner.temp }}\secrets
device: LSSensorESP32
outdir: ${{ github.workspace }}\src\ESP32

- name: Compile Arduino project
run: |
& "$Env:RUNNER_TOOL_CACHE\arduino-cli\arduino-cli.exe" --config-file config.yaml compile ./src/ESP32 --output-dir build --build-property "compiler.cpp.extra_flags=-DFW_VERSION=${{ github.run_number }}"

- name: Upload firmware to Arduino
if: ${{ github.event.inputs.serial_port != '' }}
run: |
$port = "${{ github.event.inputs.serial_port }}"
& "$Env:RUNNER_TOOL_CACHE\arduino-cli\arduino-cli.exe" --config-file config.yaml upload ./src/ESP32 --port $port --input-dir build

- name: Uložení firmware
if: ${{ github.event.inputs.serial_port == '' }}
shell: powershell
env:
FIRMWARE_TARGET_PATH: ${{ vars.FIRMWARE_TARGET_PATH }}
FW_VERSION: ${{ github.run_number }}
GIT_SHA: ${{ github.sha }}
run: |
$ErrorActionPreference = 'Stop'
if (-not $env:FIRMWARE_TARGET_PATH) { throw "FIRMWARE_TARGET_PATH variable is not set" }

$buildDir = Join-Path $env:GITHUB_WORKSPACE 'build'
$version = $env:FW_VERSION

# Aplikační image pro OTA (ESP32 nahrává *.ino.bin, ne bootloader/partitions)
$appBin = Get-ChildItem -Path $buildDir -Filter '*.ino.bin' -File | Select-Object -First 1
if (-not $appBin) { throw "Application firmware (*.ino.bin) not found in $buildDir" }

# 1) Historie: celý build do podadresáře pojmenovaného verzí
$versionDir = Join-Path $env:FIRMWARE_TARGET_PATH $version
New-Item -ItemType Directory -Path $versionDir -Force | Out-Null
Copy-Item -Path "$buildDir\*" -Destination $versionDir -Recurse -Force

# 2) OTA: pevná cesta na poslední firmware + manifest
if (-not (Test-Path $env:FIRMWARE_TARGET_PATH)) {
New-Item -ItemType Directory -Path $env:FIRMWARE_TARGET_PATH -Force | Out-Null
}
$latestBin = Join-Path $env:FIRMWARE_TARGET_PATH 'firmware.bin'
Copy-Item -Path $appBin.FullName -Destination $latestBin -Force

$hash = (Get-FileHash -Path $latestBin -Algorithm SHA256).Hash.ToLower()
$size = (Get-Item $latestBin).Length

# Jednoduchý key=value manifest – ESP32 ho rozparsuje bez JSON knihovny
$manifest = @(
"version=$version"
"file=firmware.bin"
"size=$size"
"sha256=$hash"
"commit=$($env:GIT_SHA)"
)
$manifestPath = Join-Path $env:FIRMWARE_TARGET_PATH 'manifest.txt'
# LF konce řádků a bez BOM – snazší parsování na zařízení
[System.IO.File]::WriteAllText($manifestPath, ($manifest -join "`n") + "`n")

Write-Host "Firmware verze $version uložen do $versionDir; OTA: $latestBin (manifest $manifestPath)"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
config.h
secret.h
10 changes: 7 additions & 3 deletions LSSensor.ino → src/Arduino/Arduino.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ int wattMetter2Counter = 0;
unsigned long lastSendToMQTT = 0;
unsigned long lastTime = 0;
bool closeRequired = false;
bool initialZeroSent = false;

#pragma pack(push, 1)
struct DiagData {
Expand Down Expand Up @@ -143,8 +144,12 @@ void loop() {
detachInterrupt(digitalPinToInterrupt(LSSensorPIN2));
if(Connect())
{
sprintf(data, "{\"V\":%d,\"S\":%d}", 0, 0);
mqttClient.Publish(ELCONSUMPTION, data);
if(!initialZeroSent)
{
sprintf(data, "{\"V\":%d,\"S\":%d}", 0, 0);
mqttClient.Publish(ELCONSUMPTION, data);
initialZeroSent = true;
}
sprintf(data, "{\"V\":%d,\"S\":%d}", wattMetter1Counter, wattMetter2Counter);
mqttClient.Publish(ELCONSUMPTION, data);

Expand All @@ -156,7 +161,6 @@ void loop() {
currentDiagData.rssi = espDrv.GetRssi();
mqttClient.Publish(LSSENSOR_DIAG, (const uint8_t*)&currentDiagData, sizeof(DiagData), false);
currentDiagData.loopMaxMs = 0;
mqttClient.Disconnect();
}
lastSendToMQTT = currentMillis;
attachInterrupt(digitalPinToInterrupt(LSSensorPIN1), WattMetter1Received, RISING);
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions sketch.yaml → src/Arduino/sketch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ profiles:
platforms:
- platform: arduino:avr (1.8.7)
libraries:
- dir: MQTTESP8266
default_profile: LSSensor_Uno
- dir: ../../MQTTESP8266
default_profile: LSSensor_Uno
Loading
Loading