Der finnes sikkert en del verktøy for å analysere MQTT trafikk men jeg fant ut jeg skulle lage et selv spesifikt med tanke på kun zwavejs2mqtt og zigbee2mqtt.
Jeg har laget loggedelen i Node-Red men regner med tilsvarende funksjon finnes i andre verktøy.
Først logges all aktuell trafikk. 2 varianter her:
Abonner på ALL MQTT trafikk og filtrer ut det du er interessert i
Abonner på kun aktuelle topics
Alle MQTT nodene er disablet her, enable enten øverste eller en eller flere av de nederste og la dette kjøre en tid, gjerne en time eller 2. Da havner alle aktive topics i filen MQTT_topics.txt. En liten bit av den kan se slik ut:
NodeRed nodene er rimelig grunnleggende og kan importeres herfra:
[{"id":"2b42c795f7798f70","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":2140,"wires":[["4417bad8572db2ed"]]},{"id":"4417bad8572db2ed","type":"change","z":"1dce5ca2ce2c0a55","name":"topic2payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":2140,"wires":[["5ade4ca28718f0ef"]]},{"id":"b2d5a3fda7df79f1","type":"file","z":"1dce5ca2ce2c0a55","name":"","filename":"/home/pi/log/MQTT_topics.txt","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":790,"y":2230,"wires":[[]]},{"id":"5ade4ca28718f0ef","type":"switch","z":"1dce5ca2ce2c0a55","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"zwave","vt":"str"},{"t":"cont","v":"zigbee","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":2140,"wires":[["b2d5a3fda7df79f1"],["b2d5a3fda7df79f1"]]},{"id":"e70b6f1574b9e395","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"zwave/#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":2190,"wires":[["715f21d7a7c96200"]]},{"id":"897acaa4eb04c040","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"zwaveGar/#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":2240,"wires":[["715f21d7a7c96200"]]},{"id":"74edcc6a00fabba3","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"zigbee2mqtt/#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":2290,"wires":[["715f21d7a7c96200"]]},{"id":"715f21d7a7c96200","type":"change","z":"1dce5ca2ce2c0a55","name":"topic2payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":2230,"wires":[["b2d5a3fda7df79f1"]]},{"id":"c8766bd440588a3b","type":"comment","z":"1dce5ca2ce2c0a55","name":"Logg MQTT data for analyse","info":"","x":220,"y":2090,"wires":[]},{"id":"6db118ed1b0c56de","type":"mqtt-broker","name":"DaleMQTT","broker":"172.16.0.94","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
Dette her er versjon 1, finner nok på noe bedre etterhvert...
Spørsmål
SveinHa
Der finnes sikkert en del verktøy for å analysere MQTT trafikk men jeg fant ut jeg skulle lage et selv spesifikt med tanke på kun zwavejs2mqtt og zigbee2mqtt.
Jeg har laget loggedelen i Node-Red men regner med tilsvarende funksjon finnes i andre verktøy.
Først logges all aktuell trafikk. 2 varianter her:
Alle MQTT nodene er disablet her, enable enten øverste eller en eller flere av de nederste og la dette kjøre en tid, gjerne en time eller 2. Da havner alle aktive topics i filen MQTT_topics.txt. En liten bit av den kan se slik ut:
zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Upper_Humidity_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Lower_Humidity_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Upper_Lighting_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Lower_Lighting_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Upper_Ultraviolet_Limit zwaveGar/Uteomraade/UtelysGarasje/switch_multilevel/endpoint_1/targetValue/set zigbee2mqtt/Lys/EldhusUte/set zigbee2mqtt/Lys/SpisebordDim/set zigbee2mqtt/Lys/Sov1Tak/set zigbee2mqtt/HUE/Garasje1/set zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Lower_Ultraviolet_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Temperature_Recover_Limit/65280 zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Recover_Limit_Temperature_Unit/255 zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Humidity_Recover_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Lighting_Recover_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Ultraviolet_Recover_Limit zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Temperature_Below_Lower_Limit/1 zwaveGar/Garasje/BevegAeotec/configuration/endpoint_0/Temperature_Above_Lower_Limit/16
Kjør så dette Python scriptet:
import os command = "sort MQTT_topics.txt -o MQTT_topics_s.txt" res = os.system(command) count = 0 fileIn = open('MQTT_topics_s.txt') fileOut = open('MQTT_topics_c.txt', 'w') line=fileIn.readline() while len(line)!=0: newLine=fileIn.readline() if newLine[:newLine.rfind('/')] == line[:line.rfind('/')]: # Begrens strenglengde til siste "/" count += 1 else: subline = line[:line.rfind('/')] # Begrens strenglengde til siste "/" msg = str(count) + ", " + subline + '\n' fileOut.write(msg) count = 0 line = newLine fileIn.close() fileOut.close() command = "sort -nr MQTT_topics_c.txt -o MQTT_topics_c.txt" res = os.system(command) res = os.remove('MQTT_topics_s.txt')
...og der dukker opp en fil med navnet MQTT_topics_c.txt som inneholder alle topics fram til siste "/" med antall duplikater funnet sorterrt synkende:
En liten bit av den kan se slik ut:
109, zigbee2mqtt/IKEA/Kjok_TrafoS 109, zigbee2mqtt/IKEA/Kjok_TrafoN 108, zigbee2mqtt/IKEA 96, zwave/TekniskRom/QB2/sensor_multilevel/endpoint_3 96, zigbee2mqtt/Nedis 88, zwave/TekniskRom/QB2/sensor_multilevel/endpoint_0 87, zwaveGar/Garasje/BevegAeotec/battery/endpoint_0 82, zigbee2mqtt/Solar 80, zwaveGar/Garasje/BevegAeotec/sensor_multilevel/endpoint_0 78, zwave/Teknisk/Gulvtemperaturer/sensor_multilevel/endpoint_4 77, zwaveGar/Uteomraade/UtelysGarasje/switch_multilevel/endpoint_1/targetValue 77, zigbee2mqtt/Solar/PwrInDiesel 77, zigbee2mqtt/Solar/PwrIn
NodeRed nodene er rimelig grunnleggende og kan importeres herfra:
[{"id":"2b42c795f7798f70","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":150,"y":2140,"wires":[["4417bad8572db2ed"]]},{"id":"4417bad8572db2ed","type":"change","z":"1dce5ca2ce2c0a55","name":"topic2payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":2140,"wires":[["5ade4ca28718f0ef"]]},{"id":"b2d5a3fda7df79f1","type":"file","z":"1dce5ca2ce2c0a55","name":"","filename":"/home/pi/log/MQTT_topics.txt","appendNewline":true,"createDir":true,"overwriteFile":"false","encoding":"none","x":790,"y":2230,"wires":[[]]},{"id":"5ade4ca28718f0ef","type":"switch","z":"1dce5ca2ce2c0a55","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"zwave","vt":"str"},{"t":"cont","v":"zigbee","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":2140,"wires":[["b2d5a3fda7df79f1"],["b2d5a3fda7df79f1"]]},{"id":"e70b6f1574b9e395","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"zwave/#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":160,"y":2190,"wires":[["715f21d7a7c96200"]]},{"id":"897acaa4eb04c040","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"zwaveGar/#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":2240,"wires":[["715f21d7a7c96200"]]},{"id":"74edcc6a00fabba3","type":"mqtt in","z":"1dce5ca2ce2c0a55","d":true,"name":"","topic":"zigbee2mqtt/#","qos":"2","datatype":"auto","broker":"6db118ed1b0c56de","nl":false,"rap":true,"rh":0,"inputs":0,"x":170,"y":2290,"wires":[["715f21d7a7c96200"]]},{"id":"715f21d7a7c96200","type":"change","z":"1dce5ca2ce2c0a55","name":"topic2payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":2230,"wires":[["b2d5a3fda7df79f1"]]},{"id":"c8766bd440588a3b","type":"comment","z":"1dce5ca2ce2c0a55","name":"Logg MQTT data for analyse","info":"","x":220,"y":2090,"wires":[]},{"id":"6db118ed1b0c56de","type":"mqtt-broker","name":"DaleMQTT","broker":"172.16.0.94","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
Dette her er versjon 1, finner nok på noe bedre etterhvert...
Endret av SveinHa7 svar til spørsmålet
Anbefalte innlegg
Bli med i samtalen
Du kan publisere innhold nå og registrere deg senere. Hvis du har en konto, logg inn nå for å poste med kontoen din.