-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtelemetry_environmental_weewx.uc
More file actions
executable file
·57 lines (52 loc) · 1.93 KB
/
Copy pathtelemetry_environmental_weewx.uc
File metadata and controls
executable file
·57 lines (52 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import * as timers from "timers";
import * as router from "router";
import * as message from "message";
import * as node from "node";
import * as nodedb from "nodedb";
import * as channel from "channel";
import * as telemetry from "telemetry";
let weewxurl;
export function setup(config)
{
weewxurl = config.telemetry?.environmental_weewx?.url;
if (weewxurl) {
timers.setInterval("environmental_metrics", 60, config.telemetry?.environmental_weewx?.interval ?? telemetry.DEFAULT_INTERVAL);
}
};
export function tick()
{
if (timers.tick("environmental_metrics")) {
try {
const j = json(platform.fetch(weewxurl, 2));
const c = j.current;
const d = j.day;
const telemetry = channel.getTelemetryChannels();
for (let i = 0; i < length(telemetry); i++) {
router.queue(message.createMessage(null, null, telemetry[i].namekey, "telemetry", {
time: time(),
environment_metrics: {
temperature: telemetry.convert("C", c.temperature),
relative_humidity: c.humidity?.value,
barometric_pressure: telemetry.convert("hPA", c.barometer),
wind_direction: c["wind direction"]?.value,
wind_speed: telemetry.convert("m/s", c["wind speed"]),
wind_gust: telemetry.convert("m/s", c["wind gust"]),
rainfall_1h: telemetry.convert("mm/h", c["rain rate"]),
rainfall_24h: telemetry.convert("mm", d["rain total"])
}
}));
}
}
catch (_) {
}
}
};
export function process(msg)
{
if (msg.data?.telemetry?.environment_metrics && node.forMe(msg)) {
nodedb.updateEnvironmentMetrics(msg.from, msg.data.telemetry.environment_metrics);
}
};
export function cmd(msg, reply)
{
};