Läuft erst mal , speichern in SQLite-DB

This commit is contained in:
2026-04-13 18:45:22 +02:00
parent d1cfee0dea
commit ae75b98faf
5 changed files with 32 additions and 42 deletions

5
.env
View File

@@ -1,13 +1,14 @@
# Davis Vantage Pro 2 Konfiguration # Davis Vantage Pro 2 Konfiguration
# Serieller Port der Wetterstation # Serieller Port der Wetterstation
PORT_PATH=/dev/ttyUSB0 #PORT_PATH=/dev/ttyUSB0
PORT_PATH=/dev/cu.usbserial-0001
# Baudrate (Davis Standard: 19200) # Baudrate (Davis Standard: 19200)
BAUD_RATE=19200 BAUD_RATE=19200
# Pfad zur SQLite-Datenbank # Pfad zur SQLite-Datenbank
DB_PATH=/data/wetter.db DB_PATH=./data/wetter.db
# Abfrageintervall für LOOP-Daten in Millisekunden (Standard: 30s) # Abfrageintervall für LOOP-Daten in Millisekunden (Standard: 30s)
LOOP_INTERVAL_MS=30000 LOOP_INTERVAL_MS=30000

View File

@@ -172,20 +172,16 @@ function parseLOOP1(pkt) {
return { return {
time: new Date(), time: new Date(),
tempOut: temp(pkt.readInt16LE(12)), tempOut: temp(pkt.readInt16LE(12)),
tempOutHigh: null,
tempOutLow: null,
tempIn: temp(pkt.readInt16LE(9)), tempIn: temp(pkt.readInt16LE(9)),
humOut: hum(pkt[33]), humOut: hum(pkt[33]),
humIn: hum(pkt[11]), humIn: hum(pkt[11]),
windAvg: mph(pkt[14]), windAvg: mph(pkt[14]),
windHigh: null, windGust: null,
windDir: degToDir(pkt.readUInt16LE(16)), windDir: degToDir(pkt.readUInt16LE(16)),
windHighDir: null, forecast: pkt[89],
pressure: press === 0 ? null : r1(press * 33.8639 / 1000), pressure: press === 0 ? null : r1(press * 33.8639 / 1000),
rain: +(pkt.readUInt16LE(50) * RAIN_CLICK).toFixed(1), rain: +(pkt.readUInt16LE(50) * RAIN_CLICK).toFixed(1),
rainRate: +(pkt.readUInt16LE(41) * 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 { return {
time: parseDateTime(dateWord, timeWord), time: parseDateTime(dateWord, timeWord),
tempOut: fTenthToC(buf.readInt16LE(4)), tempOut: fTenthToC(buf.readInt16LE(4)),
tempOutHigh: fTenthToC(buf.readInt16LE(6)),
tempOutLow: fTenthToC(buf.readInt16LE(8)),
tempIn: fTenthToC(buf.readInt16LE(20)), tempIn: fTenthToC(buf.readInt16LE(20)),
humOut: buf[23] === 255 ? null : buf[23], humOut: buf[23] === 255 ? null : buf[23],
humIn: buf[22] === 255 ? null : buf[22], humIn: buf[22] === 255 ? null : buf[22],
windAvg: mphToKmh(buf[24]), windAvg: mphToKmh(buf[24]),
windHigh: mphToKmh(buf[25]), windGust: mphToKmh(buf[25]),
windDir: windDirStr(buf[27]), windDir: windDirStr(buf[27]),
windHighDir: windDirStr(buf[26]),
pressure: inHgToHPa(buf.readUInt16LE(14)), pressure: inHgToHPa(buf.readUInt16LE(14)),
rain: +(buf.readUInt16LE(10) * RAIN_CLICK).toFixed(1), rain: +(buf.readUInt16LE(10) * RAIN_CLICK).toFixed(1),
rainRate: +(buf.readUInt16LE(12) * RAIN_CLICK).toFixed(1), rainRate: +(buf.readUInt16LE(12) * RAIN_CLICK).toFixed(1),
solarRad: buf.readUInt16LE(16) === 32767 ? null : buf.readUInt16LE(16),
}; };
} }

42
db.js
View File

@@ -18,19 +18,16 @@ CREATE TABLE IF NOT EXISTS readings (
ts INTEGER NOT NULL, -- Unix-Zeit in Sekunden (UTC) ts INTEGER NOT NULL, -- Unix-Zeit in Sekunden (UTC)
source TEXT NOT NULL, -- 'archive' | 'loop' source TEXT NOT NULL, -- 'archive' | 'loop'
temp_out REAL, -- °C temp_out REAL, -- °C
temp_out_high REAL, -- °C (nur Archiv)
temp_out_low REAL, -- °C (nur Archiv)
temp_in REAL, -- °C temp_in REAL, -- °C
hum_out INTEGER, -- % hum_out INTEGER, -- %
hum_in INTEGER, -- % hum_in INTEGER, -- %
wind_avg REAL, -- km/h wind_avg REAL, -- km/h
wind_high REAL, -- km/h (nur Archiv) wind_high REAL, -- km/h (nur Archiv)
wind_dir TEXT, -- Himmelsrichtung wind_dir TEXT, -- Himmelsrichtung
wind_high_dir TEXT, -- Himmelsrichtung (nur Archiv)
pressure REAL, -- hPa pressure REAL, -- hPa
rain REAL, -- mm (Archiv: Intervall; Loop: Tagessumme) rain REAL, -- mm (Archiv: Intervall; Loop: Tagessumme)
rain_rate REAL, -- mm/h rain_rate REAL, -- mm/h
solar_rad INTEGER, -- W/m² forecast INTEGER, -- Forecast Icons Byte (nur Loop)
UNIQUE(ts, source) UNIQUE(ts, source)
); );
CREATE INDEX IF NOT EXISTS idx_readings_ts ON readings(ts); CREATE INDEX IF NOT EXISTS idx_readings_ts ON readings(ts);
@@ -67,33 +64,30 @@ export function getLatestTs(db) {
const INSERT_SQL = ` const INSERT_SQL = `
INSERT OR IGNORE INTO readings INSERT OR IGNORE INTO readings
(ts, source, temp_out, temp_out_high, temp_out_low, temp_in, (ts, source, temp_out, temp_in,
hum_out, hum_in, wind_avg, wind_high, wind_dir, wind_high_dir, hum_out, hum_in, wind_avg, wind_high, wind_dir,
pressure, rain, rain_rate, solar_rad) pressure, rain, rain_rate, forecast)
VALUES VALUES
(@ts, @source, @temp_out, @temp_out_high, @temp_out_low, @temp_in, (@ts, @source, @temp_out, @temp_in,
@hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir, @wind_high_dir, @hum_out, @hum_in, @wind_avg, @wind_high, @wind_dir,
@pressure, @rain, @rain_rate, @solar_rad) @pressure, @rain, @rain_rate, @forecast)
`; `;
function toRow(record, source) { function toRow(record, source) {
return { return {
ts: Math.floor(record.time.getTime() / 1000), ts: Math.floor(record.time.getTime() / 1000),
source, source,
temp_out: record.tempOut ?? null, temp_out: record.tempOut ?? null,
temp_out_high: record.tempOutHigh ?? null, temp_in: record.tempIn ?? null,
temp_out_low: record.tempOutLow ?? null, hum_out: record.humOut ?? null,
temp_in: record.tempIn ?? null, hum_in: record.humIn ?? null,
hum_out: record.humOut ?? null, wind_avg: record.windAvg ?? null,
hum_in: record.humIn ?? null, wind_high: record.windGust ?? null,
wind_avg: record.windAvg ?? null, wind_dir: record.windDir ?? null,
wind_high: record.windHigh ?? null, pressure: record.pressure ?? null,
wind_dir: record.windDir ?? null, rain: record.rain ?? null,
wind_high_dir: record.windHighDir ?? null, rain_rate: record.rainRate ?? null,
pressure: record.pressure ?? null, forecast: record.forecast ?? null,
rain: record.rain ?? null,
rain_rate: record.rainRate ?? null,
solar_rad: record.solarRad ?? null,
}; };
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "wetter_1", "name": "wetter_1",
"version": "1.0.0", "version": "1.0.1",
"description": "", "description": "",
"license": "ISC", "license": "ISC",
"author": "rxf", "author": "rxf",

View File

@@ -71,10 +71,13 @@ async function runLoop(db) {
const data = await fetchLoopData(station); const data = await fetchLoopData(station);
insertRecord(db, data, "loop"); insertRecord(db, data, "loop");
log( log(
`Außen: ${data.tempOut?.toFixed(1)}°C ` + // `Außen: ${data.tempOut?.toFixed(1)}°C ` +
`Feuchte: ${data.humOut}% ` + `InnenT: ${data.tempIn?.toFixed(1)}°C ` +
`Wind: ${data.windAvg} km/h ` + // `Feuchte: ${data.humOut}% ` +
`Druck: ${data.pressure} hPa` `InnenH: ${data.humIn}% ` +
// `Wind: ${data.windAvg} km/h ` +
`Druck: ${data.pressure} hPa ` +
`Forecast: ${data.forecast}`
); );
} catch (e) { } catch (e) {
warn("LOOP-Fehler: " + e.message + " Verbindung wird neu aufgebaut."); warn("LOOP-Fehler: " + e.message + " Verbindung wird neu aufgebaut.");