Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,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)

Comment on lines +1124 to +1128
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--sensor-config is executed after the global ACK/NAK wait block, but it sets waitForAckNak = True only inside this late block. As a result, remote --sensor-config commands won’t trigger the “Waiting for an acknowledgment…” path and the interface may close immediately after sending. Please move this handling up with the other remote-admin actions (before the ACK/NAK wait section), or explicitly call iface.waitForAckNak() right after sensorConfig() when --dest is remote.

Copilot uses AI. Check for mistakes.
# 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
Expand Down Expand Up @@ -2035,6 +2040,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='+',
default=None
)
Comment on lines +2043 to +2049
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New CLI surface area (--sensor-config) isn’t covered by the existing meshtastic/tests/test_main.py CLI tests (which already validate many other flags). Please add at least a basic unit test that initParser() accepts --sensor-config and that onConnected() routes it to Node.sensorConfig() with the expected argument list.

Copilot uses AI. Check for mistakes.

return parser

def initParser():
Expand Down
174 changes: 174 additions & 0 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,180 @@ def onAckNak(self, p):
print(f"Received an ACK.")
self.iface._acknowledgment.receivedAck = True

def sensorConfig(self, commands: List = None):
"""Send a sensor configuration command"""
self.ensureSessionKey()

Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sensorConfig() defaults commands to None but immediately iterates over it (for command in commands), which will raise a TypeError if the method is called without CLI args (or with an empty value from other API consumers). Please guard against commands is None (and possibly len(commands)==0) early and exit with a clear message or exception.

Suggested change
if not commands:
print("No sensor configuration commands were provided.")
return

Copilot uses AI. Check for mistakes.
p = admin_pb2.AdminMessage()
if any(['scd4x_config' in command for command in commands]):
cleanup_commands = [command.replace('scd4x_config.', '') for command in commands]

