Much more easy - one sub for all
This commit is contained in:
15
index.html
15
index.html
@@ -21,7 +21,7 @@
|
|||||||
th {
|
th {
|
||||||
background-color: #f4f4f4;
|
background-color: #f4f4f4;
|
||||||
}
|
}
|
||||||
.new-row { background-color: #ff0099; transition: background-color 1.5s; }
|
.new-row { background-color: #ff0099; transition: background-color 1.5s ease; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
@@ -76,7 +76,7 @@
|
|||||||
CellMode.textContent = message.mode;
|
CellMode.textContent = message.mode;
|
||||||
CellRSTR.textContent = message.RST_RCVD;
|
CellRSTR.textContent = message.RST_RCVD;
|
||||||
CellRSTS.textContent = message.RST_SENT;
|
CellRSTS.textContent = message.RST_SENT;
|
||||||
timestampCell.textContent = message.qso_time;;
|
timestampCell.textContent = tsclean(message.qso_time);
|
||||||
|
|
||||||
row.appendChild(timestampCell);
|
row.appendChild(timestampCell);
|
||||||
row.appendChild(CellStationCall);
|
row.appendChild(CellStationCall);
|
||||||
@@ -89,7 +89,9 @@
|
|||||||
row.appendChild(CellRSTS);
|
row.appendChild(CellRSTS);
|
||||||
row.classList.add('new-row');
|
row.classList.add('new-row');
|
||||||
tableBody.insertBefore(row, tableBody.firstChild);
|
tableBody.insertBefore(row, tableBody.firstChild);
|
||||||
$(row).removeClass('new-row', 1500);
|
setTimeout(() => {
|
||||||
|
row.classList.remove('new-row');
|
||||||
|
}, 1500);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -101,6 +103,13 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
function tsclean(timestamp) {
|
||||||
|
const parts = timestamp.split(':');
|
||||||
|
if (parts.length === 2) {
|
||||||
|
return `${timestamp}:00`;
|
||||||
|
}
|
||||||
|
return timestamp; // Already normalized
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
37
mqtt.js
37
mqtt.js
@@ -17,23 +17,20 @@ app.get('/', (req, res) => { // Routing fuer index.html
|
|||||||
res.sendFile(__dirname + '/index.html'); // index.html rauspusten
|
res.sendFile(__dirname + '/index.html'); // index.html rauspusten
|
||||||
});
|
});
|
||||||
|
|
||||||
io.on('connection', (socket) => { // Neue socket.io Connection?
|
const mqttC=mqtt.connect(mqttserver);
|
||||||
console.log(socket.id + " connected"); // Debug
|
mqttC.on('connect', () => {
|
||||||
client[socket.id] = mqtt.connect(mqttserver); // Dann neue MQTT-Verbindung aufmachen (je sock.io CLient eine, indiziert ueber die socket.id)
|
console.log('Connected to MQTT broker');
|
||||||
client[socket.id].subscribe('wavelog/#'); // Vom alten topic "unscubriben"
|
mqttC.subscribe('wavelog/#', (err) => {
|
||||||
/*
|
if (!err) {
|
||||||
socket.on('wishtopic', (msg) => { // Von der Website kommt ein neuer Topic-Wunsch
|
console.log(`Subscribed to topic`);
|
||||||
client[socket.id].unsubscribe(topica); // Vom alten topic "unscubriben"
|
} else {
|
||||||
client[socket.id].subscribe(msg); // Neues Subscriben
|
console.log('Error');
|
||||||
topica=msg; // Neues merken
|
console.log(err);
|
||||||
console.log('message: ' + msg); // Debug-Log
|
}
|
||||||
});
|
});
|
||||||
*/
|
});
|
||||||
socket.on("disconnect", (reason) => { // Socket.io Client gone? Dann mqtt fuer diesen Client wieder schliessen
|
|
||||||
client[socket.id].end();
|
mqttC.on('message', function (topic, message) { // Handler, wenn mqtt-message kommt
|
||||||
console.log(socket.id + " disconnected");
|
|
||||||
});
|
|
||||||
client[socket.id].on('message', function (topic, message) { // Handler, wenn mqtt-message kommt
|
|
||||||
date=new Date(); // Timestamp in date merken
|
date=new Date(); // Timestamp in date merken
|
||||||
msg={}; // msg-object initialisieren
|
msg={}; // msg-object initialisieren
|
||||||
if (message.toString().substring(0,1)=='{') { // JSON-String? Dann aufbereiten
|
if (message.toString().substring(0,1)=='{') { // JSON-String? Dann aufbereiten
|
||||||
@@ -47,9 +44,15 @@ io.on('connection', (socket) => { // Neue socket.io Connection?
|
|||||||
msg.content=message.toString(); // Ist nix json? dann ab in "content" damit
|
msg.content=message.toString(); // Ist nix json? dann ab in "content" damit
|
||||||
}
|
}
|
||||||
tobrowser=parse_msg(msg.content);
|
tobrowser=parse_msg(msg.content);
|
||||||
socket.emit("mqtt",tobrowser); // und raus an den Browser (nur fuer DIESES Socket, nicht fuer alle Clients) damit
|
io.emit("mqtt",tobrowser); // und raus an den Browser (nur fuer DIESES Socket, nicht fuer alle Clients) damit
|
||||||
console.log('QSO from: '+tobrowser.station_call+' with '+tobrowser.call+' in Mode: '+tobrowser.mode+' at '+tobrowser.qso_time);
|
console.log('QSO from: '+tobrowser.station_call+' with '+tobrowser.call+' in Mode: '+tobrowser.mode+' at '+tobrowser.qso_time);
|
||||||
// socket.emit("mqtt",parse_msg(msg)); // und raus an den Browser (nur fuer DIESES Socket, nicht fuer alle Clients) damit
|
// socket.emit("mqtt",parse_msg(msg)); // und raus an den Browser (nur fuer DIESES Socket, nicht fuer alle Clients) damit
|
||||||
|
});
|
||||||
|
|
||||||
|
io.on('connection', (socket) => { // Neue socket.io Connection?
|
||||||
|
console.log(socket.id + " connected"); // Debug
|
||||||
|
socket.on("disconnect", (reason) => { // Socket.io Client gone? Dann mqtt fuer diesen Client wieder schliessen
|
||||||
|
console.log(socket.id + " disconnected");
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user