Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add sensor-config commands
  • Loading branch information
oscgonfer committed Feb 8, 2026
commit b54ac0e0f0aaee60c5a54069e47bbb6c7818447a
13 changes: 13 additions & 0 deletions meshtastic/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Comment on lines +1124 to +1128

Copilot AI Mar 6, 2026

Copy link

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 @@ -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
)
Comment on lines +2043 to +2049

Copilot AI Mar 6, 2026

Copy link

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
43 changes: 43 additions & 0 deletions meshtastic/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Copilot AI Mar 6, 2026

Copy link

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 '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"""
Expand Down