Browse Source

minor changes: cleanup todo, correction help message, naming sniffer->mqtt_sniffer

master
Dirk Alders 1 year ago
parent
commit
c9103de08e
1 changed files with 6 additions and 7 deletions
  1. 6
    7
      mqtt_sniffer.py

+ 6
- 7
mqtt_sniffer.py View File

10
 VERSION = "0.1.0"
10
 VERSION = "0.1.0"
11
 STARTTIME = time.time()
11
 STARTTIME = time.time()
12
 # TODO: Implement default values for bottombar_entries
12
 # TODO: Implement default values for bottombar_entries
13
-# TODO: Implement the Filter functionality
14
 
13
 
15
 HELPTEXT = """
14
 HELPTEXT = """
16
 F1: Get this help message
15
 F1: Get this help message
17
 F2: Set a filter (regular expression) for the topic of a message
16
 F2: Set a filter (regular expression) for the topic of a message
18
     Examples:
17
     Examples:
19
-    * "/gfw/*/videv" Get everything with "/gfw/" before "/videv" 
20
-F9: Start / Stop logging to mqtt-sniffer.log
18
+    * "/gfw/.*/videv" Get everything with "/gfw/" before "/videv" 
19
+F9: Start / Stop logging to mqtt_sniffer.log
21
 F12: Quit the mqtt sniffer
20
 F12: Quit the mqtt sniffer
22
 """
21
 """
23
 
22
 
42
         data = message.payload
41
         data = message.payload
43
 
42
 
44
     if match:
43
     if match:
45
-        print("%9.04f::%30s::%s" % (ts, message.topic, data))
44
+        print("%9.04f::%75s::%s" % (ts, message.topic, data))
46
         if my_bb.get_entry('log2file'):
45
         if my_bb.get_entry('log2file'):
47
-            logfile.write("%9.04f::%30s::%s\n" % (ts, message.topic, data))
46
+            logfile.write("%9.04f::%s::%s\n" % (ts, message.topic, data))
48
             logfile.flush()
47
             logfile.flush()
49
 
48
 
50
 if __name__ == "__main__":
49
 if __name__ == "__main__":
68
     my_bb.add_entry('msg_re', 2, my_bb.FUNC_TEXT, label='[F2] Filter')
67
     my_bb.add_entry('msg_re', 2, my_bb.FUNC_TEXT, label='[F2] Filter')
69
     my_bb.add_entry('quit', 12, my_bb.FUNC_QUIT, "Quit", label='[F12]', right=True)
68
     my_bb.add_entry('quit', 12, my_bb.FUNC_QUIT, "Quit", label='[F12]', right=True)
70
     my_bb.add_entry('log2file', 9, my_bb.FUNC_BOOL, label='[F9] Log2File', right=True)
69
     my_bb.add_entry('log2file', 9, my_bb.FUNC_BOOL, label='[F9] Log2File', right=True)
71
-    with open('sniffer.log', 'w') as logfile:
72
-        mc = mqtt.mqtt_client("sniffer", args.hostname, port=args.port, username=args.username, password=password)
70
+    with open('mqtt_sniffer.log', 'w') as logfile:
71
+        mc = mqtt.mqtt_client("mqtt_sniffer", args.hostname, port=args.port, username=args.username, password=password)
73
         mc.add_callback("#", rx_mqtt)
72
         mc.add_callback("#", rx_mqtt)
74
         my_bb.run()
73
         my_bb.run()

Loading…
Cancel
Save