#define CAYENNE_DEBUG // Uncomment to show debug messages
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#define VIRTUAL_CHANNEL 2
#define ACTUATOR_PIN 4
#include <CayenneMQTTESP8266Shield.h>
#include <ESP8266SerialLibrary.h>
// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "password";
// Cayenne authentication info.
char username[] = "username";
char password[] = "password";
char clientID[] = "client_id";
// ESP8266 Serial object.
#define EspSerial Serial1
ESP8266 wifi(&EspSerial);
void setup()
{
Serial.begin(9600);
delay(10);
pinMode(ACTUATOR_PIN, OUTPUT);
// Set ESP8266 baud rate
EspSerial.begin(115200);
//EspSerial.begin(115200);
delay(50);
Cayenne.begin(username, password, clientID, wifi, ssid, wifiPassword);
}
void loop()
{
Cayenne.loop();
}
// Data from Cayenne.
CAYENNE_IN(VIRTUAL_CHANNEL)
{
// Write value to turn the relay switch on or off. This code assumes you wire your relay as normally open.
if (getValue.asInt() == 0)
{
digitalWrite(ACTUATOR_PIN, HIGH);
}
else
{
digitalWrite(ACTUATOR_PIN, LOW);
}
}
// Send data to Cayenne
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);
}
I am writing ssid and password of the WiFi, and username, clientID, password to the corresponding places of course.