sendData, API help

Hi, Meshtastic has been fantastic! I’ve been working with the Python API and have a couple questions. The method descriptions on is good, but leaves a few blanks here and there.

I’m trying to use the sendData command. I can send data but not sure how to work with the results. Hopefully I’m not packing in too much in one post, but hopefully these are simple questions. Thanks so much for your help!


Send out a packet from one node:


Print out the received packet with the example code:

def onReceive(packet, interface): # called when a packet arrives
    print(f"Received: {packet}")

And I receive the packet. The decoded part is:

‘decoded’: {‘data’: {‘payload’: ‘MTIzZm9vYmFy’, ‘typ’: ‘OPAQUE’}}

…That doesn’t look very decoded! What am I supposed to do with the payload (to decrypt it)? I feel like I’m missing something.

Also, is there an explanation somewhere for the dataType enum?

And, how to find info about the meaning of ‘rxSnr’? I assume, received signal to noise ratio. What could I use that for?


I send out a packet and get the returned object,

p1 = interface.sendData(byteData=b’\x00’)
p2 = interface.sendData(byteData=b’\xab’)
p3 = interface.sendData(byteData=b’123foobar’)

Results are:

p1: decoded { data { payload: “\000” } }
p2: decoded { data { payload: “\253” } }
p3: decoded { data { payload: “123foobar” } }

Are those payloads correct? I’m not highly proficient working with Python bytes, but p1 and p2 are apparently octal codes, but p3 is the text directly. It seems odd.


I was also having trouble sending to specific destinationId addresses. If i use a device id directly, I get the Python dictionary attribute error:

Exception has occurred: AttributeError
‘dict’ object has no attribute ‘num’

In the library’s sendPacket definition,

if isinstance(destinationId, int):
    nodeNum = destinationId
elif destinationId == BROADCAST_ADDR:
    nodeNum = BROADCAST_NUM
    nodeNum = self.nodes[destinationId].num

Line 165 (the last line above) throws the error, since the dictionary keys are strings. Wouldn’t this be correct instead? Or does the google protobuf stuff do some magic that failed to work for me here? (I have yet to learn what exactly protobuf does…)

nodeNum = self.nodes[destinationId][‘num’]


Thanks again!

Great questions! Here’s some answers:

Q1: oops - it looks like we are forgetting to base64 decode the string for incoming binary packets. (MTIzZm9vYmFy is base64 for 123foobar). Do you mind putting a bug in for meshtastic-python and I’ll fix it tomorrow or Friday?

Q2: That looks correct to me - python byte arrays are really strings down at the bottom. The reason only the first two are shown as octal is that python tries to print as ASCII if it can, but if it can’t it will show as octal.

Q3: This was a bug that was fixed a few days ago. Just do “pip3 install --upgrade meshtastic” and it should go away.

Perfect, thank you!

  1. That figures - I just needed my translator droid to speak Bocce… OK, I’ve created a bug for you over in github!
  2. Good to know. Those are the little programmer things that are easy to explain but hard to find references and answers for. Now that you explained it, I’ll find that information everywhere!
  3. Indeed it went away. I’d just installed meshtastic in the past day or two. Great that you’re handling the bugs so fast! I’ll make sure to update and check if I encounter other potential bugs!

That solves my first round, guess I’ll try and stir up more trouble!

1 Like

ooh - I just thought of something:

‘decoded’: {‘data’: {‘payload’: ‘MTIzZm9vYmFy’, ‘typ’: ‘OPAQUE’}}

Might just be an artifact of how the ‘toString’ method for dictionary is implemented. I haven’t looked yet, but the behavior there might be ‘try to show as JSON’. And JSON doesn’t understand binary arrays, so it shows it as base64. But if you were to programmatically look at, I bet you would find it is a byte array containing b’123foobar’. So everything might be actually fine.