Programmatically reboot a node



  • @Daniele That is the opposite of what I have - here my GW is 'up' in mycontroller but node 0 is 'down' and yet it is working perfectly with myc and all nodes!

    If this is a random thing I would suggest triple checking all connections individually to ensure they are tight and no movement at all can happen. I took out a DC barrel connector and replaced it and things got a lot better from just that one change.

    I also put the arduino watchdog on the GW node as another way to recover from any 'hangs'.

    I added the previously posted operations as another way to tackle problems with the gw, but not sure how to tell if it is working as expected!

    Finally I upgraded the pi from stretch to buster and fully updated everything.

    Since then I have had 7-8 weeks without any issues (previously 1-2 weeks was about all I could hope for).

    I still have a ups on my to do list. That will happen soon I hope.



  • @Daniele some example to send the payload.
    Note: I didn't test this in practice. Please let me know if you face an issue.

    var myImports = new JavaImporter(java.lang, java.util, org.mycontroller.standalone.utils.McUtils);
    
    with(myImports) {
      // get your node/sensor/variable via uuid
      var mySensorVariable = mcApi.uidTag().getByUid("abc").getResource();
      
      // set new value
      mySensorVariable.value  = 2
      
      // send paylaod
      mcApi.sensor().sendPayload(mySensorVariable);
    }
    


  • @jkandasa thank you for the example, but how can I leverage it to reboot a node?
    I mean, as far as I understand the reboot payload is not a regular sensor that I can map through a uid.



  • @Daniele I have modified the script and here is your request,

    var myImports = new JavaImporter(java.lang, java.util, org.mycontroller.standalone.utils.McUtils, org.mycontroller.standalone.message.IMessage);
    
    with(myImports) {
      // get your gateway via uuid
      var myGateway = mcApi.uidTag().getByUid("my-test-gateway").getResource();
      
      // Import message type
      var Message = Java.type("org.mycontroller.standalone.message.IMessage")
      
      // create message object
      var message = Message.getInstance()
      
      // update gateway id.
      message.setGatewayId(myGateway.id)
      
      // update message type
      message.setType("Internal")
      
      // update message sub type
      message.setSubType("Reboot")
      
      // set sensor id as 255 for node message
      message.setSensorId("255")
      
      // set acknowledgement status
      message.setAck(0)
      
      // set empty payload, but json conversion throws excepton for empty, so set it as "0"
      message.setPayload("0")
      
      // update your node EUI
      message.setNodeEui(21)
      
      // send Raw Message
      mcApi.sensor().sendRawMessage(message);
    }
    
    


  • Amazing, thank you!



  • Hi all,

    I have a similar problem with Raspberry PI and MySensors Serial Node with NRF radio.
    After a random time the node service on RPI stops working:

    c1398a70-e1c5-4de6-8652-bff918bba715-image.png

    To restart the service I need to run 'sudo systemctl restart mysgw.service'.
    Currently, I have scheduled a script to do that, which decrease problem frequency, however, it still happens.

    Q: Is there a way to run this console command from the MyController script when the selected node is down?

    jkandasa it would be great if you can provide an example.

    Many Thanks.



  • @Radi-M can you try this and let me know,

    var myImports = new JavaImporter(java.lang, java.util);
    
    with(myImports) {
      // your command to execute
      var command = "sudo systemctl restart mysgw.service";
      
      // execute your command
      mcApi.osCommandExecuter().executeLinuxCommand(command);
    }
    


  • Hi,

    It works.

    Many thanks.
    Radi-M



  • Probably a stupid question, but will this reboot all mys GW attached to the pi?



  • Probably a stupid question, but will this reboot all mys GW attached to the pi?

    @skywatch Yes, it will. if your mys GW powered by RPI


Log in to reply
 

Suggested Topics

6
Online

569
Users

460
Topics

2.8k
Posts