Hello. I have a IoT project that uses two CloudTime variables for a turn on-off schedule.
On my Dashboard there are time pickers to set them.
My problem is that if board gets disconnected, after reconnecting, the variables reset to 00:01.
I need to keep them so if power cut or network issues appear with the board, after starting again sketch will continue working without need to configure again.
Is there a way to keep their values in the cloud after losing connection with the board?
Hi!
Can you please share the sketch? It might be a problem with the sketch and not with the Cloud.
Thanks!
#include <WiFiNINA.h>
const int pumpPin = 9;
unsigned long pumpStartTime = 0;
unsigned long pumpElapsedTime = 0;
#include "thingProperties.h"
void setup() {
pinMode(pumpPin, OUTPUT);
// Set LED pins as outputs
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
if (pumpActivated) {
unsigned long currentTime = millis();
pumpElapsedTime = currentTime - pumpStartTime;
if (workingNow) {
// Check if the pump run time has elapsed
if (pumpElapsedTime >= pumpRunTime * 60000) {
turnPumpOff();
Serial.println("Pump turned off");
debug = "Pump turned off";
}
} else {
// Check if the pump off time has elapsed
if (pumpElapsedTime >= pumpOffTime * 60000) {
turnPumpOn();
Serial.println("Pump turned on");
debug = "Pump turned on";
}
}
} else {
turnPumpOff();
Serial.println("Pump deactivated");
debug = "Pump deactivated";
}
if (workingNow) {
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, HIGH);
digitalWrite(LEDB, LOW);
} else {
digitalWrite(LEDR, LOW);
digitalWrite(LEDG, LOW);
digitalWrite(LEDB, HIGH);
}
}
void turnPumpOn() {
digitalWrite(pumpPin, HIGH);
workingNow = true;
pumpStartTime = millis();
}
void turnPumpOff() {
digitalWrite(pumpPin, LOW);
workingNow = false;
pumpStartTime = millis();
}
void onPumpRunTimeChange() {
// Add your code here to act upon PumpRunTime change
}
void onPumpOffTimeChange() {
// Add your code here to act upon PumpOffTime change
}
void onPumpActivatedChange() {
if (pumpActivated) {
Serial.println("Pump activated");
debug = "Pump activated";
turnPumpOn();
} else {
Serial.println("Pump deactivated");
debug = "Pump deactivated";
turnPumpOff();
}
}
void onWorkingNowChange() {
// Add your code here to act upon WorkingNow change
}
void onDebugChange() {
// Add your code here to act upon Debug change
}
@nicktodorov which are the two cloud properties that are resetting?
edit: they are PumpRunTime
and PumpOffTime
No, the cloud variables reset. As they are cloud ones, they are not defined in the sketch, but created on the iot cloud in the setup section and edited through the Dashboard.
They have to be defined also in the sketch, they are added automatically in the
thingProperties.h file
nevermind, i think i've reproduced your issue i'll let you know as soon as we have a fix
@nicktodorov i've made some test, as a workarount you can use int
properties instead of the dedicated CloudTime
Thank you.
But how can I define a value like 8:00 this way?
I was using this nice feature of the IoT cloud that eliminates the need for adding real time clock modules on my boards and still being able to define schedules with start and off times.
You need only to cange the variable type in yout sketch setup tab. The time pickers will continue to work as usual.
@nicktodorov forget what i've said. Time picker only supports CloudTime variable (I did not refresh my dashboard page). I'll let you know when the issue with the CloudTime variable is fixed
Hi @nicktodorov the issue has been fixed. The CloudTime property value is now retained correctly after a board reboot.
Can you please try again and let me know if everything works also on your side?
Sorry for the inconvenience.
Yes, with a quick reboot test seems to work now.
I will keep an eye on it long term and notify you here if for some reason it happens again.
Thank you!
Great, thanks!
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.