Add voltage/temp display and voltage checking

This commit is contained in:
Adam Goldsmith 2018-07-11 21:17:57 -04:00
parent b602a1e314
commit aa9a676806

View File

@ -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 =
`<tr><th>Callsign</th>` +
`<th>Last Heard</th>` +
`<th>Time since Last Heard</th>`;
`<th>Time since Last Heard</th>` +
`<th>Last Voltage</th>` +
`<th>Last Temperature</th>`;
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 =
`<td>${callsign}</td>` +
`<td>${station.lastHeard.toLocaleTimeString('en-GB')}</td>` +
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>`;
`<td>${nowDelta.toLocaleTimeString('en-GB', {timeZone: "UTC"})}</td>` +
`<td>${station.lastVoltage||''}</td>` +
`<td>${station.lastTemperature||''}</td>`;
}
}
@ -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();
};