diff --git a/client.js b/client.js
index 66da7e5..d5f460d 100644
--- a/client.js
+++ b/client.js
@@ -3,6 +3,7 @@ let stations = {};
let messages = [];
const timeoutLength = 20 * 60 * 1000; // 20 Minutes
+const lowVoltage = 11.9;
Notification.requestPermission(permission => {
if (permission === "granted") {
@@ -15,7 +16,9 @@ function redrawTable() {
table.innerHTML =
`
Callsign | ` +
`Last Heard | ` +
- `Time since Last Heard | `;
+ `Time since Last Heard | ` +
+ `Last Voltage | ` +
+ `Last Temperature | `;
for (let callsign in stations) {
let station = stations[callsign];
let nowDelta = new Date(new Date() - station.lastHeard);
@@ -24,10 +27,16 @@ function redrawTable() {
if (nowDelta.getTime() > timeoutLength) {
tr.classList.add('timedOut');
}
+ if (station.lastVoltage < lowVoltage) {
+ tr.classList.add('lowVoltage');
+ }
tr.innerHTML =
`${callsign} | ` +
`${station.lastHeard.toLocaleTimeString('en-GB')} | ` +
- `${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})} | `;
+ `${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})} | ` +
+ `${station.lastVoltage||''} | ` +
+ `${station.lastTemperature||''} | `;
+
}
}
@@ -36,6 +45,11 @@ function alertNotHeard(callsign) {
{body: `Last Heard: ${stations[callsign].lastHeard.toLocaleTimeString('en-GB')}`});
}
+function alertVoltage(callsign) {
+ new Notification(`${callsign}'s battery has dropepd below ${lowVoltage}V`,
+ {body: `Voltage: ${stations[callsign].lastVoltage}`});
+}
+
let aprsStream = new WebSocket("ws://localhost:1234");
aprsStream.onmessage = function(event) {
let message = JSON.parse(event.data);
@@ -59,6 +73,15 @@ aprsStream.onmessage = function(event) {
stations[callsign].timeout = window.setTimeout(
alertNotHeard, timeoutLength, callsign);
+ if ('data' in message && 'analog' in message.data) {
+ stations[callsign].lastVoltage = message.data.analog[0] / 10;
+ stations[callsign].lastTemperature = message.data.analog[1];
+
+ if (stations[callsign].lastVoltage <= lowVoltage) {
+ alertVoltage(callsign);
+ }
+ }
+
redrawTable();
};
---|