@@ -117,6 +117,7 @@ def run(self):
117
117
message = dumps (message )
118
118
self .cloudClient .mqttClient .publish_packet (topic , message )
119
119
message = None
120
+ self .cloudClient .writeQueue .task_done ()
120
121
except :
121
122
exception ("WriterThread Unexpected error" )
122
123
return
@@ -243,6 +244,8 @@ def SendSystemInfo(self):
243
244
cayennemqtt .DataChannel .add (data , cayennemqtt .SYS_OS_NAME , value = self .oSInfo .ID )
244
245
cayennemqtt .DataChannel .add (data , cayennemqtt .SYS_OS_VERSION , value = self .oSInfo .VERSION_ID )
245
246
cayennemqtt .DataChannel .add (data , cayennemqtt .AGENT_VERSION , value = self .config .get ('Agent' , 'Version' , __version__ ))
247
+ cayennemqtt .DataChannel .add (data , cayennemqtt .SYS_POWER_RESET , value = 0 )
248
+ cayennemqtt .DataChannel .add (data , cayennemqtt .SYS_POWER_HALT , value = 0 )
246
249
config = SystemConfig .getConfig ()
247
250
if config :
248
251
channel_map = {'I2C' : cayennemqtt .SYS_I2C , 'SPI' : cayennemqtt .SYS_SPI , 'Serial' : cayennemqtt .SYS_UART , 'DeviceTree' : cayennemqtt .SYS_DEVICETREE }
@@ -374,7 +377,7 @@ def ExecuteMessage(self, message):
374
377
return
375
378
channel = message ['channel' ]
376
379
info ('ExecuteMessage: {}' .format (message ))
377
- if channel == cayennemqtt .SYS_POWER :
380
+ if channel in ( cayennemqtt .SYS_POWER_RESET , cayennemqtt . SYS_POWER_HALT ) :
378
381
self .ProcessPowerCommand (message )
379
382
elif channel .startswith (cayennemqtt .DEV_SENSOR ):
380
383
self .ProcessSensorCommand (message )
@@ -391,16 +394,27 @@ def ExecuteMessage(self, message):
391
394
392
395
def ProcessPowerCommand (self , message ):
393
396
"""Process command to reboot/shutdown the system"""
394
- error = None
397
+ error_message = None
395
398
try :
396
- commands = {'reset' : 'sudo shutdown -r now' , 'halt' : 'sudo shutdown -h now' }
397
- output , result = executeCommand (commands [message ['payload' ]])
398
- debug ('ProcessPowerCommand: {}, result: {}, output: {}' .format (message , result , output ))
399
- if result != 0 :
400
- error = 'Error executing shutdown command'
399
+ self .EnqueueCommandResponse (message , error_message )
400
+ commands = {cayennemqtt .SYS_POWER_RESET : 'sudo shutdown -r now' , cayennemqtt .SYS_POWER_HALT : 'sudo shutdown -h now' }
401
+ if int (message ['payload' ]) == 1 :
402
+ debug ('Processing power command' )
403
+ data = []
404
+ cayennemqtt .DataChannel .add (data , message ['channel' ], value = 1 )
405
+ self .EnqueuePacket (data )
406
+ self .writeQueue .join ()
407
+ output , result = executeCommand (commands [message ['channel' ]])
408
+ debug ('ProcessPowerCommand: {}, result: {}, output: {}' .format (message , result , output ))
409
+ if result != 0 :
410
+ error_message = 'Error executing shutdown command'
401
411
except Exception as ex :
402
- error = '{}: {}' .format (type (ex ).__name__ , ex )
403
- self .EnqueueCommandResponse (message , error )
412
+ error_message = '{}: {}' .format (type (ex ).__name__ , ex )
413
+ if error_message :
414
+ error (error_message )
415
+ data = []
416
+ cayennemqtt .DataChannel .add (data , message ['channel' ], value = 0 )
417
+ self .EnqueuePacket (data )
404
418
405
419
def ProcessAgentCommand (self , message ):
406
420
"""Process command to manage the agent state"""
0 commit comments