Stream QSOs

This commit is contained in:
2025-04-02 09:47:11 +00:00
parent a446efda36
commit 2a9640081b
3 changed files with 25 additions and 16 deletions

View File

@@ -1,7 +0,0 @@
const config = {
mqttserver: {
host: "mqtt://[your mqtt-server hiere]"
}
};
module.exports = config;

View File

@@ -12,7 +12,6 @@
</style>
</head>
<body>
Topic: <input type="text" id="i_topic" name="n_topic"></br>
<div id="mqtt" class="monospace selection"></div>
<script type="text/javascript">
(function() {
@@ -23,20 +22,20 @@
console.log('Connected to:', socket.host);
});
socket.on('mqtt', function(message) {
if (message.topic) {
try {
message.content=JSON.stringify(message.content);
showit=JSON.stringify(message);
} catch {};
buffer.append( message.timestamp.toString() +':&nbsp;<b>'+message.topic.toString() + '</b>&nbsp;&nbsp;' + message.content.toString() + '<br/>' );
buffer.append( showit.toString() + '<br/>' );
buffer.scrollTop(lines*100);
lines++;
}
});
/*
$( "#i_topic" ).change(function() {
socket.emit("wishtopic",this.value);
$('#mqtt').empty();
});
*/
})();
</script>

25
mqtt.js
View File

@@ -16,12 +16,15 @@ app.get('/', (req, res) => { // Routing fuer index.html
io.on('connection', (socket) => { // Neue socket.io Connection?
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
client[socket.id].end();
console.log(socket.id + " disconnected");
@@ -33,17 +36,31 @@ io.on('connection', (socket) => { // Neue socket.io Connection?
try {
messagex=JSON.parse(message); // Versuchen mqtt-nachricht durch den jsonparser zu parsen
msg.content=messagex; // ergebnis in content haemmern
} catch(e) {}
console.log("JSON");
} catch(e) {
console.log("No JSON");
}
} else {
msg.content=message.toString(); // Ist nix json? dann ab in "content" damit
}
msg.timestamp=dateFormat(date, "yyyy-mm-dd hh:MM:ss"); // timestamp formatieren
msg.topic=topic.toString(); // topic in das nachrichtenobject packen
socket.emit("mqtt",msg); // und raus an den Browser (nur fuer DIESES Socket, nicht fuer alle Clients) damit
tobrowser=parse_msg(msg.content);
socket.emit("mqtt",tobrowser); // 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
});
});
function parse_msg(msg) {
let retmsg={};
retmsg.call=msg.COL_CALL;
retmsg.station_call=msg.STATION_CALLSIGN;
retmsg.station_grid=msg.COL_MY_GRIDSQUARE;
retmsg.grid=msg.COL_GRIDSQUARE;
retmsg.band=msg.COL_BAND;
retmsg.mode=msg.COL_MODE
return retmsg;
}
http.listen(8000, () => { // Webserver starten
console.log(`Socket.IO server running at http://localhost:8000/`); // debug
});