mirror of
https://github.com/meshtastic/python.git
synced 2026-02-15 02:11:33 -05:00
1.0.5 fix #14, let users set bool,float or string params.
Example usage: Or to configure an ESP32 based board to join a wifi network as a station (wifi support in the device code is coming soon): ``` meshtastic --set wifi_ap_mode false --setstr wifi_ssid mywifissid --setstr wifi_password mywifipsw ``` Or to configure an ESP32 to run as a Wifi access point: ``` meshtastic --set wifi_ap_mode true --setstr wifi_ssid mywifissid --setstr wifi_password mywifipsw ```
This commit is contained in:
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@@ -26,7 +26,7 @@
|
||||
"request": "launch",
|
||||
"module": "meshtastic",
|
||||
"justMyCode": true,
|
||||
"args": ["--debug", "--setpref", "a", "1", "--setpref", "b", "2"]
|
||||
"args": ["--debug", "--set", "a", "1", "--set", "b", "2"]
|
||||
},
|
||||
{
|
||||
"name": "meshtastic shell",
|
||||
|
||||
14
README.md
14
README.md
@@ -28,12 +28,24 @@ You can also use this tool to set any of the device parameters which are stored
|
||||
to keep the bluetooth link alive for eight hours (any usage of the bluetooth protcol from your phone will reset this timer)
|
||||
|
||||
```
|
||||
meshtastic --setpref wait_bluetooth_secs 28800
|
||||
meshtastic --set wait_bluetooth_secs 28800
|
||||
Connected to radio...
|
||||
Setting preference wait_bluetooth_secs to 28800
|
||||
Writing modified preferences to device...
|
||||
```
|
||||
|
||||
Or to configure an ESP32 based board to join a wifi network as a station (wifi support in the device code is coming soon):
|
||||
|
||||
```
|
||||
meshtastic --set wifi_ap_mode false --setstr wifi_ssid mywifissid --setstr wifi_password mywifipsw
|
||||
```
|
||||
|
||||
Or to configure an ESP32 to run as a Wifi access point:
|
||||
|
||||
```
|
||||
meshtastic --set wifi_ap_mode true --setstr wifi_ssid mywifissid --setstr wifi_password mywifipsw
|
||||
```
|
||||
|
||||
## Required device software version
|
||||
|
||||
This API and tool both require that the device is running Meshtastic 0.6.0 or later.
|
||||
|
||||
@@ -28,13 +28,15 @@ def onReceive(packet, interface):
|
||||
rxSnr = packet['rxSnr']
|
||||
hopLimit = packet['hopLimit']
|
||||
print(f"message: {msg}")
|
||||
reply="got msg \'{}\' with rxSnr: {} and hopLimit: {}".format(msg,rxSnr,hopLimit)
|
||||
print("Sending reply: ",reply)
|
||||
reply = "got msg \'{}\' with rxSnr: {} and hopLimit: {}".format(
|
||||
msg, rxSnr, hopLimit)
|
||||
print("Sending reply: ", reply)
|
||||
interface.sendText(reply)
|
||||
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
|
||||
def onConnection(interface, topic=pub.AUTO_TOPIC):
|
||||
"""Callback invoked when we connect/disconnect from a radio"""
|
||||
print(f"Connection changed: {topic.getName()}")
|
||||
@@ -44,8 +46,8 @@ def onConnected(interface):
|
||||
"""Callback invoked when we connect to a radio"""
|
||||
global args
|
||||
print("Connected to radio")
|
||||
closeNow = False # Should we drop the connection after we finish?
|
||||
try:
|
||||
|
||||
if args.settime:
|
||||
print("Setting device RTC time")
|
||||
# can include lat/long/alt etc: latitude = 37.5, longitude = -122.1
|
||||
@@ -56,20 +58,51 @@ def onConnected(interface):
|
||||
interface.sendText(args.sendtext, args.dest,
|
||||
wantAck=True, wantResponse=True)
|
||||
|
||||
if args.setpref:
|
||||
for pref in args.setpref:
|
||||
if args.set or args.setstr:
|
||||
closeNow = True
|
||||
|
||||
# Handle the int/float/bool arguments
|
||||
for pref in (args.set or []):
|
||||
name = pref[0]
|
||||
print(f"Setting preference {name} to {pref[1]}")
|
||||
# FIXME, currently this tool only supports setting integers
|
||||
# try to parse as int, float or bool
|
||||
try:
|
||||
val = int(pref[1])
|
||||
valstr = pref[1]
|
||||
try:
|
||||
val = int(valstr)
|
||||
except ValueError:
|
||||
try:
|
||||
val = float(valstr)
|
||||
except ValueError:
|
||||
trueTerms = {"t", "true", "yes"}
|
||||
falseTerms = {"f", "false", "no"}
|
||||
if valstr in trueTerms:
|
||||
val = True
|
||||
elif valstr in falseTerms:
|
||||
val = False
|
||||
else:
|
||||
raise Exception(
|
||||
"Value must be numeric or boolean")
|
||||
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}")
|
||||
|
||||
# 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}")
|
||||
|
||||
print("Writing modified preferences to device")
|
||||
interface.writeConfig()
|
||||
|
||||
if args.info:
|
||||
closeNow = True
|
||||
print(interface.myInfo)
|
||||
print(interface.radioConfig)
|
||||
print("Nodes in mesh:")
|
||||
@@ -78,7 +111,7 @@ def onConnected(interface):
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
if args.info or args.setpref:
|
||||
if closeNow:
|
||||
interface.close() # after running command then exit
|
||||
|
||||
|
||||
@@ -113,7 +146,10 @@ def main():
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument(
|
||||
"--setpref", help="Set a preferences field", nargs=2, action='append')
|
||||
"--set", help="Set a numeric preferences field", nargs=2, action='append')
|
||||
|
||||
parser.add_argument(
|
||||
"--setstr", help="Set a string preferences field", nargs=2, action='append')
|
||||
|
||||
parser.add_argument(
|
||||
"--dest", help="The destination node id for the --send commands, if not set '^all' is assumed", default="^all")
|
||||
@@ -144,7 +180,7 @@ def main():
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
|
||||
|
||||
if (not args.seriallog) and (args.info or args.setpref or args.sendtext):
|
||||
if (not args.seriallog) and (args.info or args.set or args.setstr or args.sendtext):
|
||||
args.seriallog = "none" # assume no debug output in this case
|
||||
|
||||
if args.test:
|
||||
|
||||
File diff suppressed because one or more lines are too long
2
proto
2
proto
Submodule proto updated: 2824331686...ce422b7c44
2
setup.py
2
setup.py
@@ -10,7 +10,7 @@ with open("README.md", "r") as fh:
|
||||
# This call to setup() does all the work
|
||||
setup(
|
||||
name="meshtastic",
|
||||
version="1.0.4",
|
||||
version="1.0.5",
|
||||
description="Python API & client shell for talking to Meshtastic devices",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
|
||||
Reference in New Issue
Block a user