mirror of
https://github.com/meshtastic/python.git
synced 2026-01-09 08:17:55 -05:00
Merge pull request #135 from Hydra-Designs/master
Added very basic implementation of configure command for provisioning / setting preferences via yaml
This commit is contained in:
15
example_config.yaml
Normal file
15
example_config.yaml
Normal file
@@ -0,0 +1,15 @@
|
||||
owner: Bob TBeam
|
||||
|
||||
channel_url: https://www.meshtastic.org/d/#CgUYAyIBAQ
|
||||
|
||||
location:
|
||||
lat: 35.88888
|
||||
lon: -93.88888
|
||||
alt: 304
|
||||
|
||||
user_prefs:
|
||||
region: 1
|
||||
is_always_powered: true
|
||||
send_owner_interval: 2
|
||||
screen_on_secs: 31536000
|
||||
wait_bluetooth_secs: 31536000
|
||||
@@ -8,6 +8,7 @@ import logging
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
import yaml
|
||||
from pubsub import pub
|
||||
import pyqrcode
|
||||
import pkg_resources
|
||||
@@ -351,6 +352,49 @@ def onConnected(interface):
|
||||
print("Writing modified preferences to device")
|
||||
getNode().writeConfig()
|
||||
|
||||
if args.configure:
|
||||
with open(args.configure[0]) as file:
|
||||
configuration = yaml.safe_load(file)
|
||||
closeNow = True
|
||||
|
||||
if 'owner' in configuration:
|
||||
print(f"Setting device owner to {configuration['owner']}")
|
||||
getNode().setOwner(configuration['owner'])
|
||||
|
||||
if 'channel_url' in configuration:
|
||||
print("Setting channel url to", configuration['channel_url'])
|
||||
getNode().setURL(configuration['channel_url'])
|
||||
|
||||
if 'location' in configuration:
|
||||
alt = 0
|
||||
lat = 0.0
|
||||
lon = 0.0
|
||||
time = 0 # always set time, but based on the local clock
|
||||
prefs = interface.localNode.radioConfig.preferences
|
||||
|
||||
if 'alt' in configuration['location']:
|
||||
alt = int(configuration['location']['alt'])
|
||||
prefs.fixed_position = True
|
||||
print(f"Fixing altitude at {alt} meters")
|
||||
if 'lat' in configuration['location']:
|
||||
lat = float(configuration['location']['lat'])
|
||||
prefs.fixed_position = True
|
||||
print(f"Fixing latitude at {lat} degrees")
|
||||
if 'lon' in configuration['location']:
|
||||
lon = float(configuration['location']['lon'])
|
||||
prefs.fixed_position = True
|
||||
print(f"Fixing longitude at {lon} degrees")
|
||||
print("Setting device position")
|
||||
interface.sendPosition(lat, lon, alt, time)
|
||||
interface.localNode.writeConfig()
|
||||
|
||||
if 'user_prefs' in configuration:
|
||||
prefs = getNode().radioConfig.preferences
|
||||
for pref in configuration['user_prefs']:
|
||||
setPref(prefs, pref, str(configuration['user_prefs'][pref]))
|
||||
print("Writing modified preferences to device")
|
||||
getNode().writeConfig()
|
||||
|
||||
if args.seturl:
|
||||
closeNow = True
|
||||
getNode().setURL(args.seturl)
|
||||
@@ -568,6 +612,11 @@ def initParser():
|
||||
""" Initialize the command line argument parsing."""
|
||||
global parser, args
|
||||
|
||||
parser.add_argument(
|
||||
"--configure",
|
||||
help="Specify a path to a yaml(.yml) file containing the desired settings for the connected device.",
|
||||
action='append')
|
||||
|
||||
parser.add_argument(
|
||||
"--port",
|
||||
help="The port the Meshtastic device is connected to, i.e. /dev/ttyUSB0. If unspecified, we'll try to find it.",
|
||||
|
||||
@@ -54,3 +54,4 @@ urllib3==1.26.7
|
||||
webencodings==0.5.1
|
||||
wrapt==1.13.3
|
||||
zipp==3.6.0
|
||||
pyyaml==5.3.0
|
||||
Reference in New Issue
Block a user