From f2f86c90ceb2ccd74b85d56f40f8d955b2b4eea7 Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 16 Dec 2022 00:05:13 +0100 Subject: [PATCH 1/4] Added local MQTT data source --- js/localtracker.js | 124 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 js/localtracker.js diff --git a/js/localtracker.js b/js/localtracker.js new file mode 100644 index 0000000..1729069 --- /dev/null +++ b/js/localtracker.js @@ -0,0 +1,124 @@ + +var local_livedata = "ws://sonde.bitnet.be:9001/"; +var local_clientID = "SondeHub-Tracker-" + Math.floor(Math.random() * 10000000000); +var local_client = new Paho.Client(local_livedata, local_clientID); +var local_clientConnected = false; +var local_clientActive = false; +var local_clientTopic; +var local_messageRate = 0; +var local_messageRateAverage = 10; + + +local_live_data_buffer = {positions:{position:[]}} +function local_liveData() { + local_client.onConnectionLost = local_onConnectionLost; + local_client.onMessageArrived = local_onMessageArrived; + + local_client.connect({onSuccess:local_onConnect,onFailure:local_connectionError,reconnect:true}); + + function local_onConnect() { + if (wvar.query && sondePrefix.indexOf(wvar.query) == -1) { + var topic = "sondes/" + wvar.query; + local_client.subscribe(topic); + local_clientTopic = topic; + } else { + local_client.subscribe("batch"); + local_clientTopic = "batch"; + } + // Also subscribe to listener data, for listener and chase-car telemetry. + // To revert listener-via-websockets change, comment out this line, + // and un-comment the 'Disable periodical listener refresh' lines further below. + local_client.subscribe("listener/#"); + + local_clientConnected = true; + $("#stText").text("websocket |"); + }; + + function local_connectionError(error) { + $("#stText").text("conn. error |"); + local_clientConnected = false; + local_clientActive = false; + if (!document.getElementById("stTimer").classList.contains('friendly-dtime') ) { + document.getElementById("stTimer").classList.add('friendly-dtime'); + $("#updatedText").text(" Updated: "); + } + refresh(); + }; + + function local_onConnectionLost(responseObject) { + if (responseObject.errorCode !== 0) { + local_clientConnected = false; + local_clientActive = false; + if (!document.getElementById("stTimer").classList.contains('friendly-dtime') ) { + document.getElementById("stTimer").classList.add('friendly-dtime'); + $("#updatedText").text(" Updated: "); + } + refresh(); + } + }; + + function local_onMessageArrived(message) { + local_messageRate += 1; + setTimeout(function(){ + local_messageRate -= 1; + }, (1000 * local_messageRateAverage)); + if ( document.getElementById("stTimer").classList.contains('friendly-dtime') ) { + document.getElementById("stTimer").classList.remove('friendly-dtime'); + } + $("#stTimer").text(Math.round(local_messageRate/10) + " msg/s"); + $("#updatedText").text(" "); + var dateNow = new Date().getTime(); + try { + if (local_clientActive) { + if(message.topic.startsWith("listener")){ + // Message is Listener / Chase-Car information + var frame = JSON.parse(message.payloadString.toString()); + // We need to convert this into the right format for feeding into the receiver / chase car update functions. + // Probably a cleaner way of doing this. + // Format needs to be {callsign : {timestamp: frame}} + var formatted_frame = {}; + formatted_frame[frame.uploader_callsign] = {}; + formatted_frame[frame.uploader_callsign][frame.ts] = frame; + + // Send frames with mobile present and true onto the chase-car updater, + // otherwise, send them to the receiver updater. + // Do this on a per-update bases, since listener / chase car updates shouldn't + // be as frequent. + if(frame.hasOwnProperty('mobile')) { + if(frame.mobile == true) { + updateChase(formatted_frame); + } else { + updateReceivers(formatted_frame, single=true); + } + } else { + updateReceivers(formatted_frame, single=true); + } + + } else { + var frame = JSON.parse(message.payloadString.toString()); + + if (wvar.query == "" || sondePrefix.indexOf(wvar.query) > -1 || wvar.query == frame.serial) { + + var test = formatData(frame, true); + if (local_clientActive) { + local_live_data_buffer.positions.position.push.apply(local_live_data_buffer.positions.position,test.positions.position) + $("#stTimer").attr("data-timestamp", dateNow); + $("#stText").text("websocket |"); + } + } + } + } else { + console.log("WebSockets - Discarding Message, not ready yet.") + } + } + catch(err) {} + }; +} + + +// Interval to read in the live data buffer and update the page. +setInterval(function(){ + update(local_live_data_buffer); + local_live_data_buffer.positions.position=[]; +}, 500) + From 90c8e64f286df6d5ebebc6f8e81b2b940aeb2b8b Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 16 Dec 2022 00:06:17 +0100 Subject: [PATCH 2/4] Add localtracker.js to build script --- build.sh | 1 + js/tracker.js | 1 + 2 files changed, 2 insertions(+) diff --git a/build.sh b/build.sh index 1b07ff8..c11d209 100755 --- a/build.sh +++ b/build.sh @@ -25,6 +25,7 @@ BUILD_DATE="`date -u +%Y-%m-%dT%H:%M:%SZ`" java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge iscroll.js >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge chasecar.lib.js | sed "s/{VER}/$VERSION/" >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge tracker.js >> mobile.js +java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge localtracker.js >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge app.js | sed "s/{VER}/$VERSION/" | sed "s/{BUILD_DATE}/$BUILD_DATE/" >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge colour-map.js >> mobile.js java -jar "../tools/yuicompressor-2.4.8.jar" --type=js --disable-optimizations --nomunge xdata.js >> mobile.js diff --git a/js/tracker.js b/js/tracker.js index d0c03f7..a27c8c5 100644 --- a/js/tracker.js +++ b/js/tracker.js @@ -938,6 +938,7 @@ function load() { startAjax(); liveData(); + local_liveData(); }; L.NumberedDivIcon = L.Icon.extend({ From e8b82a946decba2f4991cc677c2bd3e4b1f6b3a6 Mon Sep 17 00:00:00 2001 From: Hans Date: Fri, 16 Dec 2022 01:06:30 +0100 Subject: [PATCH 3/4] console.log websocket error --- js/localtracker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/js/localtracker.js b/js/localtracker.js index 1729069..180248f 100644 --- a/js/localtracker.js +++ b/js/localtracker.js @@ -36,6 +36,7 @@ function local_liveData() { function local_connectionError(error) { $("#stText").text("conn. error |"); + console.log(error); local_clientConnected = false; local_clientActive = false; if (!document.getElementById("stTimer").classList.contains('friendly-dtime') ) { From 964c9776559e52cd89c40b048d27c4a453c3bf72 Mon Sep 17 00:00:00 2001 From: Hans Date: Tue, 28 May 2024 15:37:46 +0200 Subject: [PATCH 4/4] Change header bar color to make it easier to differentiate --- css/skeleton.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/css/skeleton.css b/css/skeleton.css index 5db3d38..d38af93 100644 --- a/css/skeleton.css +++ b/css/skeleton.css @@ -21,7 +21,7 @@ /* #Base 960 Grid ================================================== */ - .container { position: relative; width: 960px; margin: 0 auto; padding: 0; } + .container { position: relative; width: 960px; margin: 0 auto; padding: 0; background-color: #ff000088; } .container .column, .container .columns { float: left; display: inline; margin-left: 10px; margin-right: 10px; } .row { margin-bottom: 20px; }