I found the following example in the documentation:
import meshtastic
from pubsub import pub
def onReceive(packet, interface): # called when a packet arrives
print(f"Received: {packet}")
def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect to the radio
# defaults to broadcast, specify a destination ID if you wish
interface.sendText("hello mesh")
pub.subscribe(onReceive, "meshtastic.receive")
pub.subscribe(onConnection, "meshtastic.connection.established")
# By default will try to find a meshtastic device, otherwise provide a device path like /dev/ttyUSB0
interface = meshtastic.SerialInterface()
Thing is, it exits immediately. Is there a way to make it loop forever, printing incoming messages as they go?
You can run your main program loop in there (read inputs, print outputs etc), or if there is none, you can do what the example code does - sleep() in an infinite loop:
I found the following example in the documentation:
Thing is, it exits immediately. Is there a way to make it loop forever, printing incoming messages as they go?