I can get values of button on serial port as i triggers it but i can’t get the LED to light up
Below is my code:
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#define vp1 1
#define vp2 2
// WiFi network info.
char ssid = “xxx”;
char wifiPassword = “xxx”;
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “xxx”;
char password = “xxx”;
char clientID = “xxx”;
unsigned long lastMillis = 0;
void setup() {
pinMode(D2, OUTPUT);
Serial.begin(115200);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
void loop() {
Cayenne.loop();
if (millis() - lastMillis > 3000)
{
lastMillis = millis();
}
}
// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
//Cayenne.virtualWrite(0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
};
CAYENNE_IN(vp1)
{
int currentValue = getValue.asInt();
if (currentValue == 1) {
digitalWrite(D2, HIGH);
Serial.println(“a”);
}
else {
digitalWrite(D2, LOW);
}
}
CAYENNE_IN(2)
{
int currentValue = getValue.asInt();
if (currentValue == 1) {
digitalWrite(D0, HIGH);
Serial.println(“B”);
}
else {
digitalWrite(D0, LOW);
}
}
This is what i saw from Serial Port
[2048] Connected to WiFi
[2048] IP: 192.168.43.232
[2048] Connecting to mqtt.mydevices.com:1883
[2934] Connected
[7420] Channel 65534, value 1
[10640] Channel 65534, value 0
As for the setup, i just link a wire from D2 to positive side of LED bulb while the other goes to ground
Pls help, Thanks