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

    Programmatically reboot a node

    Scheduled Pinned Locked Moved Developers Zone
    15 Posts 4 Posters 1.0k 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.
    • D Offline
      Daniele
      last edited by

      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.

      skywatchS 1 Reply Last reply Reply Quote 0
      • skywatchS Offline
        skywatch @Daniele
        last edited by skywatch

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

        jkandasaJ 1 Reply Last reply Reply Quote 0
        • jkandasaJ Offline
          jkandasa @skywatch
          last edited by

          @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

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

            jkandasaJ 1 Reply Last reply Reply Quote 0
            • jkandasaJ Offline
              jkandasa @Daniele
              last edited by

              @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

                Amazing, thank you!

                1 Reply Last reply Reply Quote 0
                • R Offline
                  Radi-M
                  last edited by Radi-M

                  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.

                  jkandasaJ 1 Reply Last reply Reply Quote 0
                  • jkandasaJ Offline
                    jkandasa @Radi-M
                    last edited by jkandasa

                    @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

                      Hi,

                      It works.

                      Many thanks.
                      Radi-M

                      1 Reply Last reply Reply Quote 1
                      • skywatchS Offline
                        skywatch
                        last edited by

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

                        jkandasaJ 1 Reply Last reply Reply Quote 0
                        • jkandasaJ Offline
                          jkandasa @skywatch
                          last edited by

                          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

                          589

                          Users

                          529

                          Topics

                          3.4k

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