ESP32 not updating led when value change on cloud through API

I've been trying to update the esp32 led through node js.
I also updated the variable value true/false through Arduino cloud API publish property and it does reflect on the cloud.
But when it updates it's not reflected on the ESP32 and the led is not on/off , though when i try the same with the dashboard it works perfectly fine.
Any Suggestions?

Here is my sketch code.

/* Sketch generated by the Arduino IoT Cloud Thing "Untitled" https://create.arduino.cc/cloud/things/****

Arduino IoT Cloud Variables description

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

CloudLight led;
CloudTemperatureSensor temperature;
CloudRelativeHumidity humidity;
String Wifi_SSID;
String wifi_PWD;

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"
#include "DHT.h"

#define DHTPIN 15

#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

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);

dht.begin();
// 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();
DHT_SENSOR_READ();
//onLedChange();
// Your code here

}

void onLedChange() {
if (led == true )
{
digitalWrite(2, HIGH);
}
if ( led == false) {
digitalWrite(2, LOW);
}
Serial.print("Led is - "); Serial.println(led);
}

void DHT_SENSOR_READ() {
float h = dht.readHumidity();
float t = dht.readTemperature();
temperature = t;
humidity = h;
Serial.print("Temperature is - "); Serial.println(t);
Serial.print("Humidity is - "); Serial.println(h);
delay(1000);

}

void onWifiSSIDChange() {
// Do something
}

void onWifiPWDChange() {
// Do something
}

first suggestion figure out how to use code tags.

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