|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | +<title> |
| 5 | +MQTT Server Stats |
| 6 | +</title> |
| 7 | +<link type="text/css" rel="stylesheet" href="/app.css" media="all"> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | +<table id="messagetable"><tr><th>Topic</th><th>Value</th></tr></table> |
| 11 | +<P> |
| 12 | +<div id="time" style="font-size:x-small"></div> |
| 13 | +<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> |
| 14 | +<script src="http://www.trease.eu:8500/socket.io/socket.io.js"></script> |
| 15 | +<script> |
| 16 | + ElementExists = function(id) { |
| 17 | + return !!document.getElementById(id); |
| 18 | + }; |
| 19 | + |
| 20 | + var socket = io.connect("http://192.168.1.103:8500/mqttstats"); |
| 21 | + socket.on('data', function(data) { |
| 22 | + // console.log("Message received " + data.topic + " of " + data.value); |
| 23 | + |
| 24 | + // check the target topic exisits & if not create a target table entry |
| 25 | + if (!ElementExists (data.topic)) { |
| 26 | + // console.log("Creating target " + data.topic); |
| 27 | + var table=document.getElementById("messagetable"); |
| 28 | + |
| 29 | + // itertate through table to find out where to insert row in alpha order |
| 30 | + var count = 1; |
| 31 | + if (document.getElementById("messagetable").rows.length != 1) { |
| 32 | + for (i = 1; i < document.getElementById("messagetable").rows.length; i++) { |
| 33 | + var row = table.rows[i]; |
| 34 | + var col = row.cells[0]; |
| 35 | + if (col.firstChild.nodeValue < data.topic) { |
| 36 | + count++; |
| 37 | + } |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + var row=table.insertRow(count); |
| 42 | + var cell=row.insertCell(0); |
| 43 | + cell.id = data.topic; |
| 44 | + var cell=row.insertCell(0); |
| 45 | + cell.id = data.topic + "name"; |
| 46 | + document.getElementById(data.topic).style.textAlign="right" |
| 47 | + document.getElementById(data.topic + "name").innerHTML= data.topic; |
| 48 | + } |
| 49 | + // new we know there is a target, update it |
| 50 | + // console.log("Setting target " + data.topic + " to " + data.value); |
| 51 | + document.getElementById(data.topic).innerHTML= data.value; |
| 52 | + |
| 53 | + // print the time the refresh happened |
| 54 | + var dt = new Date(); |
| 55 | + document.getElementById("time").innerHTML= dt.toLocaleTimeString(); |
| 56 | + }); |
| 57 | +</script> |
| 58 | +</body> |
| 59 | +</html> |
| 60 | + |
0 commit comments