Skip to content

Commit b54ac0e

Browse files
committed
Add sensor-config commands
1 parent cdf893e commit b54ac0e

2 files changed

Lines changed: 56 additions & 0 deletions

File tree

meshtastic/__main__.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,11 @@ def setSimpleConfig(modem_preset):
10851085
print(f"Waiting {args.wait_to_disconnect} seconds before disconnecting")
10861086
time.sleep(int(args.wait_to_disconnect))
10871087

1088+
if args.sensor_config:
1089+
closeNow = True
1090+
waitForAckNak = True
1091+
interface.getNode(args.dest, False, **getNode_kwargs).sensorConfig(args.sensor_config)
1092+
10881093
# if the user didn't ask for serial debugging output, we might want to exit after we've done our operation
10891094
if (not args.seriallog) and closeNow:
10901095
interface.close() # after running command then exit
@@ -1983,6 +1988,14 @@ def addRemoteAdminArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPars
19831988
metavar="TIMESTAMP",
19841989
)
19851990

1991+
group.add_argument(
1992+
"--sensor-config",
1993+
help="Send a sensor admin command to configure sensor parameters.",
1994+
action="store",
1995+
nargs=2,
1996+
default=None
1997+
)
1998+
19861999
return parser
19872000

19882001
def initParser():

meshtastic/node.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,49 @@ def onAckNak(self, p):
977977
print(f"Received an ACK.")
978978
self.iface._acknowledgment.receivedAck = True
979979

980+
def sensorConfig(self, command: List = None):
981+
"""Send a sensor configuration command"""
982+
self.ensureSessionKey()
983+
984+
p = admin_pb2.AdminMessage()
985+
if 'scd4x_config' in command[0]:
986+
if 'set_asc' in command[0]:
987+
if command[1] == "true":
988+
p.sensor_config.scd4x_config.set_asc = True
989+
print ("Setting SCD4X ASC mode")
990+
elif command[1] == "false":
991+
p.sensor_config.scd4x_config.set_asc = False
992+
print ("Setting SCD4X FRC mode")
993+
else:
994+
print(
995+
f'Not valid argument for sensor_config.scd4x.set_asc'
996+
)
997+
elif 'set_temperature' in command[0]:
998+
try:
999+
temperature = float(command[1])
1000+
except ValueError:
1001+
print(
1002+
f'Invalid value for reference temperature'
1003+
)
1004+
return
1005+
else:
1006+
print (f"Setting SCD4X Reference temperature to {temperature}")
1007+
p.sensor_config.scd4x_config.set_temperature = temperature
1008+
elif 'factory_reset' in command[0]:
1009+
print ("Performing factory reset on SCD4X")
1010+
p.sensor_config.scd4x_config.factory_reset = True
1011+
# TODO - add the rest?
1012+
1013+
elif 'sen5x_config' in command[0]:
1014+
raise NotImplementedError("Not implemented")
1015+
1016+
# How to represent a HANDLED event?
1017+
if self == self.iface.localNode:
1018+
onResponse = None
1019+
else:
1020+
onResponse = self.onAckNak
1021+
return self._sendAdmin(p, onResponse=onResponse)
1022+
9801023
def _requestChannel(self, channelNum: int):
9811024
"""Done with initial config messages, now send regular
9821025
MeshPackets to ask for settings"""

0 commit comments

Comments
 (0)