Läuft erst mal , speichern in SQLite-DB
This commit is contained in:
5
.env
5
.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
|
||||
|
||||
14
davis.js
14
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),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
42
db.js
42
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,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "wetter_1",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "",
|
||||
"license": "ISC",
|
||||
"author": "rxf",
|
||||
|
||||
11
wetter.js
11
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.");
|
||||
|
||||
Reference in New Issue
Block a user