diff --git a/.env b/.env index 3151107..45f255b 100644 --- a/.env +++ b/.env @@ -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 \ No newline at end of file diff --git a/davis.js b/davis.js index 2065e6a..53d4f1f 100644 --- a/davis.js +++ b/davis.js @@ -167,7 +167,8 @@ function parseLOOP1(pkt) { const mph = (raw) => raw === 255 ? null : +(raw * 1.60934).toFixed(1); const r1 = (v) => v !== null && v !== undefined ? +v.toFixed(1) : null; - const press = pkt.readUInt16LE(7); + 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), }; diff --git a/db.js b/db.js index 7f91c65..d600528 100644 --- a/db.js +++ b/db.js @@ -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, }; } diff --git a/wetter.js b/wetter.js index e96fd26..461f8d3 100644 --- a/wetter.js +++ b/wetter.js @@ -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) {