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

This commit is contained in:
Dirk Alders 2023-07-31 19:49:30 +02:00
parent 9b2141ff55
commit c9103de08e

View File

@ -10,14 +10,13 @@ import time
VERSION = "0.1.0"
STARTTIME = time.time()
# TODO: Implement default values for bottombar_entries
# TODO: Implement the Filter functionality
HELPTEXT = """
F1: Get this help message
F2: Set a filter (regular expression) for the topic of a message
Examples:
* "/gfw/*/videv" Get everything with "/gfw/" before "/videv"
F9: Start / Stop logging to mqtt-sniffer.log
* "/gfw/.*/videv" Get everything with "/gfw/" before "/videv"
F9: Start / Stop logging to mqtt_sniffer.log
F12: Quit the mqtt sniffer
"""
@ -42,9 +41,9 @@ def rx_mqtt(mc, userdata, message):
data = message.payload
if match:
print("%9.04f::%30s::%s" % (ts, message.topic, data))
print("%9.04f::%75s::%s" % (ts, message.topic, data))
if my_bb.get_entry('log2file'):
logfile.write("%9.04f::%30s::%s\n" % (ts, message.topic, data))
logfile.write("%9.04f::%s::%s\n" % (ts, message.topic, data))
logfile.flush()
if __name__ == "__main__":
@ -68,7 +67,7 @@ if __name__ == "__main__":
my_bb.add_entry('msg_re', 2, my_bb.FUNC_TEXT, label='[F2] Filter')
my_bb.add_entry('quit', 12, my_bb.FUNC_QUIT, "Quit", label='[F12]', right=True)
my_bb.add_entry('log2file', 9, my_bb.FUNC_BOOL, label='[F9] Log2File', right=True)
with open('sniffer.log', 'w') as logfile:
mc = mqtt.mqtt_client("sniffer", args.hostname, port=args.port, username=args.username, password=password)
with open('mqtt_sniffer.log', 'w') as logfile:
mc = mqtt.mqtt_client("mqtt_sniffer", args.hostname, port=args.port, username=args.username, password=password)
mc.add_callback("#", rx_mqtt)
my_bb.run()