meshtastic / python

The Python CLI and API for talking to Meshtastic devices
https://meshtastic.org
379 stars 160 forks source link

Python code to receive text. #557

Closed ghost closed 5 months ago

ghost commented 5 months ago

I just need a good snippet for receiving text over the mesh using python. I see lots of ways to send text, unless im just looking at this all wrong. What i want to do is have a way to send custom commands to a machine that has a lora radio. I have the script mostly done i can't seem to find a way to receive text any help will do thanks.

ianmcorvidae commented 5 months ago

You might be able to find what you need in https://github.com/pdxlocations/Meshtastic-Python-Examples/blob/main/send-and-receive.py or another script in that repository; there's several good examples there.

The basic structure of "how to receive text" is: 1.) write a function that takes a packet and a MeshInterface as arguments that does what you want when receiving. You can check the portnum within the decoded field of the packet to make sure you've got a message that's of the type you want (text, sounds like, which would be TEXT_MESSAGE_APP. 2.) (assuming the above function is named onReceive) add a line like pub.subscribe(onReceive, 'meshtastic.receive') (where pub is from the pubsub module)

ghost commented 5 months ago

Thank you.