mirror of
https://github.com/meshtastic/python.git
synced 2025-12-24 08:27:55 -05:00
add commandline option for setting radio configs
This commit is contained in:
2
TODO.md
2
TODO.md
@@ -2,7 +2,6 @@
|
||||
|
||||
## Before beta
|
||||
|
||||
- make command line options for displaying/changing config
|
||||
- update nodedb as nodes change
|
||||
- radioConfig - getter/setter syntax: https://www.python-course.eu/python3_properties.php
|
||||
- let user change radio params via commandline options
|
||||
@@ -35,3 +34,4 @@
|
||||
- DONE keep everything in dicts
|
||||
- DONE have device send a special packet at boot so the serial client can detect if it rebooted
|
||||
- DONE add fromId and toId to received messages dictionaries
|
||||
- make command line options for displaying/changing config
|
||||
|
||||
@@ -121,6 +121,15 @@ class MeshInterface:
|
||||
toRadio.packet.CopyFrom(meshPacket)
|
||||
self._sendToRadio(toRadio)
|
||||
|
||||
def writeConfig(self):
|
||||
"""Write the current (edited) radioConfig to the device"""
|
||||
if self.radioConfig == None:
|
||||
raise Exception("No RadioConfig has been read")
|
||||
|
||||
t = mesh_pb2.ToRadio()
|
||||
t.set_radio.CopyFrom(self.radioConfig)
|
||||
self._sendToRadio(t)
|
||||
|
||||
def _disconnected(self):
|
||||
"""Called by subclasses to tell clients this interface has disconnected"""
|
||||
self.isConnected = False
|
||||
|
||||
@@ -20,14 +20,27 @@ def onConnection(interface, topic=pub.AUTO_TOPIC):
|
||||
"""Callback invoked when we connect/disconnect from a radio"""
|
||||
print(f"Connection changed: {topic.getName()}")
|
||||
global args
|
||||
if topic.getName() == "meshtastic.connection.established" and args.info:
|
||||
print(interface.myInfo)
|
||||
print(interface.radioConfig)
|
||||
interface.close()
|
||||
print("Nodes in mesh:")
|
||||
for n in interface.nodes.values():
|
||||
asDict = google.protobuf.json_format.MessageToJson(n)
|
||||
print(asDict)
|
||||
if topic.getName() == "meshtastic.connection.established":
|
||||
try:
|
||||
if args.setpref:
|
||||
name = args.setpref[0]
|
||||
val = int(args.setpref[1])
|
||||
setattr(interface.radioConfig.preferences, name, val)
|
||||
print("Writing modified preferences to device...")
|
||||
interface.writeConfig()
|
||||
|
||||
if args.info:
|
||||
print(interface.myInfo)
|
||||
print(interface.radioConfig)
|
||||
print("Nodes in mesh:")
|
||||
for n in interface.nodes.values():
|
||||
asDict = google.protobuf.json_format.MessageToJson(n)
|
||||
print(asDict)
|
||||
except Exception as ex:
|
||||
print(ex)
|
||||
|
||||
if args.info or args.setpref:
|
||||
interface.close() # after running command then exit
|
||||
|
||||
|
||||
def onNode(node):
|
||||
@@ -59,6 +72,8 @@ def main():
|
||||
parser.add_argument("--info", help="Read and display the radio config information",
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("--setpref", help="Set a preferences field", nargs=2)
|
||||
|
||||
parser.add_argument("--debug", help="Show API library debug log messages",
|
||||
action="store_true")
|
||||
|
||||
@@ -69,6 +84,9 @@ def main():
|
||||
args = parser.parse_args()
|
||||
logging.basicConfig(level=logging.DEBUG if args.debug else logging.INFO)
|
||||
|
||||
if args.info or args.setpref:
|
||||
args.seriallog = "none" # assume no debug output in this case
|
||||
|
||||
if args.test:
|
||||
test.testAll()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user