if 'factory_reset' in cleanup_commands:
print ("Performing factory reset on SCD4X")
p.sensor_config.scd4x_config.factory_reset = True
elif 'scd4xdisables.disable_trh' in cleanup_commands:
print (cleanup_commands)
print ("Disabling SCD4X sensors")
if cleanup_commands[cleanup_commands.index('scd4xdisables.disable_trh')+1] == "true":
p.sensor_config.scd4x_config.scd4xdisables.disable_trh = True
print ("Disabling temperature")
elif cleanup_commands[cleanup_commands.index('scd4xdisables.disable_trh')+1] == "false":
p.sensor_config.scd4x_config.scd4xdisables.disable_trh = False
print ("Enabling temperature")
else:
if 'set_asc' in cleanup_commands:
if cleanup_commands[cleanup_commands.index('set_asc')+1] == "true":
p.sensor_config.scd4x_config.set_asc = True
print ("Setting SCD4X ASC mode")
elif cleanup_commands[cleanup_commands.index('set_asc')+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_config.set_asc'
)
if 'set_target_co2_conc' in cleanup_commands:
try:
target_co2_conc = int(cleanup_commands[cleanup_commands.index('set_target_co2_conc')+1])
except ValueError:
print(
f'Invalid value for target CO2 conc'
)
return
else:
print (f"Setting SCD4X target CO2 conc to {target_co2_conc}")
p.sensor_config.scd4x_config.set_target_co2_conc = target_co2_conc
send_command = True
if 'set_temperature' in cleanup_commands:
try:
temperature = float(cleanup_commands[cleanup_commands.index('set_temperature')+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
send_command = True
Comment on lines +1038 to +1052
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

send_command is assigned but never read. This is dead code and may trigger linting failures; either remove it or use it to control the “Nothing to request”/sending behavior consistently across all sensor config fields.

Copilot uses AI. Check for mistakes.
if 'set_altitude' in cleanup_commands:
try:
altitude = int(cleanup_commands[cleanup_commands.index('set_altitude')+1])
except ValueError:
print(
f'Invalid value for reference altitude'
)
return
else:
print (f"Setting SCD4X Reference altitude to {altitude}")
p.sensor_config.scd4x_config.set_altitude = altitude
if 'set_ambient_pressure' in cleanup_commands:
try:
ambient_pressure = int(cleanup_commands[cleanup_commands.index('set_ambient_pressure')+1])
except ValueError:
print(
f'Invalid value for reference ambient pressure'
)
return
else:
print (f"Setting SCD4X Reference ambient pressure to {ambient_pressure}")
p.sensor_config.scd4x_config.set_ambient_pressure = ambient_pressure

if any(['sen5x_config' in command for command in commands]):
cleanup_commands = [command.replace('sen5x_config.', '') for command in commands]
if 'set_one_shot_mode' in cleanup_commands:
if cleanup_commands[cleanup_commands.index('set_one_shot_mode')+1] == "true":
p.sensor_config.sen5x_config.set_one_shot_mode = True
print ("Setting SEN5X one shot mode")
elif cleanup_commands[cleanup_commands.index('set_one_shot_mode')+1] == "false":
p.sensor_config.sen5x_config.set_one_shot_mode = False
print ("Setting SEN5X continuous mode")
else:
print(
f'Not valid argument for sensor_config.sen5x_config.set_one_shot_mode'
)

if any(['scd30_config' in command for command in commands]):
cleanup_commands = [command.replace('scd30_config.', '') for command in commands]

if 'soft_reset' in cleanup_commands:
print ("Performing soft reset on SCD30")
p.sensor_config.scd30_config.soft_reset = True
else:
if 'set_asc' in cleanup_commands:
if cleanup_commands[cleanup_commands.index('set_asc')+1] == "true":
p.sensor_config.scd30_config.set_asc = True
print ("Setting SCD30 ASC mode")
elif cleanup_commands[cleanup_commands.index('set_asc')+1] == "false":
p.sensor_config.scd30_config.set_asc = False
print ("Setting SCD30 FRC mode")
else:
print(
f'Not valid argument for sensor_config.scd30_config.set_asc'
)
if 'set_target_co2_conc' in cleanup_commands:
try:
target_co2_conc = int(cleanup_commands[cleanup_commands.index('set_target_co2_conc')+1])
except ValueError:
print(
f'Invalid value for target CO2 conc'
)
return
else:
print (f"Setting SCD30 target CO2 conc to {target_co2_conc}")
p.sensor_config.scd30_config.set_target_co2_conc = target_co2_conc
send_command = True
if 'set_temperature' in cleanup_commands:
try:
temperature = float(cleanup_commands[cleanup_commands.index('set_temperature')+1])
except ValueError:
print(
f'Invalid value for reference temperature'
)
return
else:
print (f"Setting SCD30 Reference temperature to {temperature}")
p.sensor_config.scd30_config.set_temperature = temperature
send_command = True
if 'set_altitude' in cleanup_commands:
try:
altitude = int(cleanup_commands[cleanup_commands.index('set_altitude')+1])
except ValueError:
print(
f'Invalid value for reference altitude'
)
return
else:
print (f"Setting SCD30 Reference altitude to {altitude}")
p.sensor_config.scd30_config.set_altitude = altitude
if 'set_measurement_interval' in cleanup_commands:
try:
measurement_interval = int(cleanup_commands[cleanup_commands.index('set_measurement_interval')+1])
except ValueError:
print(
f'Invalid value for measurement interval'
)
return
else:
print (f"Setting SCD30 measurement interval to {measurement_interval}")
p.sensor_config.scd30_config.set_measurement_interval = measurement_interval


print ("Payload")
print (p.sensor_config)

# How to represent a HANDLED event?
if self == self.iface.localNode:
onResponse = None
else:
onResponse = self.onAckNak

if p.ByteSize():
# TODO - Should this require a response?
return self._sendAdmin(p, onResponse=onResponse)
else:
print ('Nothing to request')

def _requestChannel(self, channelNum: int):
"""Done with initial config messages, now send regular
MeshPackets to ask for settings"""
Expand Down
Loading