Explorar el Código

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

master
Dirk Alders hace 1 año
padre
commit
c9103de08e
Se han modificado 1 ficheros con 6 adiciones y 7 borrados
  1. 6
    7
      mqtt_sniffer.py

+ 6
- 7
mqtt_sniffer.py Ver fichero

@@ -10,14 +10,13 @@ import time
10 10
 VERSION = "0.1.0"
11 11
 STARTTIME = time.time()
12 12
 # TODO: Implement default values for bottombar_entries
13
-# TODO: Implement the Filter functionality
14 13
 
15 14
 HELPTEXT = """
16 15
 F1: Get this help message
17 16
 F2: Set a filter (regular expression) for the topic of a message
18 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 20
 F12: Quit the mqtt sniffer
22 21
 """
23 22
 
@@ -42,9 +41,9 @@ def rx_mqtt(mc, userdata, message):
42 41
         data = message.payload
43 42
 
44 43
     if match:
45
-        print("%9.04f::%30s::%s" % (ts, message.topic, data))
44
+        print("%9.04f::%75s::%s" % (ts, message.topic, data))
46 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 47
             logfile.flush()
49 48
 
50 49
 if __name__ == "__main__":
@@ -68,7 +67,7 @@ if __name__ == "__main__":
68 67
     my_bb.add_entry('msg_re', 2, my_bb.FUNC_TEXT, label='[F2] Filter')
69 68
     my_bb.add_entry('quit', 12, my_bb.FUNC_QUIT, "Quit", label='[F12]', right=True)
70 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 72
         mc.add_callback("#", rx_mqtt)
74 73
         my_bb.run()

Loading…
Cancelar
Guardar