Skip to content

Instantly share code, notes, and snippets.

@joshcarter
Created October 5, 2022 04:02
Show Gist options
  • Save joshcarter/7908328a5e2dfb1c2d57584f4f42d7fd to your computer and use it in GitHub Desktop.
Save joshcarter/7908328a5e2dfb1c2d57584f4f42d7fd to your computer and use it in GitHub Desktop.
Meshtastic Python API example
from time import sleep
import meshtastic
import meshtastic.serial_interface
from pubsub import pub
def on_receive(packet, interface):
print(f'received: {packet}')
def on_connection(interface, topic=pub.AUTO_TOPIC):
interface.sendText('hello mesh')
def run():
pub.subscribe(on_receive, 'meshtastic.receive')
pub.subscribe(on_connection, 'meshtastic.connection.established')
interface = meshtastic.serial_interface.SerialInterface('/dev/cu.usbmodem54750409071')
num = 1
while True:
sleep(1)
interface.sendText(f'mac: {num}')
num += 1
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment