-
-
Save D3f0/e649ebf0b5b79173674788a8f65b1419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import fileinput | |
import re | |
import sys | |
import binascii | |
from paho.mqtt.publish import single | |
# Esto buscan una trama que tenga Payload MARA | |
regex = re.compile(r'\[(?P<ip>[\d\.]+)\]\s<\w+=[\w_]+>\s[<>]+\s(?P<frame>[\w{2}\s?]+)') | |
def process(line): | |
groups = regex.search(line) | |
if groups: | |
co_ip, human_readable_frame = groups.group(1), groups.group(2) | |
if len(human_readable_frame) < 8: | |
return | |
payload = binascii.unhexlify(human_readable_frame.strip().replace(' ', '')) | |
topic = '/smve/{}'.format(co_ip) | |
print("PUBLISHING to {}".format(co_ip)) | |
try: | |
single( | |
topic=topic, | |
payload=payload, | |
hostname='mqtt.ignorelist.com' | |
) | |
except Exception as e: | |
print("ERROR! %s" % e) | |
else: | |
print("Skipping line") | |
sys.stdout.flush() | |
print("Starting to publish...") | |
for line in fileinput.input(): | |
process(line) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment