ESP8266-01 toggling GPIO 0

I’m having an issue with toggling GPIO 0 on a standalone 8266-01. I have the 8266 connected to my dashboard. I added digital output on channel 0 of the 8266. The state of GPIO 0 of the 8266 doesn’t change when clicking on the icon. Below is the sketch that’s been loaded into the 8266. Can some one look at it a tell what I am missing?

Thanks

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#define VIRTUAL_PIN V0

// WiFi network info.
char ssid = “";
char wifiPassword[] = "
”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “";
char password[] = "
";
char clientID[] = "
*****”;

int relayPin = 0;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(relayPin, OUTPUT); //Relay
digitalWrite(relayPin, LOW);
}

void loop() {
Cayenne.loop();

}

CAYENNE_IN(VIRTUAL_PIN) {

int i = getValue.asInt();
if (i == 0) {
digitalWrite(relayPin, LOW);
}
else {
digitalWrite(relayPin, HIGH);
}

}

@jdfletchx7 you are using MQTT to connect so do the following changes:
add a custom button widget with channel 0.

CAYENNE_IN(0) {
int i = getValue.asInt();
if (i == 0) {
digitalWrite(relayPin, LOW);
}
else {
digitalWrite(relayPin, HIGH);
}
1 Like

@shramik_salgaonkar thanks for the response. When i change the statement to "CAYENNE_IN(0), then i receive the following error when i verify the sketch. Also, I already have a custom widget using channel 0.

Arduino: 1.8.6 Hourly Build 2017/11/13 11:19 (Linux), Board: “Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 1M (512K SPIFFS), ck, Disabled, None”

In file included from /home/pi/Arduino/libraries/Cayenne-MQTT-ESP8266-master/src/CayenneArduinoDefines.h:131:0,
from /home/pi/Arduino/libraries/Cayenne-MQTT-ESP8266-master/src/CayenneArduinoMQTTClient.h:21,
from /home/pi/Arduino/libraries/Cayenne-MQTT-ESP8266-master/src/CayenneMQTTWiFiClient.h:21,
from /home/pi/Arduino/libraries/Cayenne-MQTT-ESP8266-master/src/CayenneMQTTESP8266.h:23,
from /home/pi/Arduino/ESP8266NEW5/ESP8266NEW5.ino:7:
/home/pi/Arduino/ESP8266NEW5/ESP8266NEW5.ino: In function ‘void InputHandler0(Request&, CayenneMessage&)’:
/home/pi/Arduino/libraries/Cayenne-MQTT-ESP8266-master/src/CayenneHandlers.h:66:34: error: redefinition of ‘void InputHandler0(Request&, CayenneMessage&)’
#define CAYENNE_IN(channel) void InputHandler ## channel (Request& request, CayenneMessage& getValue)
^
/home/pi/Arduino/ESP8266NEW5/ESP8266NEW5.ino:50:1: note: in expansion of macro ‘CAYENNE_IN’
CAYENNE_IN(0)
^
/home/pi/Arduino/libraries/Cayenne-MQTT-ESP8266-master/src/CayenneHandlers.h:66:34: error: ‘void InputHandler0(Request&, CayenneMessage&)’ previously defined here
#define CAYENNE_IN(channel) void InputHandler ## channel (Request& request, CayenneMessage& getValue)
^
/home/pi/Arduino/ESP8266NEW5/ESP8266NEW5.ino:36:1: note: in expansion of macro ‘CAYENNE_IN’
CAYENNE_IN(0) {
^
exit status 1
Error compiling for board Generic ESP8266 Module.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

@shramik_salgaonkar Disregard my last post. I have it working. Thank you

1 Like