Compare commits

...

18 Commits

Author SHA1 Message Date
Hermes
27e8d25fac fix: publish raw OTA files to rolling release with backup artifacts
All checks were successful
OTA build / build-ota (push) Successful in 2m25s
2026-08-30 18:19:12 -05:00
Hermes
e7b9398d04 fix: use upload-artifact v3 for Gitea compatibility
All checks were successful
OTA build / build-ota (push) Successful in 2m50s
2026-08-30 14:45:59 -05:00
Hermes
bb087d10c4 fix: switch OTA delivery to direct attached artifacts
Some checks failed
OTA build / build-ota (push) Failing after 2m11s
2026-08-30 12:10:03 -05:00
Hermes
2920809d23 fix: make OTA workflow YAML valid and remove debug files
Some checks failed
OTA build / build-ota (push) Failing after 2m9s
2026-08-30 10:30:09 -05:00
Hermes
ae5a9d572a ci: trigger OTA verification 2026-08-30T02:53:27Z 2026-08-29 21:54:39 -05:00
Hermes
27c323f1e1 ci: trigger direct OTA push verification 2026-08-29 19:00:14 -05:00
Hermes
e9511999e7 ci: publish direct OTA files via package registry 2026-08-29 18:28:37 -05:00
Hermes
4c90c1075c ci: add OTA build workflow
All checks were successful
OTA build / build-ota (push) Successful in 2m19s
2026-08-29 16:16:57 -05:00
94a6929fea Changes 2026-05-14 17:49:06 -05:00
c382ae2888 Fix resetting the timer also when the status hasn't changed 2026-01-12 08:32:33 -06:00
7a493759ba issues - most likely caused by light setting 2026-01-11 19:13:48 -06:00
5ccd15dde3 Changed the sensor from PIR to Radar - technically the mqtt messages are not correct anymore. 2026-01-11 16:07:23 -06:00
Joe Tretter
f7ab7f61a2 Prevent wrong triggering by requiring 2 triggers within 30 seconds to initially react. Hopefully that helps preventing accidental triggers. 2025-04-06 18:20:17 -05:00
Joe Tretter
9a128704ff Change various things including reboot when connection doesn't work and not delaying the loop when motion is detected 2025-04-04 19:52:08 -05:00
Joe Tretter
150a9aae20 Some more logging and cosmetics 2025-04-04 17:26:26 -05:00
Joe Tretter
2fb449522d Merge branch 'master' of kawomi.com:/var/local/git/PlatformIOProjects 2025-04-03 16:59:19 -05:00
Joe Tretter
79d440646d First try version of the kitchen PIR 2025-04-03 16:58:44 -05:00
Joe Tretter
c23cf033de First try version of the kitchen PIR 2025-04-03 15:37:32 -05:00
5 changed files with 225 additions and 40 deletions

View File

