Sendet nun zusätzlich per http-POST

This commit is contained in:
2026-04-13 21:35:20 +02:00
parent 8039060530
commit a7d82d31ab
4 changed files with 17 additions and 5 deletions

3
.env
View File

@@ -12,3 +12,6 @@ DB_PATH=./data/wetter.db
# Abfrageintervall für LOOP-Daten in Millisekunden (Standard: 30s)
LOOP_INTERVAL_MS=30000
# URL für die HTPP-POSTs der Daten
POST_URL=http://localhost:8001/debug

View File

@@ -168,6 +168,7 @@ function parseLOOP1(pkt) {
const r1 = (v) => v !== null && v !== undefined ? +v.toFixed(1) : null;
const press = pkt.readUInt16LE(7);
const barTrend = pkt.readInt8(3); // 80 = noch keine Trendinformation
return {
time: new Date(),
@@ -180,6 +181,7 @@ function parseLOOP1(pkt) {
windDir: degToDir(pkt.readUInt16LE(16)),
forecast: pkt[89],
pressure: press === 0 ? null : r1(press * 33.8639 / 1000),
barTrend: barTrend === 80 ? null : barTrend,
rain: +(pkt.readUInt16LE(50) * RAIN_CLICK).toFixed(1),
rainRate: +(pkt.readUInt16LE(41) * RAIN_CLICK).toFixed(1),
};

6
db.js
View File

@@ -27,7 +27,6 @@ CREATE TABLE IF NOT EXISTS readings (
pressure REAL, -- hPa
rain REAL, -- mm (Archiv: Intervall; Loop: Tagessumme)
rain_rate REAL, -- mm/h
forecast INTEGER, -- Forecast Icons Byte (nur Loop)
UNIQUE(ts, source)
);
CREATE INDEX IF NOT EXISTS idx_readings_ts ON readings(ts);
@@ -66,11 +65,11 @@ const INSERT_SQL = `
INSERT OR IGNORE INTO readings
(ts, source, temp_out, temp_in,
hum_out, hum_in, wind_avg, wind_high, wind_dir,
pressure, rain, rain_rate, forecast)
pressure, rain, rain_rate)
VALUES
(@ts, @source, @temp_out, @temp_in,
@hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir,
@pressure, @rain, @rain_rate, @forecast)
@pressure, @rain, @rain_rate)
`;
function toRow(record, source) {
@@ -87,7 +86,6 @@ function toRow(record, source) {
pressure: record.pressure ?? null,
rain: record.rain ?? null,
rain_rate: record.rainRate ?? null,
forecast: record.forecast ?? null,
};
}

View File

@@ -18,6 +18,7 @@ import { readArchiveSince, connectStation, fetchLoopData } from "./davis.js";
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const DB_PATH = process.env.DB_PATH ?? path.join(__dirname, "wetter.db");
const LOOP_INTERVAL_MS = Number(process.env.LOOP_INTERVAL_MS ?? 30_000);
const POST_URL = process.env.POST_URL ?? null;
// ── Hilfsfunktionen ────────────────────────────────────────────────────────
@@ -70,6 +71,13 @@ async function runLoop(db) {
try {
const data = await fetchLoopData(station);
insertRecord(db, data, "loop");
if (POST_URL) {
fetch(POST_URL, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(data),
}).catch(e => warn("POST fehlgeschlagen: " + e.message));
}
log(
// `Außen: ${data.tempOut?.toFixed(1)}°C ` +
`InnenT: ${data.tempIn?.toFixed(1)}°C ` +
@@ -77,6 +85,7 @@ async function runLoop(db) {
`InnenH: ${data.humIn}% ` +
// `Wind: ${data.windAvg} km/h ` +
`Druck: ${data.pressure} hPa ` +
`Trend: ${data.barTrend ?? "n/a"} ` +
`Forecast: ${data.forecast}`
);
} catch (e) {