Understanding Gateway Bridge packets

Hello,
I’d like to understand the structure of the Chirpstack Gateway Bridge packet that is published on the MQTT broker.
In particular, on the gateway/+/event/up topic, for example I can see this post:

0A11 8004 0000 0080 BD03 06D6 9947 F2F0 
3AA7 1012 1108 A084 919E 031A 0908 7D10 
071A 0334 2F35 1A3B 0A08 B827 EBFF FEB4 
5CD1 28AB FFFF FFFF FFFF FFFF 0131 0000 
0000 0000 2040 3802 4001 7A04 5B85 7F33 
8201 104F 67AB 900A 5D4D 87AA F60C 1277 
A898 87

How can I interpret it?
Thank you
Leonardo

You are seing the output of the Protobuf marshaler, if you want to see “plain” you need to change it to json.

1 Like

Thank you! I suspected this but unfortunately if I try to parse it to JSON, I get:
*** PAYLOAD IS NOT VALID JSON DATA ***

Illegal character ((CTRL-CHAR, code 17)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: java.io.StringReader@1e8d490; line: 2, column: 2]

Do yu have any advise to parse it? Maybe an online parser or something similar?

Thank you again!

the official API GitHub - brocaar/chirpstack-api: ChirpStack API (Protobuf & gRPC)
You can probably built a debug script with chirpstack-api · PyPI - dont forget to share it if you do :slight_smile:

1 Like

In addition to the protobuf definitions already linked, read up on the Gateway Bridge docs on payload format(s):

https://www.chirpstack.io/gateway-bridge/payloads/events/

Thank you! I’ve installed the api tool but I don’t find anything I can use to translate my byte array to a JSON human readable file.

Hello again,
I’ve installed the API but I don’t find the way to extract the information I need (DeviceEUI) from my byte array which is protobuf marshaller as you correctly said.
Is there a way to do so?
Or is there another way to retrieve the Device EUI that is communicating to the network from the MQTT?

Oh sorry if I was not clear, you have to build the script yourself. The API just provides the protobuf “objects”. You need to then subscribe and unmarshal the events you want. UplinkFrames should be under gw/gateway namespace as far as the protobuf defenitions goes. How the python api reflects that: i dont know. I have never used the python-api.

1 Like

based on Can't Decode Uplink Message from MQTT client

#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import paho.mqtt.client as mqtt
import chirpstack_api.gw as gateway
import re
import pprint

def on_log(client, userdata, level, buf):
    print("log: ", buf)

def on_connect(client, userdata, flags, rc):
    if rc==0:
        print("connected ok")
        client.subscribe("gateway/+/event/+")
        client.on_message = on_message
    else:
        print("not connected", rc)
#------------------------------------------------------------------------------------------------
def on_disconnect(client, userdata, flags, rc=0):
    print("disconnect result code "+str(rc))
#------------------------------------------------------------------------------------------------
def on_message(client, userdata, msg):
    m = re.match(r"^gateway\/(\w+)\/event\/up",msg.topic)
    if m:
        frame = gateway.UplinkFrame()
        frame.ParseFromString(msg.payload)
        pp = pprint.PrettyPrinter(indent=4)
        print("message received \n")
        pp.pprint(frame)

#------------------------------------------------------------------------------------------------
def on_subscribe(client, userdata, mid, granted_qos, properties=None):
    print("Subscribed: " + str(mid) + " " + str(granted_qos))


client = mqtt.Client("chirpstack-debugger") #create new instance

client.on_message = on_message
client.on_log = on_log
client.on_connect = on_connect
client.on_disconnect = on_disconnect
# if using tls - remember to change the port to 8883
# client.tls_set()
# client.tls_insecure_set(True)
client.username_pw_set("YOUR_USERNAME", "YOUR_PASSWORD")


client.connect("YOUR_MQTT_BROKER_ADDRESS", 1883, 60)
client.loop_forever()