Programmatically reboot a node
-
@Daniele Aha! - OK then. Here is what I did to try and stop this issue causing problems......
Then under operations I added the name for the following operation....
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.
-
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. -
@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: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