|
2 | 2 | # A library for the Meshtastic Client API |
3 | 3 |
|
4 | 4 | Primary interfaces: SerialInterface, TCPInterface, BLEInterface |
| 5 | +
|
5 | 6 | Install with pip: "[pip3 install meshtastic](https://pypi.org/project/meshtastic/)" |
| 7 | +
|
6 | 8 | Source code on [github](https://github.com/meshtastic/python) |
7 | 9 |
|
8 | 10 | notable properties of interface classes: |
9 | 11 |
|
10 | | -- nodes - The database of received nodes. Includes always up-to-date location and username information for each |
| 12 | +- `nodes` - The database of received nodes. Includes always up-to-date location and username information for each |
11 | 13 | node in the mesh. This is a read-only datastructure. |
12 | | -- nodesByNum - like "nodes" but keyed by nodeNum instead of nodeId |
13 | | -- myInfo & metadata - Contain read-only information about the local radio device (software version, hardware version, etc) |
14 | | -- localNode - Pointer to a node object for the local node |
| 14 | +- `nodesByNum` - like "nodes" but keyed by nodeNum instead of nodeId. As such, includes "unknown" nodes which haven't seen a User packet yet |
| 15 | +- `myInfo` & `metadata` - Contain read-only information about the local radio device (software version, hardware version, etc) |
| 16 | +- `localNode` - Pointer to a node object for the local node |
15 | 17 |
|
16 | 18 | notable properties of nodes: |
17 | | -- localConfig - Current radio settings, can be written to the radio with the `writeConfig` method. |
18 | | -- moduleConfig - Current module settings, can be written to the radio with the `writeConfig` method. |
19 | | -- channels - The node's channels, keyed by index. |
| 19 | +
|
| 20 | +- `localConfig` - Current radio settings, can be written to the radio with the `writeConfig` method. |
| 21 | +- `moduleConfig` - Current module settings, can be written to the radio with the `writeConfig` method. |
| 22 | +- `channels` - The node's channels, keyed by index. |
20 | 23 |
|
21 | 24 | # Published PubSub topics |
22 | 25 |
|
23 | 26 | We use a [publish-subscribe](https://pypubsub.readthedocs.io/en/v4.0.3/) model to communicate asynchronous events. Available |
24 | 27 | topics: |
25 | 28 |
|
26 | | -- meshtastic.connection.established - published once we've successfully connected to the radio and downloaded the node DB |
27 | | -- meshtastic.connection.lost - published once we've lost our link to the radio |
28 | | -- meshtastic.receive.text(packet) - delivers a received packet as a dictionary, if you only care about a particular |
| 29 | +- `meshtastic.connection.established` - published once we've successfully connected to the radio and downloaded the node DB |
| 30 | +- `meshtastic.connection.lost` - published once we've lost our link to the radio |
| 31 | +- `meshtastic.receive.text(packet)` - delivers a received packet as a dictionary, if you only care about a particular |
29 | 32 | type of packet, you should subscribe to the full topic name. If you want to see all packets, simply subscribe to "meshtastic.receive". |
30 | | -- meshtastic.receive.position(packet) |
31 | | -- meshtastic.receive.user(packet) |
32 | | -- meshtastic.receive.data.portnum(packet) (where portnum is an integer or well known PortNum enum) |
33 | | -- meshtastic.node.updated(node = NodeInfo) - published when a node in the DB changes (appears, location changed, username changed, etc...) |
34 | | -- meshtastic.log.line(line) - a raw unparsed log line from the radio |
35 | | -
|
36 | | -We receive position, user, or data packets from the mesh. You probably only care about meshtastic.receive.data. The first argument for |
37 | | -that publish will be the packet. Text or binary data packets (from sendData or sendText) will both arrive this way. If you print packet |
38 | | -you'll see the fields in the dictionary. decoded.data.payload will contain the raw bytes that were sent. If the packet was sent with |
39 | | -sendText, decoded.data.text will **also** be populated with the decoded string. For ASCII these two strings will be the same, but for |
| 33 | +- `meshtastic.receive.position(packet)` |
| 34 | +- `meshtastic.receive.user(packet)` |
| 35 | +- `meshtastic.receive.data.portnum(packet)` (where portnum is an integer or well known PortNum enum) |
| 36 | +- `meshtastic.node.updated(node = NodeInfo)` - published when a node in the DB changes (appears, location changed, username changed, etc...) |
| 37 | +- `meshtastic.log.line(line)` - a raw unparsed log line from the radio |
| 38 | +
|
| 39 | +We receive position, user, or data packets from the mesh. You probably only care about `meshtastic.receive.data`. The first argument for |
| 40 | +that publish will be the packet. Text or binary data packets (from `sendData` or `sendText`) will both arrive this way. If you print packet |
| 41 | +you'll see the fields in the dictionary. `decoded.data.payload` will contain the raw bytes that were sent. If the packet was sent with |
| 42 | +`sendText`, `decoded.data.text` will **also** be populated with the decoded string. For ASCII these two strings will be the same, but for |
40 | 43 | unicode scripts they can be different. |
41 | 44 |
|
42 | 45 | # Example Usage |
|
0 commit comments