Hey !!
I am very anxious to seek help as I am new to the IOT cloud of Arduino. The problem is that I am using Node MCU(ESP 8266) and trying with an elementary test sketch set to update a variable's value; as you can see in the code, I uploaded the program to the device using Web Editor. But the issue is that my thing is continuously being shown "Offline", and the variable is also not updated on the dashboard. Still, ironically I am getting the desired results on the serial monitor. Also, to be added, this whole worked well for once (for about a minute). But since then, I have been having trouble. Kindly help me to rectify this.
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/9d2e05e0-04ef-4d53-bde9-b9ab56c0fd5e
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int test_variable;
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"
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);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
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(2);
ArduinoCloud.printDebugInfo();
}
void loop()
{
test_variable = rand()/1000000;
delay(1000);
Serial.println(test_variable);
}
/*
Since TestVariable is READ_WRITE variable, onTestVariableChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTestVariableChange() {
// Add your code here to act upon TestVariable change
}
In the loop() function you are missing calling to ArduinoCloud.update(). That's the function that connects to the cloud and updates the variables under the hood
I would suggest removing the delay in the loop, replacing it with an implementation with millis()
Take a look at this section in the documentation or at this example to get more information.
I am grateful for your support. Your assistance has been invaluable to me. I have been struggling with this issue for a long time; your solution was incredibly relevant and has navigated me through this.
I am sending my data to google sheets using the IFTTT webhook, and it is being sent successfully, but every time my Google Sheet attains 2000 entries, a new sheet is created with the same name. I have attached the photo for that. How can I avoid the creation of a new sheet and let my data be on the same sheet?
And the second issue is that all the 3 of my variables are being written in new Rows as shown in the first photo. Still, I want whenever data be sent through the IOT cloud(as 10 seconds in my case), a new Row should be added, but these variables should be written in the adjacent columns.
I am providing my code for reference. @dbeamonte_arduino, can you please help me out?
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/9d2e05e0-04ef-4d53-bde9-b9ab56c0fd5e
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
int test_variable;
int test_variable2;
int test_variable3;
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"
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);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
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(2);
ArduinoCloud.printDebugInfo();
}
unsigned long previousMillis = 0;
unsigned long prevMillis = 0;
void loop()
{
ArduinoCloud.update();
if (millis() - previousMillis > 5000)
{
previousMillis = millis();
test_variable = rand()/100000000;
test_variable2 = rand()/100000000;
test_variable3 = rand()/100000000;
Serial.println(test_variable);
Serial.println(test_variable2);
Serial.println(test_variable3);
}
if (millis() - prevMillis > 600000)
{
prevMillis = millis();
setup();
}
}
Without knowing all the details of your implementation, I would suggest that you change the variable policy from "ON CHANGE" to "PERIODIC" to try to reduce the number of events.
Bear in mind that the webhook will be triggered on every variable change. So, you should either do that or create some kind of filter for your variable in your sketch so that the amount of data sent to the Cloud (and ultimately sent via the webhook) is reduced.