@@ -0,0 +1,140 @@
name: OTA build
on:
push:
branches:
- '**'
workflow_dispatch:
jobs:
build-ota:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install PlatformIO
run: |
python -m pip install --upgrade pip
pip install platformio
- name: Build OTA firmware binaries
run: pio run
- name: Prepare direct OTA files
run: |
set -eu
rm -rf dist/ota
project_name="${GITHUB_REPOSITORY#*/}"
project_name="${project_name#PlatformIO_}"
timestamp="$(date -u +%Y-%m-%dT%H-%M-%SZ)"
mkdir -p dist/ota
found=0
for fw in .pio/build/*/firmware.bin .pio/build/*/firmware.hex; do
[ -f "$fw" ] || continue
env_name="$(basename "$(dirname "$fw")")"
ext="${fw##*.}"
cp "$fw" "dist/ota/${project_name}_${env_name}_${timestamp}.${ext}"
found=1
done
if [ "$found" -eq 0 ]; then
echo 'No firmware.bin or firmware.hex artifacts were produced.' >&2
exit 1
fi
find dist/ota -maxdepth 1 -type f | sort
- name: Upload backup OTA artifact ZIP
uses: actions/upload-artifact@v3
with:
name: ota-files
path: dist/ota/*
if-no-files-found: error
- name: Publish raw OTA files to rolling release
env:
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
run: |
python - <<'PY'
import json
import mimetypes
import os
import sys
from pathlib import Path
from urllib.request import Request, urlopen
from urllib.error import HTTPError
server = os.environ['GITHUB_SERVER_URL']
repo = os.environ['GITHUB_REPOSITORY']
token = os.environ.get('GITEA_TOKEN')
if not token:
print('GITEA_TOKEN missing', file=sys.stderr)
sys.exit(1)
api = f"{server}/api/v1/repos/{repo}"
headers = {
'Authorization': f'token {token}',
'Accept': 'application/json',
'Content-Type': 'application/json',
'User-Agent': 'Hermes-Agent'
}
tag = 'ota-builds'
release_name = 'OTA Builds'
body = 'Rolling OTA files from the latest successful push build.'
def req(url, method='GET', data=None, extra_headers=None):
h = dict(headers)
if extra_headers:
h.update(extra_headers)
payload = None if data is None else json.dumps(data).encode()
r = Request(url, data=payload, headers=h, method=method)
with urlopen(r, timeout=120) as resp:
body = resp.read()
if not body:
return None
text = body.decode()
try:
return json.loads(text)
except json.JSONDecodeError:
return text
try:
release = req(f"{api}/releases/tags/{tag}")
except HTTPError as e:
if e.code != 404:
raise
release = req(f"{api}/releases", method='POST', data={
'tag_name': tag,
'target': os.environ.get('GITHUB_SHA', ''),
'name': release_name,
'body': body,
'draft': False,
'prerelease': True,
})
release_id = release['id']
existing = req(f"{api}/releases/{release_id}/assets") or []
for asset in existing:
rid = asset['id']
req(f"{api}/releases/{release_id}/assets/{rid}", method='DELETE')
for path in sorted(Path('dist/ota').glob('*')):
if not path.is_file():
continue
mime = mimetypes.guess_type(path.name)[0] or 'application/octet-stream'
upload_headers = {
'Authorization': f'token {token}',
'Content-Type': mime,
'Accept': 'application/json',
'User-Agent': 'Hermes-Agent'
}
url = f"{api}/releases/{release_id}/assets?name={path.name}"
data = path.read_bytes()
r = Request(url, data=data, headers=upload_headers, method='POST')
with urlopen(r, timeout=240) as resp:
print(resp.read().decode())
PY

3
.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"CodeGPT.apiKey": "CodeGPT Plus Beta"
}

0
AGENTS.md Normal file
View File

View File

@@ -11,6 +11,7 @@
[env:esp32doit-devkit-v1] [env:esp32doit-devkit-v1]
platform = espressif32 platform = espressif32
board = esp32doit-devkit-v1 board = esp32doit-devkit-v1
monitor_speed = 115200
framework = arduino framework = arduino
lib_deps = lib_deps =
knolleary/PubSubClient@^2.8 knolleary/PubSubClient@^2.8

View File

@@ -6,8 +6,7 @@
const int PIR_PIN=23; const int PIR_PIN=23;
const char* ssid = "JoNelsDarlings"; const char* ssid = "JoNelsDarlings";
const char* password = "Paris2016"; const char* password = "Paris2016";
const char* mqtt_server = "mqtt.ddns.kawomi.com"; const char* mqttServerName = "mqtt.ddns.kawomi.com";
WiFiClient espClient; WiFiClient espClient;
PubSubClient mqttClient(espClient); PubSubClient mqttClient(espClient);
@@ -16,7 +15,6 @@ unsigned long lastMsg = 0;
char msg[MSG_BUFFER_SIZE]; char msg[MSG_BUFFER_SIZE];
void setup_wifi() { void setup_wifi() {
delay(10); delay(10);
// We start by connecting to a WiFi network // We start by connecting to a WiFi network
Serial.println(); Serial.println();
@@ -39,37 +37,19 @@ void setup_wifi() {
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
} }
void send_mqtt(String status, long minutes=0) {
Serial.print("MQTT Send status ");
Serial.print(status);
Serial.print(" mins ");
Serial.println(minutes);
void reconnect() { JsonDocument doc;
// Loop until we're reconnected
while (!mqttClient.connected()) {
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP32Client-";
clientId += String(random(0xffff), HEX);
// Attempt to connect
if (mqttClient.connect(clientId.c_str())) {
Serial.println("MQTT connected");
// Once connected, publish an announcement...
} else {
Serial.print("MQTT failed, rc=");
Serial.print(mqttClient.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void send_mqtt(String value) {
const size_t CAPACITY = JSON_OBJECT_SIZE(1);
StaticJsonDocument<CAPACITY> doc;
// create an object
JsonObject object = doc.to<JsonObject>(); JsonObject object = doc.to<JsonObject>();
object["status"] = value.c_str(); object["status"] = status.c_str();
if (minutes > 0) {
object["minutes"] = minutes;
}
// serialize the object and send the result to Serial
static char sensorStatus[150]; static char sensorStatus[150];
serializeJson(doc, sensorStatus); serializeJson(doc, sensorStatus);
Serial.println(sensorStatus); Serial.println(sensorStatus);
@@ -77,28 +57,89 @@ void send_mqtt(String value) {
mqttClient.publish("Address/Livorno/Kitchen/PIR", sensorStatus, true); mqttClient.publish("Address/Livorno/Kitchen/PIR", sensorStatus, true);
} }
void reconnect() {
int numRetries=0;
while (!mqttClient.connected()) {
numRetries++;
Serial.print("Attempting MQTT connection...");
// Create a random client ID
String clientId = "ESP32Client-";
clientId += String(random(0xffff), HEX);
if (mqttClient.connect(clientId.c_str())) {
Serial.println("MQTT connected");
} else {
Serial.print("MQTT failed, rc=");
Serial.print(mqttClient.state());
Serial.println(" try again in 5 seconds");
if (numRetries>5){
Serial.println("Too many retries, restarting the ESP...");
ESP.restart();
}
delay(5000);
}
}
send_mqtt("ready");
}
void setup() { void setup() {
pinMode(LED_BUILTIN,OUTPUT); pinMode(LED_BUILTIN,OUTPUT);
pinMode(PIR_PIN,INPUT); pinMode(PIR_PIN,INPUT_PULLUP);
Serial.begin(115200); Serial.begin(115200);
setup_wifi(); setup_wifi();
mqttClient.setServer(mqtt_server, 1883); const int mqttPort=1883;
mqttClient.setServer(mqttServerName, mqttPort);
} }
const int millisPerSecond=1000;
long previousMotionMillis=millis();
short previousState=-1;
long previousNoMoNotifyMinutes=0;
void loop() { void loop() {
if (!mqttClient.connected()) { if (!mqttClient.connected()) {
reconnect(); reconnect();
} }
mqttClient.loop(); mqttClient.loop();
int pir = digitalRead(PIR_PIN); short currentState = digitalRead(PIR_PIN);
if (pir == HIGH) { // This out pin triggering is dependent not only on movement, but also on light levels which can be configured in the app.
// I set it to 255 and "below" - this triggered it for me.....
//send_mqtt("occupancy_state_debug", currentState);
// When occupancy is detected, reset the timer
if (currentState == HIGH) {
previousMotionMillis=millis();
}
// Send messages only on status change, we don't want to flood the network...
if (currentState != previousState) {
Serial.print("Status changed; currentState: ");
Serial.print(currentState);
Serial.print(" previousState: ");
Serial.println(previousState);
if (currentState == HIGH) {
send_mqtt("motion"); send_mqtt("motion");
digitalWrite(LED_BUILTIN,HIGH); digitalWrite(LED_BUILTIN,HIGH);
delay(1000); } else {
send_mqtt("no_motion_immediate");
digitalWrite(LED_BUILTIN,LOW); digitalWrite(LED_BUILTIN,LOW);
} }
previousState = currentState;
}
// Send no_motion messages every minute, indicating how long we didn't see occupancy
const int secondsPerMinute=60;
long minutesSinceLastMotion=(millis()-previousMotionMillis)/(millisPerSecond*secondsPerMinute);
if ((previousNoMoNotifyMinutes != minutesSinceLastMotion) && (0 != minutesSinceLastMotion)) {
send_mqtt("no_motion", minutesSinceLastMotion);
previousNoMoNotifyMinutes = minutesSinceLastMotion;
}
delay(50);
} }