First commit
This commit is contained in:
30
loop.js
Normal file
30
loop.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import { connectStation, fetchLoopData } from "./davis.js";
|
||||
|
||||
let station = null;
|
||||
|
||||
async function connect() {
|
||||
station = await connectStation();
|
||||
}
|
||||
|
||||
async function update() {
|
||||
try {
|
||||
const data = await fetchLoopData(station);
|
||||
console.log(
|
||||
`[${data.time.toLocaleTimeString("de-DE", { hour12: false })}] ` +
|
||||
`Außen: ${data.tempOut?.toFixed(1)}°C ` +
|
||||
`Feuchte: ${data.humOut}% ` +
|
||||
`Wind: ${data.windAvg} km/h`
|
||||
);
|
||||
} catch (e) {
|
||||
console.error("Fehler:", e.message);
|
||||
try { await station?.disconnect(); } catch {}
|
||||
station = null;
|
||||
try { await connect(); } catch {}
|
||||
}
|
||||
setTimeout(update, 30000);
|
||||
}
|
||||
|
||||
await connect();
|
||||
update();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user