Skip to content
Draft
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 @@ -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
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
)

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()

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