Skip to content

Instantly share code, notes, and snippets.

@D3f0
Created August 28, 2017 17:12
Show Gist options
  • Save D3f0/e649ebf0b5b79173674788a8f65b1419 to your computer and use it in GitHub Desktop.
Save D3f0/e649ebf0b5b79173674788a8f65b1419 to your computer and use it in GitHub Desktop.
#!/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