Hubduino, is there a way to send a command to restart the arduino?

@kuzenkohome, here is some info for generating a Hubduino reset from Hubitat. This method uses a call to the CPU’s reset vector to initiate the reset.

Please note that the preferred method to perform a reset by software is to have the Watchdog Timer trigger the reset.

The difference between the two methods is that the Watchdog method initializes some registers and on-chip peripherals to a known state before calling the reset vector. However, a simple call to the reset vector may be sufficient for your case; you will need to test this for yourself.

Note: I have done this for an AVR processor. I was using a Mega2560/W5500. If you’re using a NodeMCU, I have provided some notes below.

I’ve broken this down to 4 steps.

Step 1 - add code to Hubduino:
In the method “receiveSmartString()” in file “ST_Anything\Everything.cpp”, add this code after the 4-line block of code belonging to “if (message == "refresh")” (i.e., after the closing brace):

else if (message == "reboot")
{
  // Restarts program from beginning but does not reset the peripherals and registers
  asm volatile ("  jmp 0");
}

Compile and upload the firmware.

I haven’t tried this, but it seems the equivalent to the asm line above for NodeMCU is “ESP.restart()”. It seems that after uploading your sketch, you need to push the NodeMCU’s reset button once in order for a subsequent software reset to work properly.

Also, I’ve seen some posts that indicate that the watchdog is enabled by default on NodeMCU; if that is the case, then using a busy loop “while(1) {};” should suffice to cause the watchdog to time out – this would be the preferred solution. If anybody can test, I’d be interested in knowing.

Step 2 – test manually:

  • On Hubitat, go to the Devices list and select the HubDuino device.
  • In the “Send Data” box, enter the word: reboot
  • Click the “Send Data” button above. This should send a reboot message to HubDuino.

Step 3 – Add a Hubitat “HTTP Momentary Switch” virtual device:
Install the driver code for “HTTP Momentary Switch” (another excellent contribution by @ogiewon, I might add!). The code is in GitHub.
Create a virtual device. I used the following settings:

  • Device IP:
  • Device Port:
  • URL Path: /reboot?
  • Post,GET,PUT: POST
  • Content-Type: application/x-www-form-urlencoded
    Please note in the URL Path above, the “slash” and “question mark” on each side of “reboot”; these are important.

Step 4 – add a Hubitat rule
Create a new rule using the virtual switch created above. Select “Control Switches”, “Turn switches on” and select the virtual switch.

That is all the info I can glean from my notes. Let me know if you have any questions.

1 Like