Skip to content

Commit e3b3b4c

Browse files
committed
Add further admin commands
1 parent b54ac0e commit e3b3b4c

2 files changed

Lines changed: 83 additions & 30 deletions

File tree

meshtastic/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1992,7 +1992,7 @@ def addRemoteAdminArgs(parser: argparse.ArgumentParser) -> argparse.ArgumentPars
19921992
"--sensor-config",
19931993
help="Send a sensor admin command to configure sensor parameters.",
19941994
action="store",
1995-
nargs=2,
1995+
nargs='+',
19961996
default=None
19971997
)
19981998

meshtastic/node.py

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

980-
def sensorConfig(self, command: List = None):
980+
def sensorConfig(self, commands: List = None):
981981
"""Send a sensor configuration command"""
982982
self.ensureSessionKey()
983983

984984
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")
985+
if any(['scd4x_config' in command for command in commands]):
986+
cleanup_commands = [command.replace('scd4x_config.', '') for command in commands]
987+
988+
if 'factory_reset' in cleanup_commands:
989+
print ("Performing factory reset on SCD4X")
990+
p.sensor_config.scd4x_config.factory_reset = True
991+
else:
992+
if 'set_asc' in cleanup_commands:
993+
if cleanup_commands[cleanup_commands.index('set_asc')+1] == "true":
994+
p.sensor_config.scd4x_config.set_asc = True
995+
print ("Setting SCD4X ASC mode")
996+
elif cleanup_commands[cleanup_commands.index('set_asc')+1] == "false":
997+
p.sensor_config.scd4x_config.set_asc = False
998+
print ("Setting SCD4X FRC mode")
999+
else:
1000+
print(
1001+
f'Not valid argument for sensor_config.scd4x_config.set_asc'
1002+
)
1003+
if 'set_target_co2_conc' in cleanup_commands:
1004+
try:
1005+
target_co2_conc = int(cleanup_commands[cleanup_commands.index('set_target_co2_conc')+1])
1006+
except ValueError:
1007+
print(
1008+
f'Invalid value for target CO2 conc'
1009+
)
1010+
return
1011+
else:
1012+
print (f"Setting SCD4X target CO2 conc to {target_co2_conc}")
1013+
p.sensor_config.scd4x_config.set_target_co2_conc = target_co2_conc
1014+
send_command = True
1015+
if 'set_temperature' in cleanup_commands:
1016+
try:
1017+
temperature = float(cleanup_commands[cleanup_commands.index('set_temperature')+1])
1018+
except ValueError:
1019+
print(
1020+
f'Invalid value for reference temperature'
1021+
)
1022+
return
1023+
else:
1024+
print (f"Setting SCD4X Reference temperature to {temperature}")
1025+
p.sensor_config.scd4x_config.set_temperature = temperature
1026+
send_command = True
1027+
if 'set_altitude' in cleanup_commands:
1028+
try:
1029+
altitude = int(cleanup_commands[cleanup_commands.index('set_altitude')+1])
1030+
except ValueError:
1031+
print(
1032+
f'Invalid value for reference altitude'
1033+
)
1034+
return
1035+
else:
1036+
print (f"Setting SCD4X Reference altitude to {altitude}")
1037+
p.sensor_config.scd4x_config.set_altitude = altitude
1038+
if 'set_ambient_pressure' in cleanup_commands:
1039+
try:
1040+
ambient_pressure = int(cleanup_commands[cleanup_commands.index('set_ambient_pressure')+1])
1041+
except ValueError:
1042+
print(
1043+
f'Invalid value for reference ambient pressure'
1044+
)
1045+
return
1046+
else:
1047+
print (f"Setting SCD4X Reference ambient pressure to {ambient_pressure}")
1048+
p.sensor_config.scd4x_config.set_ambient_pressure = ambient_pressure
1049+
1050+
if any(['sen5x_config' in command for command in commands]):
1051+
cleanup_commands = [command.replace('sen5x_config.', '') for command in commands]
1052+
if 'set_one_shot_mode' in cleanup_commands:
1053+
if cleanup_commands[cleanup_commands.index('set_one_shot_mode')+1] == "true":
1054+
p.sensor_config.sen5x_config.set_one_shot_mode = True
1055+
print ("Setting SEN5X one shot mode")
1056+
elif cleanup_commands[cleanup_commands.index('set_one_shot_mode')+1] == "false":
1057+
p.sensor_config.sen5x_config.set_one_shot_mode = False
1058+
print ("Setting SEN5X continuous mode")
9931059
else:
9941060
print(
995-
f'Not valid argument for sensor_config.scd4x.set_asc'
1061+
f'Not valid argument for sensor_config.sen5x_config.set_one_shot_mode'
9961062
)
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")
10151063

10161064
# How to represent a HANDLED event?
10171065
if self == self.iface.localNode:
10181066
onResponse = None
10191067
else:
10201068
onResponse = self.onAckNak
1021-
return self._sendAdmin(p, onResponse=onResponse)
1069+
1070+
if p.ByteSize():
1071+
# TODO - Should this require a response?
1072+
return self._sendAdmin(p, onResponse=onResponse)
1073+
else:
1074+
print ('Nothing to request')
10221075

10231076
def _requestChannel(self, channelNum: int):
10241077
"""Done with initial config messages, now send regular

0 commit comments

Comments
 (0)