Dashboard value sent to Nano after reboot, want to use my specified default value instead

Using the IoT Cloud and a web Dashboard with a Nano 33 IoT, some "Read & Write" variables.

When my Nano reboots, I set some important default values that will always work -- a safety measure. So if it doesn't have network, it should all "just work."

I have these as "onChange" Read & Write values on the web Dashboard so they can be adjusted in real-time. Problem: If my Nano reboots, it picks up these adjusted values on the Dashboard, not "my" defaults.

Example: I have a Read & Write thermostat setting on the Dashboard, which my script sets to 440. If the Nano reboots, it will start out with the 440, but then it will take on the value on the Dashboard, even if the Dashboard has not been moved since the Nano has rebooted.

I have tried setting the values both before and after ArduinoCloud in setup(). Same result.

I might be able to put a flag in the "onChange" areas of the code to "ignore the first 'change'" -- that's the only thing I can think to try at the mo (outside of editing automatically generated code, which I don't want to do). Is this what other people do?

Q1: How can I make it so that if the Nano reboots I can use "my" default values no matter what the web Dashboard says? Then if someone uses the Dashboard to change the slider, the new value would be used.

Q1a: If this is "doable," is there an option to "have it both ways"? To both force my defaults (and ignore the Dashboard) at reboot OR to go ahead and use the Dashboard values at reboot? I can see both as valuable.

I noted a similar item here, but I think it's the reverse of my request:

Thanks!

Answer: Yes, you can create a flag as a "one off" defense against a change happening when your script starts up ArduinoCloud. It could be the "Cloud Variables" holding the altered value not the Dashboard widget, but that really doesn't matter. I tested this a few times, and it worked for me.

So it looks like I have my answer.

// Declare the flag early
bool bPipeTemperatureSettingReady = false;

// And use it in the onChange
/*
  Since IPipeTemperatureSetting is READ_WRITE variable, onIPipeTemperatureSettingChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onIPipeTemperatureSettingChange()  {
  // Add your code here to act upon IPipeTemperatureSetting change
  if (!bPipeTemperatureSettingReady) {
    iPipeTemperatureSetting = DEFAULT_PIPE_TEMPERATURE;
    bPipeTemperatureSettingReady = true;
  }
}
1 Like

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