added regex for topic filter
This commit is contained in:
parent
745e8e9524
commit
011ee98477
@ -1,8 +1,9 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import getpass
|
import getpass
|
||||||
import logging
|
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import mqtt
|
import mqtt
|
||||||
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
@ -10,7 +11,6 @@ from textual.containers import Vertical
|
|||||||
from textual.widgets import Footer, Header, Input, RichLog
|
from textual.widgets import Footer, Header, Input, RichLog
|
||||||
|
|
||||||
|
|
||||||
# TODO: Usage of multiple regex for topic filter
|
|
||||||
# TODO: Integrate sending of message (topic + payload)
|
# TODO: Integrate sending of message (topic + payload)
|
||||||
|
|
||||||
class MqttReceiver(object):
|
class MqttReceiver(object):
|
||||||
@ -68,7 +68,10 @@ class MqttSniffer(App):
|
|||||||
"""filter the mqtt messages."""
|
"""filter the mqtt messages."""
|
||||||
topic_match = False
|
topic_match = False
|
||||||
for topic_filter in self.topic_filter.split(","):
|
for topic_filter in self.topic_filter.split(","):
|
||||||
topic_match |= topic_filter.lower() in record.topic.lower()
|
try:
|
||||||
|
topic_match |= len(re.findall(topic_filter, record.topic)) > 0
|
||||||
|
except re.error:
|
||||||
|
pass # No valid regular expression
|
||||||
|
|
||||||
if topic_match:
|
if topic_match:
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user