Skip to content

Instantly share code, notes, and snippets.

@sybip
Created March 26, 2021 13:14
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/219a900cc23acc9234f45cdb94e5c2a7 to your computer and use it in GitHub Desktop.
Save sybip/219a900cc23acc9234f45cdb94e5c2a7 to your computer and use it in GitHub Desktop.
goTenna Mesh traffic logger, similar to (and based on) metalogger, but also including cleartext dump when practical
#!/usr/bin/env python
"""
goTenna mesh message 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 compatGTA import gtReadGTABlob
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)')
print(msgObj)
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('(unknown format)')
continue
if (('msgBlob' in m) and not m['cryptFlag']):
try:
res = gtReadGTABlob(m['msgBlob'])
except (ValueError):
continue
if res:
print(res)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment