You wrote:
"That's pretty weird. I do have projects with many variables working perfectly fine. Can you share the sketch that is not working so that I can try to reproduce the effect?"
Yes, please try to help me make this work. Is there a way I can do the Thing variable updating myself in code rather than having it be done in the background? Maybe with the ArduinoIoTCloud library? I need to be able to send SMS messages from within my cloud application, so I need to pause the Thing variable updates, send the SMS, and resume.
Here are my Thing variables. If I add one more Thing variable, the cloud stuff locks up, my main Loop executes three times before the lockup. Then it is almost impossible to reprogram the MKR NB 1500 again because the watchdog goes off in the middle of the upload process. I have a total of 21 Thing variables I want to use.
Here is the code. I am running a new clean build of Win10 because i wanted to be sure it wasn't some windows thing. I had the exact same results using a different computer. Note, I had all of the Thing variables linked to widgets on dashboards too.
Depending on how interested you are in getting to the bottom of this problem, and want to work with me at the same time,let me know your time zone and what time you would be available, and I will be here to work live with you. This is very important to me as I have the potential to lose lots of money if I can't get this to work. Thanks in advance!
Oh, I commented out the callback code and had the same problem either way.
Tom
/*
Sketch generated by the Arduino IoT Cloud Thing "GreenWater2"
[https://create.arduino.cc/cloud/things/3b7bb899-d59e-4d1e-ae90-07da76eee3c0](https://create.arduino.cc/cloud/things/3b7bb899-d59e-4d1e-ae90-07da76eee3c0)
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
String status;
String testValue;
int area1;
int area2;
int area3;
int boardO3analog;
int number1;
int number2;
int number3;
int potentiometer;
int seconds;
bool led;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
int i = 0;
unsigned long starttime = millis();
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
Serial.println("Serial working");
// Defined in thingProperties.h
initProperties();
/*
Invoking `addCallback` on the ArduinoCloud object allows you to subscribe
to any of the available events and decide which functions to call when they are fired.
The functions `doThisOnConnect`, `doThisOnSync`, `doThisOnDisconnect`
are custom functions and can be named to your likings and for this example
they are defined/implemented at the bottom of the Sketch
*/
// I have tried with and without these callbacks and program fails the same way
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect);
// Connect to Arduino IoT Cloud
// If watchdog is on and program fails to connect to the cloud it is almost
// impossible to upload a new sketch because the watchdog fires during the upload process
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false); // false = no watchdog
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
}
// ====================== Main Loop =========================
void loop() {
ArduinoCloud.update();
// Your code here
Serial.print("\n(");
Serial.print(i++);
Serial.print(") CloudCon = ");
Serial.println(ArduinoCloud.connected());
//seconds = (millis()-starttime) / 1000; //seconds
//potentiometer = analogRead(A0);
delay(1000); // much shorter than watchdog ~ 16 sec
}
// ====================== END Main Loop ====================
/*
Since Status is READ_WRITE variable, onStatusChange() is
executed every time a new value is received from IoT Cloud.
*/
void onStatusChange() {
// Add your code here to act upon Status change via dashboard
Serial.print("Status=");
Serial.println(status);
}
/*
Since TestValue is READ_WRITE variable, onTestValueChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTestValueChange() {
// Add your code here to act upon TestValue change
}
/*
Since Area1 is READ_WRITE variable, onArea1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onArea1Change() {
// Add your code here to act upon Area1 change
Serial.print("Area1=");
Serial.println(area1);
}
/*
Since Area2 is READ_WRITE variable, onArea2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onArea2Change() {
// Add your code here to act upon Area2 change
}
/*
Since Area3 is READ_WRITE variable, onArea3Change() is
executed every time a new value is received from IoT Cloud.
*/
void onArea3Change() {
// Add your code here to act upon Area3 change
}
/*
Since BoardO3Analog is READ_WRITE variable, onBoardO3AnalogChange() is
executed every time a new value is received from IoT Cloud.
*/
void onBoardO3AnalogChange() {
// Add your code here to act upon BoardO3Analog change
}
/*
Since Number1 is READ_WRITE variable, onNumber1Change() is
executed every time a new value is received from IoT Cloud.
*/
void onNumber1Change() {
// Add your code here to act upon Number1 change
}
/*
Since Number2 is READ_WRITE variable, onNumber2Change() is
executed every time a new value is received from IoT Cloud.
*/
void onNumber2Change() {
// Add your code here to act upon Number2 change
}
/*
Since Number3 is READ_WRITE variable, onNumber3Change() is
executed every time a new value is received from IoT Cloud.
*/
void onNumber3Change() {
// Add your code here to act upon Number3 change
}
/*
Since Potentiometer is READ_WRITE variable, onPotentiometerChange() is
executed every time a new value is received from IoT Cloud.
*/
void onPotentiometerChange() {
// Add your code here to act upon Potentiometer change
}
/*
Since Seconds is READ_WRITE variable, onSecondsChange() is
executed every time a new value is received from IoT Cloud.
*/
void onSecondsChange() {
// Add your code here to act upon Seconds change
}
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
// Add your code here to act upon Led change
digitalWrite(5,led);
testValue = ("Led = " + String(led));
Serial.print("Led changed");
}
void doThisOnConnect() {
/* add your custom code here */
Serial.print("Board successfully connected to Arduino IoT Cloud - ");
Serial.println((millis() - starttime) / 1000);
}
void doThisOnSync() {
/* add your custom code here */
Serial.print("Thing Properties synchronised - ");
Serial.println((millis() - starttime) / 1000);
}
void doThisOnDisconnect() {
/* add your custom code here */
Serial.print("Board disconnected from Arduino IoT Cloud - ");
Serial.println((millis() - starttime) / 1000);
}