Help me find the solution. The code is correct, and the Switch settings on the dashboard are properly configured, but I still can't control the light

#include "thingProperties.h"
const int ledlight=25;
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);
pinMode(ledlight,OUTPUT);
// 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 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
if(led)
{
digitalWrite(ledlight,HIGH);
Serial.println("ON");
}
else
{
digitalWrite(ledlight,LOW);
Serial.println("OFF");
}
}

What is triggering onLedChange() in your code?

What is calling that function?

"The Arduino IoT Cloud is calling the onLedChange() function automatically whenever the associated variable (led) changes its value."

Hi @abderraouf_ben.

If you open the Arduino Cloud Editor Serial Monitor and then change the position of the switch on the dashboard, do you see the expected "ON" or "OFF" message printed in Serial Monitor?

In your code, change the baud rate from 9600 to 115200. "Serial.begin(9600)" then reupload the code to the board

okey

The same issue.

What board are you using?

esp32 DOIT DEVKIT V1


Please do not post pictures of code

Please post your sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

I have merged your topics due to them having too much overlap on the same subject matter @abderraouf_ben .

In the future, please only create one topic for each distinct subject matter and be careful not to cause them to converge into parallel discussions.

The reason is that generating multiple threads on the same subject matter can waste the time of the people trying to help. Someone might spend a lot of time investigating and writing a detailed answer on one topic, without knowing that someone else already did the same in the other topic.

Thanks in advance for your cooperation.

I see that at the time you took those screenshots there was no connection to your ESP32 board:

The upload capability is disabled when there is no connection:

@abderraouf_ben have you successfully uploaded your sketch from Arduino Cloud Editor to the board? This is done by clicking the rightward pointing arrow button on the Cloud Editor toolbar, then waiting until you see a "Done Uploading ..." message on the status bar:

If you never uploaded the sketch to the board, then this would explain the problems you have reported here.