From ae75b98faf0b009cc3c28e00634acc4261bd347b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20X=2E=20F=C3=BCrst?= Date: Mon, 13 Apr 2026 18:45:22 +0200 Subject: [PATCH] =?UTF-8?q?L=C3=A4uft=20erst=20mal=20,=20speichern=20in=20?= =?UTF-8?q?SQLite-DB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 5 +++-- davis.js | 14 +++----------- db.js | 42 ++++++++++++++++++------------------------ package.json | 2 +- wetter.js | 11 +++++++---- 5 files changed, 32 insertions(+), 42 deletions(-) diff --git a/.env b/.env index 358e9b2..3151107 100644 --- a/.env +++ b/.env @@ -1,13 +1,14 @@ # Davis Vantage Pro 2 – Konfiguration # Serieller Port der Wetterstation -PORT_PATH=/dev/ttyUSB0 +#PORT_PATH=/dev/ttyUSB0 +PORT_PATH=/dev/cu.usbserial-0001 # Baudrate (Davis Standard: 19200) BAUD_RATE=19200 # Pfad zur SQLite-Datenbank -DB_PATH=/data/wetter.db +DB_PATH=./data/wetter.db # Abfrageintervall für LOOP-Daten in Millisekunden (Standard: 30s) LOOP_INTERVAL_MS=30000 diff --git a/davis.js b/davis.js index 2dae1c3..2065e6a 100644 --- a/davis.js +++ b/davis.js @@ -172,20 +172,16 @@ function parseLOOP1(pkt) { return { time: new Date(), tempOut: temp(pkt.readInt16LE(12)), - tempOutHigh: null, - tempOutLow: null, tempIn: temp(pkt.readInt16LE(9)), humOut: hum(pkt[33]), humIn: hum(pkt[11]), windAvg: mph(pkt[14]), - windHigh: null, + windGust: null, windDir: degToDir(pkt.readUInt16LE(16)), - windHighDir: null, + forecast: pkt[89], pressure: press === 0 ? null : r1(press * 33.8639 / 1000), rain: +(pkt.readUInt16LE(50) * RAIN_CLICK).toFixed(1), rainRate: +(pkt.readUInt16LE(41) * RAIN_CLICK).toFixed(1), - solarRad: (pkt.readInt16LE(44) === 32767 || pkt.readInt16LE(44) < 0) - ? null : pkt.readInt16LE(44), }; } @@ -217,19 +213,15 @@ function parseRecord(buf) { return { time: parseDateTime(dateWord, timeWord), tempOut: fTenthToC(buf.readInt16LE(4)), - tempOutHigh: fTenthToC(buf.readInt16LE(6)), - tempOutLow: fTenthToC(buf.readInt16LE(8)), tempIn: fTenthToC(buf.readInt16LE(20)), humOut: buf[23] === 255 ? null : buf[23], humIn: buf[22] === 255 ? null : buf[22], windAvg: mphToKmh(buf[24]), - windHigh: mphToKmh(buf[25]), + windGust: mphToKmh(buf[25]), windDir: windDirStr(buf[27]), - windHighDir: windDirStr(buf[26]), pressure: inHgToHPa(buf.readUInt16LE(14)), rain: +(buf.readUInt16LE(10) * RAIN_CLICK).toFixed(1), rainRate: +(buf.readUInt16LE(12) * RAIN_CLICK).toFixed(1), - solarRad: buf.readUInt16LE(16) === 32767 ? null : buf.readUInt16LE(16), }; } diff --git a/db.js b/db.js index b2a7bbb..7f91c65 100644 --- a/db.js +++ b/db.js @@ -18,19 +18,16 @@ CREATE TABLE IF NOT EXISTS readings ( ts INTEGER NOT NULL, -- Unix-Zeit in Sekunden (UTC) source TEXT NOT NULL, -- 'archive' | 'loop' temp_out REAL, -- °C - temp_out_high REAL, -- °C (nur Archiv) - temp_out_low REAL, -- °C (nur Archiv) temp_in REAL, -- °C hum_out INTEGER, -- % hum_in INTEGER, -- % wind_avg REAL, -- km/h wind_high REAL, -- km/h (nur Archiv) wind_dir TEXT, -- Himmelsrichtung - wind_high_dir TEXT, -- Himmelsrichtung (nur Archiv) pressure REAL, -- hPa rain REAL, -- mm (Archiv: Intervall; Loop: Tagessumme) rain_rate REAL, -- mm/h - solar_rad INTEGER, -- W/m² + forecast INTEGER, -- Forecast Icons Byte (nur Loop) UNIQUE(ts, source) ); CREATE INDEX IF NOT EXISTS idx_readings_ts ON readings(ts); @@ -67,33 +64,30 @@ export function getLatestTs(db) { const INSERT_SQL = ` INSERT OR IGNORE INTO readings - (ts, source, temp_out, temp_out_high, temp_out_low, temp_in, - hum_out, hum_in, wind_avg, wind_high, wind_dir, wind_high_dir, - pressure, rain, rain_rate, solar_rad) + (ts, source, temp_out, temp_in, + hum_out, hum_in, wind_avg, wind_high, wind_dir, + pressure, rain, rain_rate, forecast) VALUES - (@ts, @source, @temp_out, @temp_out_high, @temp_out_low, @temp_in, - @hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir, @wind_high_dir, - @pressure, @rain, @rain_rate, @solar_rad) + (@ts, @source, @temp_out, @temp_in, + @hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir, + @pressure, @rain, @rain_rate, @forecast) `; function toRow(record, source) { return { ts: Math.floor(record.time.getTime() / 1000), source, - temp_out: record.tempOut ?? null, - temp_out_high: record.tempOutHigh ?? null, - temp_out_low: record.tempOutLow ?? null, - temp_in: record.tempIn ?? null, - hum_out: record.humOut ?? null, - hum_in: record.humIn ?? null, - wind_avg: record.windAvg ?? null, - wind_high: record.windHigh ?? null, - wind_dir: record.windDir ?? null, - wind_high_dir: record.windHighDir ?? null, - pressure: record.pressure ?? null, - rain: record.rain ?? null, - rain_rate: record.rainRate ?? null, - solar_rad: record.solarRad ?? null, + temp_out: record.tempOut ?? null, + temp_in: record.tempIn ?? null, + hum_out: record.humOut ?? null, + hum_in: record.humIn ?? null, + wind_avg: record.windAvg ?? null, + wind_high: record.windGust ?? null, + wind_dir: record.windDir ?? null, + pressure: record.pressure ?? null, + rain: record.rain ?? null, + rain_rate: record.rainRate ?? null, + forecast: record.forecast ?? null, }; } diff --git a/package.json b/package.json index 1fb5239..c6a1abc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wetter_1", - "version": "1.0.0", + "version": "1.0.1", "description": "", "license": "ISC", "author": "rxf", diff --git a/wetter.js b/wetter.js index 72bdf31..e96fd26 100644 --- a/wetter.js +++ b/wetter.js @@ -71,10 +71,13 @@ async function runLoop(db) { const data = await fetchLoopData(station); insertRecord(db, data, "loop"); log( - `Außen: ${data.tempOut?.toFixed(1)}°C ` + - `Feuchte: ${data.humOut}% ` + - `Wind: ${data.windAvg} km/h ` + - `Druck: ${data.pressure} hPa` +// `Außen: ${data.tempOut?.toFixed(1)}°C ` + + `InnenT: ${data.tempIn?.toFixed(1)}°C ` + +// `Feuchte: ${data.humOut}% ` + + `InnenH: ${data.humIn}% ` + +// `Wind: ${data.windAvg} km/h ` + + `Druck: ${data.pressure} hPa ` + + `Forecast: ${data.forecast}` ); } catch (e) { warn("LOOP-Fehler: " + e.message + " – Verbindung wird neu aufgebaut.");