diff --git a/.vscode/launch.json b/.vscode/launch.json index 93dc3c2..b803dd7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -26,7 +26,7 @@ "request": "launch", "module": "meshtastic", "justMyCode": true, - "args": ["--debug", "--set", "a", "1", "--set", "b", "2"] + "args": ["--debug", "--setchan", "psk", "fish"] }, { "name": "meshtastic shell", diff --git a/docs/meshtastic/index.html b/docs/meshtastic/index.html index 32c7f9e..4b22122 100644 --- a/docs/meshtastic/index.html +++ b/docs/meshtastic/index.html @@ -48,6 +48,18 @@ If you want to see all packets, simply subscribe to "meshtastic.receive".
We receive position, user, or data packets from the mesh. +You probably only care about meshtastic.receive.data. +The first argument for +that publish will be the packet. +Text or binary data packets (from sendData or sendText) will both arrive this way. +If you print packet +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 +sendText, decoded.data.text will also be populated with the decoded string. +For ASCII these two strings will be the same, but for +unicode scripts they can be different.
import meshtastic
from pubsub import pub
@@ -97,6 +109,12 @@ type of packet, you should subscribe to the full topic name. If you want to see
- meshtastic.receive.data(packet)
- meshtastic.node.updated(node = NodeInfo) - published when a node in the DB changes (appears, location changed, username changed, etc...)
+We receive position, user, or data packets from the mesh. You probably only care about meshtastic.receive.data. The first argument for
+that publish will be the packet. Text or binary data packets (from sendData or sendText) will both arrive this way. If you print packet
+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
+sendText, decoded.data.text will **also** be populated with the decoded string. For ASCII these two strings will be the same, but for
+unicode scripts they can be different.
+
# Example Usage
```
import meshtastic
diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py
index 316367b..d1285ea 100644
--- a/meshtastic/__main__.py
+++ b/meshtastic/__main__.py
@@ -7,6 +7,8 @@ import sys
from pubsub import pub
import google.protobuf.json_format
import pyqrcode
+import traceback
+import codecs
"""The command line arguments"""
args = None
@@ -87,39 +89,35 @@ def onConnected(interface):
if args.set or args.setstr or args.setchan:
closeNow = True
- # Handle the int/float/bool arguments
- for pref in (args.set or []):
- name = pref[0]
- #
+ def setPref(attributes, name, val):
+ """Set a preferences value"""
+ print(f"Setting {name} to {val}")
try:
- valstr = pref[1]
- val = fromStr(valstr)
- print(f"Setting preference {name} to {val}")
- setattr(interface.radioConfig.preferences, name, val)
+ try:
+ setattr(attributes, name, val)
+ except TypeError as ex:
+ # The setter didn't like our arg type - try again as a byte array (so we can convert strings to bytearray)
+ if isinstance(val, str):
+ setattr(attributes, name,
+ codecs.decode(val, "hex"))
+ else:
+ print(f"Incorrect type for {name} {ex}")
except Exception as ex:
print(f"Can't set {name} due to {ex}")
+ # Handle the int/float/bool arguments
+ for pref in (args.set or []):
+ setPref(
+ interface.radioConfig.preferences, pref[0], fromStr(pref[1]))
+
# Handle the string arguments
for pref in (args.setstr or []):
- name = pref[0]
- # try to parse as int, float or bool
- try:
- val = pref[1]
- print(f"Setting preference {name} to {val}")
- setattr(interface.radioConfig.preferences, name, val)
- except Exception as ex:
- print(f"Can't set {name} due to {ex}")
+ interface.radioConfig.preferences, setPref(pref[0], pref[1])
+ # Handle the channel settings
for pref in (args.setchan or []):
- name = pref[0]
- #
- try:
- valstr = pref[1]
- val = fromStr(valstr)
- print(f"Setting channel parameter {name} to {val}")
- setattr(interface.radioConfig.channel_settings, name, val)
- except Exception as ex:
- print(f"Can't set {name} due to {ex}")
+ setPref(interface.radioConfig.channel_settings,
+ pref[0], fromStr(pref[1]))
print("Writing modified preferences to device")
interface.writeConfig()
diff --git a/setup.py b/setup.py
index 6446664..6584771 100644
--- a/setup.py
+++ b/setup.py
@@ -12,7 +12,7 @@ with open("README.md", "r") as fh:
# This call to setup() does all the work
setup(
name="meshtastic",
- version="1.0.10",
+ version="1.0.11",
description="Python API & client shell for talking to Meshtastic devices",
long_description=long_description,
long_description_content_type="text/markdown",