File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ #
3+ # Released Under GNU GPLv3
4+ # Copyright 2025 Henri Shustak
5+ #
6+ # About :
7+ # This script will print messages as they arrive from a meshtastic node connected via serial port USB.
8+ # If you have multiple nodes attached, you will need to edit this script and specify the node to monitor.
9+ # https://gist.github.com/henri/a6584d55813f971e5b1a4ee940c07d25
10+ #
11+ # Requirements :
12+ # You will need to install python meshtastic libraries : https://github.com/meshtastic/python
13+ #
14+ # Version History :
15+ # 1.0 - initial release
16+ # 1.1 - added support for sender id and bug fixs
17+
18+ import time
19+ import meshtastic
20+ import meshtastic .serial_interface
21+ from pubsub import pub
22+
23+ def onReceive (packet , interface ):
24+ # DEBUGGING
25+ # print(f"message arrived")
26+ # print(f"{packet}")
27+ try :
28+ if packet ['decoded' ]['portnum' ] == 'TEXT_MESSAGE_APP' :
29+ message = packet ['decoded' ]['text' ]
30+ channel_num = packet ['channel' ]
31+ sender_id = packet ['fromId' ]
32+ print (f"{ channel_num } : { sender_id } : { message } " )
33+ except KeyError as e :
34+ print (f"unable to decode message" )
35+ return
36+
37+ #pub.subscribe(onReceive, "meshtastic.receive.text")
38+ pub .subscribe (onReceive , "meshtastic.receive" )
39+
40+ # try to find a meshtastic device, otherwise provide a device path like /dev/ttyUSB0
41+ interface = meshtastic .serial_interface .SerialInterface ()
42+
43+ while True :
44+ time .sleep (10 ) # wait for the next message
45+
You can’t perform that action at this time.
0 commit comments