Skip to content

Instantly share code, notes, and snippets.

@sybip
Created March 2, 2021 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sybip/4b754010cf5a667c161f3ae3d8d106ef to your computer and use it in GitHub Desktop.
Save sybip/4b754010cf5a667c161f3ae3d8d106ef to your computer and use it in GitHub Desktop.
goTenna Mesh traffic metadata logger
#!/usr/bin/env python
"""
goTenna Mesh metadata logger, using USB connected gtm-lab receiver
more info at: https://github.com/sybip/gtm-lab
"""
import serial
import sys
from time import gmtime, strftime
from binascii import unhexlify
# from pyGT https://github.com/sybip/pyGT
from gtairobj import gtReadAirMsg
from gtdefs import MSG_CLASS_NAME
try:
ser = serial.Serial(port=sys.argv[1], baudrate=115200, timeout=1)
except IndexError:
print("ERROR: Please run as %s PORT_NAME" % sys.argv[0])
sys.exit()
except serial.serialutil.SerialException:
print("ERROR: Could not open port: %s" % sys.argv[1])
sys.exit()
print('Connected to %s, Ctrl-C to quit' % sys.argv[1])
while True:
try:
x = ser.readline()
except KeyboardInterrupt:
break
x = x.rstrip()
if x:
x = x.decode('utf8')
else:
continue
# Received message lines syntax: RX_MSG:XXXX|DATA_OBJECT_HEX
if (x[0:7] == 'RX_MSG:'):
(a, msgObj, ) = x.split('|')
m = gtReadAirMsg(unhexlify(msgObj), 0)
if not m: # could not parse
print('(parsing error)')
continue
else:
continue # not a RX message
try:
destStr = '%012x:%02x' % (m['destGID'], m['destTag'])
except KeyError:
destStr = '[ALL] '
try:
print("%s %s app=%04x %012x->%15s len=%3d h=%04x %s" % (
strftime('%Y%m%d-%H%M%S', gmtime()),
MSG_CLASS_NAME[m['classID']],
m['appID'], m['fromGID'], destStr, len(m['msgBlob']),
m['hashID'], 'ENC' if m['cryptFlag'] else 'CLR'))
except KeyError:
print('(unexpected format)')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment