From b54ac0e0f0aaee60c5a54069e47bbb6c7818447a Mon Sep 17 00:00:00 2001 From: oscgonfer Date: Sun, 8 Feb 2026 18:10:28 +0100 Subject: [PATCH] Add sensor-config commands --- meshtastic/__main__.py | 13 +++++++++++++ meshtastic/node.py | 43 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index 16854002..f826e992 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -1085,6 +1085,11 @@ def setSimpleConfig(modem_preset): print(f"Waiting {args.wait_to_disconnect} seconds before disconnecting") time.sleep(int(args.wait_to_disconnect)) + if args.sensor_config: + closeNow = True + waitForAckNak = True + interface.getNode(args.dest, False, **getNode_kwargs).sensorConfig(args.sensor_config) + # if the user didn't ask for serial debugging output, we might want to exit after we've done our operation if (not args.seriallog) and closeNow: interface.close() # after running command then exit @@ -1983,6 +1988,14 @@ def addRemoteAdminArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPars metavar="TIMESTAMP", ) + group.add_argument( + "--sensor-config", + help="Send a sensor admin command to configure sensor parameters.", + action="store", + nargs=2, + default=None + ) + return parser def initParser(): diff --git a/meshtastic/node.py b/meshtastic/node.py index afb5611a..304d3bcb 100644 --- a/meshtastic/node.py +++ b/meshtastic/node.py @@ -977,6 +977,49 @@ def onAckNak(self, p): print(f"Received an ACK.") self.iface._acknowledgment.receivedAck = True + def sensorConfig(self, command: List = None): + """Send a sensor configuration command""" + self.ensureSessionKey() + + p = admin_pb2.AdminMessage() + if 'scd4x_config' in command[0]: + if 'set_asc' in command[0]: + if command[1] == "true": + p.sensor_config.scd4x_config.set_asc = True + print ("Setting SCD4X ASC mode") + elif command[1] == "false": + p.sensor_config.scd4x_config.set_asc = False + print ("Setting SCD4X FRC mode") + else: + print( + f'Not valid argument for sensor_config.scd4x.set_asc' + ) + elif 'set_temperature' in command[0]: + try: + temperature = float(command[1]) + except ValueError: + print( + f'Invalid value for reference temperature' + ) + return + else: + print (f"Setting SCD4X Reference temperature to {temperature}") + p.sensor_config.scd4x_config.set_temperature = temperature + elif 'factory_reset' in command[0]: + print ("Performing factory reset on SCD4X") + p.sensor_config.scd4x_config.factory_reset = True + # TODO - add the rest? + + elif 'sen5x_config' in command[0]: + raise NotImplementedError("Not implemented") + + # How to represent a HANDLED event? + if self == self.iface.localNode: + onResponse = None + else: + onResponse = self.onAckNak + return self._sendAdmin(p, onResponse=onResponse) + def _requestChannel(self, channelNum: int): """Done with initial config messages, now send regular MeshPackets to ask for settings"""