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>
|
||||||
|
|||||||
65
mqtt.js
65
mqtt.js
@@ -14,43 +14,46 @@ var client=new Array(); // Haelt die einzelnen mqtt-clients je (browser-)clie
|
|||||||
app.use('/jquery', express.static(path.join(__dirname, 'node_modules', 'jquery', 'dist')));
|
app.use('/jquery', express.static(path.join(__dirname, 'node_modules', 'jquery', 'dist')));
|
||||||
|
|
||||||
app.get('/', (req, res) => { // Routing fuer index.html
|
app.get('/', (req, res) => { // Routing fuer index.html
|
||||||
res.sendFile(__dirname + '/index.html'); // index.html rauspusten
|
res.sendFile(__dirname + '/index.html'); // index.html rauspusten
|
||||||
|
});
|
||||||
|
|
||||||
|
const mqttC=mqtt.connect(mqttserver);
|
||||||
|
mqttC.on('connect', () => {
|
||||||
|
console.log('Connected to MQTT broker');
|
||||||
|
mqttC.subscribe('wavelog/#', (err) => {
|
||||||
|
if (!err) {
|
||||||
|
console.log(`Subscribed to topic`);
|
||||||
|
} else {
|
||||||
|
console.log('Error');
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
mqttC.on('message', function (topic, message) { // Handler, wenn mqtt-message kommt
|
||||||
|
date=new Date(); // Timestamp in date merken
|
||||||
|
msg={}; // msg-object initialisieren
|
||||||
|
if (message.toString().substring(0,1)=='{') { // JSON-String? Dann aufbereiten
|
||||||
|
try {
|
||||||
|
messagex=JSON.parse(message); // Versuchen mqtt-nachricht durch den jsonparser zu parsen
|
||||||
|
msg.content=messagex; // ergebnis in content haemmern
|
||||||
|
} catch(e) {
|
||||||
|
console.log("No JSON");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
msg.content=message.toString(); // Ist nix json? dann ab in "content" damit
|
||||||
|
}
|
||||||
|
tobrowser=parse_msg(msg.content);
|
||||||
|
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);
|
||||||
|
// 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?
|
io.on('connection', (socket) => { // Neue socket.io Connection?
|
||||||
console.log(socket.id + " connected"); // Debug
|
console.log(socket.id + " connected"); // Debug
|
||||||
client[socket.id] = mqtt.connect(mqttserver); // Dann neue MQTT-Verbindung aufmachen (je sock.io CLient eine, indiziert ueber die socket.id)
|
|
||||||
client[socket.id].subscribe('wavelog/#'); // Vom alten topic "unscubriben"
|
|
||||||
/*
|
|
||||||
socket.on('wishtopic', (msg) => { // Von der Website kommt ein neuer Topic-Wunsch
|
|
||||||
client[socket.id].unsubscribe(topica); // Vom alten topic "unscubriben"
|
|
||||||
client[socket.id].subscribe(msg); // Neues Subscriben
|
|
||||||
topica=msg; // Neues merken
|
|
||||||
console.log('message: ' + msg); // Debug-Log
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
socket.on("disconnect", (reason) => { // Socket.io Client gone? Dann mqtt fuer diesen Client wieder schliessen
|
socket.on("disconnect", (reason) => { // Socket.io Client gone? Dann mqtt fuer diesen Client wieder schliessen
|
||||||
client[socket.id].end();
|
|
||||||
console.log(socket.id + " disconnected");
|
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
|
|
||||||
msg={}; // msg-object initialisieren
|
|
||||||
if (message.toString().substring(0,1)=='{') { // JSON-String? Dann aufbereiten
|
|
||||||
try {
|
|
||||||
messagex=JSON.parse(message); // Versuchen mqtt-nachricht durch den jsonparser zu parsen
|
|
||||||
msg.content=messagex; // ergebnis in content haemmern
|
|
||||||
} catch(e) {
|
|
||||||
console.log("No JSON");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
msg.content=message.toString(); // Ist nix json? dann ab in "content" damit
|
|
||||||
}
|
|
||||||
tobrowser=parse_msg(msg.content);
|
|
||||||
socket.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);
|
|
||||||
// socket.emit("mqtt",parse_msg(msg)); // und raus an den Browser (nur fuer DIESES Socket, nicht fuer alle Clients) damit
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -69,5 +72,5 @@ function parse_msg(msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
http.listen(8000,'127.0.0.1', () => { // Webserver starten
|
http.listen(8000,'127.0.0.1', () => { // Webserver starten
|
||||||
console.log(`Socket.IO server running at http://localhost:8000/`); // debug
|
console.log(`Socket.IO server running at http://localhost:8000/`); // debug
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user