ESP32 arduino cloud Widget not working

I could successfully upload my first led blink program to my ESP32 kit from Arduino cloud. But cannot control the led through the switch widget . What may be the reason? (When I put an led turn on and off code in the loop it gets uploaded to kit and works fine.) Here is the code for which widget was not functioning. Would you be able to help me?

#include "arduino_secrets.h"
/*
Sketch generated by the Arduino IoT Cloud Thing "first"
https://create.arduino.cc/cloud/things/7395c417-c85d-4f85-8328-e22b70e90d37

Arduino IoT Cloud Variables description

The following variables are automatically generated and updated when changes are made to the Thing

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"

void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
pinMode(2,OUTPUT);
// 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() {
ArduinoCloud.update();
// Your code here
//digitalWrite(2,HIGH);
//delay(500);
//digitalWrite(2,LOW);
//delay(500);
// the above code works fine if uncommented!
}

void onLedChange() {
// Do something
if(led){
digitalWrite(2,HIGH);

}
else{
digitalWrite(2,LOW);

}
}

Where do you change the value of "led"?

Please remember to use code tags when posting code

@sreenadhan
I'm not sure why you flagged your own post as inappropriate, is that just a misunderstanding?

In any case, I have moved your topic to a more appropriate place. Please can you take some time to read How to get the best out of this forum

Thanks,

Thank you very much. I am new to the forum and didn't know the guidelines. So, when I found it inappropriate, flagged it.
Sorry for the inconvenience
Sreenadhan

1 Like

Sorry that I didn't use tags. I was new to the forum, it was my first post and was ignorant of the guide lines.
I used a switch widget from the dashboard of Arduino cloud to control the variable 'led' but it had no effect on the actual led I connected to my ESP-WROOM-32 kit.

well using code-tags works different:

the easiest way way is
to use the automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

another way is to copy your complete sketch into the clipboard
then click the </>-Button
then paste the clipboard-content by pressing Ctr-V.
best regards Stefan

thank you very much for explaining it in a very simple way
Best Regards,
Sreenadhan

/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/97cd755f-9508-4676-a13d-862bacf98df3

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  bool led1;

  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);
  pinMode(2, OUTPUT);
  // 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() {
  ArduinoCloud.update();
  // Your code here


}

/*
  Since Led1 is READ_WRITE variable, onLed1Change() is
  executed every time a new value is received from IoT Cloud.
*/
void onLed1Change()  {
  if (led1) {
    digitalWrite(2, HIGH);
  }
  else {
    digitalWrite(2, LOW);
  }
  // Add your code here to act upon Led1 change
}

And it worked! I have deleted everything and created once again and it worked. But I couldn't figure out what mistake I did previously. Thank you all for your advices! In the meantime, I could do it in BLYNK platform as well.

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