MQTT - using the $SYS topic to get MQTT server information

Just stumbled upon a flow published in Steves internet guide that displays information in a node-RED dashboard about your Mosquitto MQTT server.

The screenprint doesn't capture the full screen, but it also shows comprehensive information about retained messages, subscriptions etc.
You may find this of interest...

[{"id":"feef7174.a35ff","type":"tab","label":"Mosquitto Broker $SYS Monitor","disabled":false,"info":""},{"id":"fce3cf67.80e7c","type":"mqtt in","z":"feef7174.a35ff","name":"","topic":"$SYS/#","qos":"0","datatype":"auto","broker":"9a3ac674.8ced9","x":110,"y":100,"wires":[["6a8d7767.9a4bf"]]},{"id":"541c48c9.3afaf8","type":"template","z":"feef7174.a35ff","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<table  class=\"table\">\n  <tr>\n\n   <th>TOPIC</th>\n    <th>VALUE</th>\n  \n  </tr>\n  {{#payload}}\n  <tr>\n    <td>{{topic}}</td> \n    <td>{{payload}}</td>\n\n\n\n  </tr>\n{{/payload}}\n\n  \n</table>","output":"str","x":360,"y":260,"wires":[["4fe2160a.b77708"]]},{"id":"ba8eee5.873479","type":"debug","z":"feef7174.a35ff","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":430,"y":80,"wires":[]},{"id":"6a8d7767.9a4bf","type":"function","z":"feef7174.a35ff","name":"","func":"var topics=context.get('topics') || {};\nvar temp=context.get('temp') || [];\nvar payload=msg.payload;\nvar topic=msg.topic\nif (topic==\"timer\")\n{\nvar keys=Object.keys(topics)\nvar temp=[];\nfor(var i=0;i<keys.length;i++)\n{\n    \n     var data={\"topic\":keys[i],\"payload\":topics[keys[i]]}\n    temp.push(data);   \n}\nmsg.payload=temp;\ntemp=[];\ncontext.set(\"temp\",temp);//reset\n//if ()\nreturn msg;\n}\nelse\n{\n    topics[topic]=payload\n    var data={\"topic\":msg.topic,\"payload\":msg.payload}\n    temp.push(data);\n    context.set(\"topics\",topics);\n}","outputs":1,"noerr":0,"x":310,"y":160,"wires":[["541c48c9.3afaf8","ba8eee5.873479"]]},{"id":"4fe2160a.b77708","type":"ui_template","z":"feef7174.a35ff","group":"5533243a.0edaa4","name":"","order":6,"width":0,"height":0,"format":"\n<style>\n\n.headline\n{\n font-size:28px; \n  font-weight: bold;\n    \n}\n\n.table\n{\n   \n    width:500px;  \n}\n.main\n{\n    height:650px;\n    width:600px;\n    //background:#ffffc6;\n//border:1px solid black;\n}\n.table th,td\n{\nborder:1px solid black;\n}\n.table th\n{\n   background: yellow;\n}\n</style>\n\n<div class=\"main\" ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":300,"y":500,"wires":[[]]},{"id":"4ef48789.b2e9d8","type":"inject","z":"feef7174.a35ff","name":"","topic":"timer","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":260,"wires":[["6a8d7767.9a4bf"]]},{"id":"9a3ac674.8ced9","type":"mqtt-broker","z":"","name":"","broker":"192.168.1.21","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"120","cleansession":true,"birthTopic":"sensors/connected/test-client","birthQos":"0","birthRetain":"true","birthPayload":"1","closeTopic":"","closePayload":"","willTopic":"sensors/connected/test-client","willQos":"0","willRetain":"true","willPayload":"0"},{"id":"5533243a.0edaa4","type":"ui_group","z":"","name":"Mosquitto","tab":"75c10258.8ebf24","disp":true,"width":"12","collapse":false},{"id":"75c10258.8ebf24","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":19,"disabled":false,"hidden":false}]
1 Like

:grinning: Welcome to MQTT Paul :rofl: Sorry, couldn't resist.

Just to note that not all brokers turn that on by default but Mosquitto does. Also, $sys won't generally show up if you subscribe to #, you generally have to subscribe to it explicitly.

It does indeed though show some very useful info.

2 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.