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

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) {