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

Since a while ago, the hub does a backup of itself at exactly 2am periodically. That triggers a cascade events on all my Hubduinos devices, where a recurring error would appear every refresh cycle when the arduino pushes telemetry on specific polling sensors using I2C. The weird part is that sometimes is a 3 in one sensor such as a BME280, and only one of the three will present error accompanied by "nan" string in place of the value of the sensor. Some of them I have to powercycle them to regain sensors telemetry on the Hubitat drivers, but regardless the arduino keeps alive ping and will be sending push messages from their various sensors as I can see them on them on the debugging logs, except for that single one returning the nan value. Problem seems more prevalent on devices using I2C devices:


So Far, the only remediation I have found is to power cycle the device.
Otherwise, if the back does not take place, they would go perfectly fine without issues.

I've narrowed down to the automatic backup as this also perturbs some presence hubs which triggers an alert of departure and arrival upon completion (my wife is so happy :smile: )
So far, I have increased the timeout value of the Hubduino parent from 900 to 9000 and cleared offset values leaving the sensors at their board default values. So far seems that this has done the trick but I am not completely sure. Is there a reset command of some sort that I can push to the arduino to restart the st:everything loop? May be this will serve as bandaid.
@ogiewon, a penny for your thoughts. And thank you introducing me to the wonderful world of Hubitat and saving me from the Evil Empire, making me rediscover my passion for the arduinos and electronics.

1 Like

"nan" is short for 'not a number', I believe. This is an error from the hardware of the Arduino/Sensor device.

The "unable to acquire lock to schedule run once" is something gone awry on the Hubitat hub. I have recently seen this occur on one of my Hubitat hubs. The only fix seems to be to reboot the Hubitat hub. Not sure what the issue is, but I don't see where the HubDuino code is at fault. I may re-architect the HubDuino Parent Driver's 'presence' detection functionality to schedule a recurring call, and then check to see how long it has been since the last update...instead of rescheduling the timeout every time new data arrives. Again, not sure why this occurs.

Unfortunately, not really. You can try calling REFRESH on the Parent Device, as that will send a command to the Arduino and cause it to communicate with the Hubitat hub.

Glad to hear you're having fun!

manuelangelrivera, I've been able to send a restart to Hubduino from Hubitat. But it is a warm restart done in software, not a cold restart like in a power off-on power cycling.

Do you want to restart the Hubduino manually (via a command from the Hubitat device page) or automatically via a Rule?

1 Like

@ogiewon, I am encountering the same "nan" error with a BME280 sensor and it only affects the humidity portion, the temp and pressure continue to work. A refresh of the parent device does not fix the error in my case. I have been living with it by just power cycling the nodemcu. I would be curious to see what data the BME280 is actually sending that is "nan".

I have replaced the BME280 with another and continue to get the same error. I have verified I am running the latest esp8266 libraries and sensor libraries. A power cycle of the esp8266 "fixes" the problem for a few days.

@Stwdtech01 I would be interested in a rule based reset command also. The question will be is if a soft restart is sufficient. If you have some code I can try it as I am getting the "nan" error right now.

Mike

1 Like

@kuzenkohome - HubDuino is not generating the "nan", it is coming from the Adafruit BME280 Arduino Library that HubDuino uses. You may want to try updating your version of this Adafruit library to the latest and greatest to see if it makes a difference. If the newer Adafruit BME280 library solves the problem, please let me know and I will update my GitHub repository with the newer version. Be aware that Adafruit may have made changes to their BME280 library which would require changes to my ST_Anything code to be able to work with the newer version. If you find that is the case, please let me know and I'll take a look at the code.

(Note: My ST_Anything GitHub repo has copies of most all of the libraries it could possibly use. I did this to ensure users had to only download one set of code, that had all been tested together, in order to get ST_Anything up and running quickly. One downside to this is that I don't chase every update to every library that comes out. Users can use the Arduino IDE's built-in Libraries Manager to see which libraries are 'Updateable' and simply update their own libraries as they see fit. I just don't have the time to constantly test every new version of every library as they are released.)

@ogiewon I wasn't suggesting that Hubduino was generating the "nan" I was just suggesting to see if there was a code change that could be used to see what humidity data the BME280 is providing.

I have version 2.0.2 of the BME280 library installed, which is the version in the library you linked to. Along with the ver. 2.7.1 of the ESP8266 core library.

The 'nan' error doesn't occur right away, it may take several days. Just brainstorming for ideas.

Going to remove the entire device from HE, reflash with code compiled today and add back into HE to see what happens.

Mike

Understood. I was just wanting to make sure you were aware of the underlying Adafruit library.

If you look at the Adafruit library code, you'll see this section of code where you can see that the library returns NAN when it believes the BME280 Humidity measurement was disabled. I have no idea what would cause that to occur.

/*!
 *  @brief  Returns the humidity from the sensor
 *  @returns the humidity value read from the device
 */
float Adafruit_BME280::readHumidity(void) {
  readTemperature(); // must be done first to get t_fine

  int32_t adc_H = read16(BME280_REGISTER_HUMIDDATA);
  if (adc_H == 0x8000) // value in case humidity measurement was disabled
    return NAN;

.
.
.
.

There is no need to remove the device from your Hub, unless you're going to remove some of the ST_Anything devices in the sketch.

I may comment out that section in the library to see what is being read from the BME280 if removal from HE, re-flash and re-add to HE doesn't fix the problem.

I removed the parent from HE as I saw this in the parent event log. This is another nodemcu that has been active in my HE since Nov 2019. The logs are missing data between jun 4 and march 1.

@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

I love it, gonna try it. It might be a band aid of sorts, but seem like a mitigation for now. Thank You @Stwdtech01 .

@kuzenkohome, you described exactly the behavior with the BME280, now that you mention it, the nan problem its with the humidity sensor in case as well. Do you have any offset value on declared on the driver? I left mine blank to troubleshoot. Have not seen the error coming back in a while. Will post back and see how its goes.

4 posts were merged into an existing topic: Hub down

@manuelangelrivera

I was getting the same errors with my hub/huduino along with my hub being very unresponsive. It would take the device page anywhere from 30-60 seconds to display.

I shut the hub down for about 45 minutes to let my zigbee mesh repair itself. Since then I have not had any performance issues or the Huduino errors. I would suggest doing this.

Also I use the humidity offset and this does not create any errors.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.