• Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login
  • Categories
  • Recent
  • Tags
  • Popular
  • Register
  • Login

Programmatically reboot a node

Scheduled Pinned Locked Moved Developers Zone
15 Posts 4 Posters 1.3k Views 1 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    skywatch @Daniele
    last edited by skywatch 1 Aug 2020, 23:13 8 Jan 2020, 17:32

    @Daniele I can't help with an example but I did just have a look to see if I could help and found what I think you are wanting.

    Just go in mycontroller to <resources>, <operations> and there you can make an operation with the drop down options to send a reboot to a particular node.

    So....

    operations.jpg

    Under operation, type = payload.
    Under Resource node followed by your desired node.
    Under payload - Reboot. You can add a delay as well here if you want.

    Then go to <rules> and add a rule to trigger the operation.

    Hope this helps.

    1 Reply Last reply Reply Quote 1
    • D Offline
      Daniele
      last edited by 9 Jan 2020, 13:54

      @skywatch thank you, I know about that, and btw I can get the same result from Resources -> Nodes, selecting the node and the Reboot from the action menu.
      What I'd like is doing the same thing programmatically.
      Just to clarify, I noticed that from time to time my ethernet gateway hangs and all the dependent nodes go offline; when this happens, it's usually sufficient issuing a reboot of the node and then reloading the gw from MyController.
      I'd like to try scheduling a script that does these 2 things for me when nodes go offline.

      S 1 Reply Last reply 9 Jan 2020, 15:56 Reply Quote 0
      • S Offline
        skywatch @Daniele
        last edited by skywatch 1 Sept 2020, 21:27 9 Jan 2020, 15:56

        @Daniele Aha! - OK then. Here is what I did to try and stop this issue causing problems......

        gwwd.jpg

        Then under operations I added the name for the following operation....

        reload.jpg

        With this running in the controller and the watchdog enabled on the uno gateway node I seem to have a good and stable result for the last 7 or 8 weeks.

        Maybe someone else has a better way to do it? If so, I'll be interested as well!

        Once the GW is reloaded you can then send reboot command using info in my first post to any node you want.

        1 Reply Last reply Reply Quote 0
        • D Offline
          Daniele
          last edited by 11 Jan 2020, 06:53

          I understand your solution, but what happens to me is a bit more strange: the gw appears online in MyController, but it's nodes are offline, so I need to check if multiple nodes of the same gw are offline to decide to reboot it (to make things more complicated, I have 3 gws since my house is made of concrete and the transmission range is very short).
          What I could do (I'll try later today) is to build a condition script that counts the offline nodes, and if there are more than a threshold than I can start an operation that reboots the gw.

          S 1 Reply Last reply 11 Jan 2020, 10:32 Reply Quote 0
          • S Offline
            skywatch @Daniele
            last edited by skywatch 1 Nov 2020, 17:52 11 Jan 2020, 10:32

            @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.

            J 1 Reply Last reply 11 Jan 2020, 18:27 Reply Quote 0
            • J Offline
              jkandasa @skywatch
              last edited by 11 Jan 2020, 18:27

              @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);
              }
              
              1 Reply Last reply Reply Quote 0
              • D Offline
                Daniele
                last edited by 12 Jan 2020, 06:46

                @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.

                J 1 Reply Last reply 13 Jan 2020, 03:04 Reply Quote 0
                • J Offline
                  jkandasa @Daniele
                  last edited by 13 Jan 2020, 03:04

                  @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);
                  }
                  
                  
                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    Daniele
                    last edited by 13 Jan 2020, 05:10

                    Amazing, thank you!

                    1 Reply Last reply Reply Quote 0
                    • R Offline
                      Radi-M
                      last edited by Radi-M 2 Jun 2020, 04:11 5 Feb 2020, 22:39

                      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.

                      J 1 Reply Last reply 6 Feb 2020, 07:26 Reply Quote 0
                      • J Offline
                        jkandasa @Radi-M
                        last edited by jkandasa 2 Jun 2020, 12:56 6 Feb 2020, 07:26

                        @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);
                        }
                        
                        1 Reply Last reply Reply Quote 0
                        • R Offline
                          Radi-M
                          last edited by 12 Feb 2020, 21:06

                          Hi,

                          It works.

                          Many thanks.
                          Radi-M

                          1 Reply Last reply Reply Quote 1
                          • skywatchS Offline
                            skywatch
                            last edited by 4 Mar 2020, 14:15

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

                            J 1 Reply Last reply 4 Mar 2020, 18:38 Reply Quote 0
                            • jkandasaJ Offline
                              jkandasa @skywatch
                              last edited by 4 Mar 2020, 18:38

                              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

                              1 Reply Last reply Reply Quote 0
                              • First post
                                Last post

                              0

                              Online

                              619

                              Users

                              531

                              Topics

                              3.4k

                              Posts
                              Copyright © 2015-2025 MyController.org | Contributors | Localization