Received: {'from': 3294300496, 'to': 4294967295, 'decoded': {'data': {'portnum': 'TEXT_MESSAGE_APP', 'payload': b'hi'}}, 'id': 2707257921, 'rxSnr': 9.75, 'hopLimit': 1, 'fromId': '!240ac45b0950', 'toId': '^all'}
b'hi'
ERROR:root:Error while handling message from radio 'dict' object has no attribute 'decode'
Traceback (most recent call last):
File "/usr/local/lib/python3.8/dist-packages/meshtastic/__init__.py", line 676, in __reader
self._handleFromRadio(self._rxBuf[HEADER_LEN:])
File "/usr/local/lib/python3.8/dist-packages/meshtastic/__init__.py", line 384, in _handleFromRadio
self._handlePacketFromRadio(fromRadio.packet)
File "/usr/local/lib/python3.8/dist-packages/meshtastic/__init__.py", line 513, in _handlePacketFromRadio
pub.sendMessage(topic, packet=asDict, interface=self)
File "/usr/local/lib/python3.8/dist-packages/pubsub/core/publisher.py", line 216, in sendMessage
topicObj.publish(**msgData)
File "/usr/local/lib/python3.8/dist-packages/pubsub/core/topicobj.py", line 452, in publish
self.__sendMessage(msgData, topicObj, msgDataSubset)
File "/usr/local/lib/python3.8/dist-packages/pubsub/core/topicobj.py", line 482, in __sendMessage
listener(data, self, allData)
File "/usr/local/lib/python3.8/dist-packages/pubsub/core/listener.py", line 237, in __call__
cb(**kwargs)
File "distmeshthread.py", line 39, in onReceive
data = packet.decode('utf-8')
AttributeError: 'dict' object has no attribute 'decode'
Now the follwing code is giving the above error
def onReceive(packet, interface):
print(f"Received: {packet}")
print(packet['decoded']['data']['payload'])
data = packet.decode('utf-8')
#packet = base64.b64encode(packet)
packet = json.dumps(data)
new = open('new.json', "w")
json.dump(packet, new, indent = 2)