File: pub_sub_example.py

package info (click to toggle)
meshtastic 2.7.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,596 kB
  • sloc: python: 10,741; sh: 76; makefile: 33
file content (30 lines) | stat: -rw-r--r-- 705 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""Simple program to demo how to use meshtastic library.
   To run: python examples/pub_sub_example.py
"""

import sys

from pubsub import pub

import meshtastic
import meshtastic.tcp_interface

# simple arg check
if len(sys.argv) < 2:
    print(f"usage: {sys.argv[0]} host")
    sys.exit(1)


def onConnection(interface, topic=pub.AUTO_TOPIC):  # pylint: disable=unused-argument
    """This is called when we (re)connect to the radio."""
    print(interface.myInfo)
    interface.close()


pub.subscribe(onConnection, "meshtastic.connection.established")

try:
    iface = meshtastic.tcp_interface.TCPInterface(sys.argv[1])
except:
    print(f"Error: Could not connect to {sys.argv[1]}")
    sys.exit(1)