ESP 8266 Christmas Lights switch Dashboard


#1

In the morning i got this Idea…

Its an easy way to switch Christmas lights On/OFF…Smartphone or else…

I know is very simple but you can think about to dim the led´s…

1 or more Christmas lights 3V

1 ESP8266

some material for Soldering

wish all much fun to build it…

(general introduction, overall experience with Cayenne, why did you create this project??)

#include <CayenneMQTTESP8266.h>
#define CAYENNE_DEBUG
#define CAYENNE_PRINT serial

char ssid[] = "******";
char wifiPassword[] = "*****";

char username[] = "******";
char password[] = "*******";
char clientID[] = "********";

void setup() {
  // put your setup code here, to run once:
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
  pinMode(5, OUTPUT);
  digitalWrite(0, LOW);
  pinMode(2, OUTPUT);
  digitalWrite(2, LOW);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  Cayenne.loop();

}
CAYENNE_IN(6)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    digitalWrite(2, HIGH);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    digitalWrite(2, LOW);
  }
}
CAYENNE_IN(7)
{
  int currentValue = getValue.asInt();
  if (currentValue == 1)
  {
    //do whatever you want when you turn on the button on cayenne dashboard
    digitalWrite(5, HIGH);
  }
  else
  {
    //do whatever you want when you turn off the button on cayenne dashboard
    digitalWrite(5, LOW);
  }
}

Esp8266 cannot add button
#2

Am completely confused right now. Do i have to write my own sketch? isn’t that why we use cayenne?? The sketch given to me for upload when configuring the esp from my dashboard does not provide a spot for inputting my wifi details. the IDE always finds one error or another with the sketch when compiling also. can someone paste a sample code i can edit?


#3

to get what you want from your device. YES.

you must be using a Ethernet connection option while selecting device.

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling. 

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

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

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

unsigned long lastMillis = 0;

void setup() {
	Serial.begin(9600);
	Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
	Cayenne.loop();

	//Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
	if (millis() - lastMillis > 10000) {
		lastMillis = millis();
		//Write data to Cayenne here. This example just sends the current uptime in milliseconds.
		Cayenne.virtualWrite(0, lastMillis);
		//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);
	}
}

#4

OK got it. Will the above sketch turn off/on an led?


#5

NO. above code is to connect to cayenne and sends the current uptime in mills to cayenne dashboard.
to get value from cayenne use this code and add custom button widget with channel 1

CAYENNE_IN(1)
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
//do whatever you want when you turn on the button on cayenne dashboard
}
else
{
//do whatever you want when you turn off the button on cayenne dashboard
}
}

#6

Great!


#7

I am purposed to be as versed in the espressif chip as i am with the raspberry pi, seeing that i am more comfortable reading a python script than c++. so with that said, i have made great progress in uploading sketches. It is just remaining for the button to turn off/on the led.

I have the ground wire of the led connected to the controller’s gnd pin, and the 3v wire connected to pin D1. But for some reason my code only sends the uptime to the dashboard and does not turn on the led. please take a look at my code and tell me why that is

// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

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

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

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

unsigned long lastMillis = 0;

void setup() {
  Serial.begin(115200);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
  Cayenne.loop();

  //Publish data every 10 seconds (10000 milliseconds). Change this value to publish at a different interval.
  if (millis() - lastMillis > 10000) {
    lastMillis = millis();
    //Write data to Cayenne here. This example just sends the current uptime in milliseconds.
    Cayenne.virtualWrite(0, lastMillis);
    //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(1)
{
int currentValue = getValue.asInt();
if (currentValue == 1)
{
//do whatever you want when you turn on the button on cayenne dashboard
digitalWrite(1, HIGH);
}
else
digitalWrite(1, LOW);
{
//do whatever you want when you turn off the button on cayenne dashboard
}
}

#8

PIN D1 is GPI05 !! turn this as your void setup…copy… you have to adress the right pins !! D1-GPIO5…D2-GPI04…search google to get a ESP8266 E12 Pinout picture.

void setup() {
// put your setup code here, to run once:
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
pinMode(5, OUTPUT);
digitalWrite(5, LOW);

i think so is ready if you copy this in your sketch ! i can’t test at this moment


#9

success! how could i have forgotten to check the gpio labeling…Code ran smoothly, i gotta a better understanding of the syntax. Thanks guys.


#10

Glad to hear @aotrakstar! Thanks for helping out @Sven :sunglasses:

~Benny


#11

Thanks Benny :+1: