Posts: 5
Threads: 1
Joined: Apr 2021
Reputation:
0
Good afternoon, I would like to ask for your support to be able to load the software to my KC868 I also have the voice module ESP8266 and SINRIC to be able to activate the 32 outputs of the KC868 through the Mobile and through Alexa
I would like to see if you can support me on how to load it with Arduino IDE since with (Voice-Module-Config) I did not have success
https://drive.google.com/file/d/1NR2Ndxx...sp=sharing
I replaced in the code: ************ with my data from my SINRIC account
#define MyApiKey "*****MY ID SINRIC*****" // TODO: Change to your sinric API Key. Your API Key is displayed on sinric.com dashboard
#define MySSID "************" // TODO: Change to your Wifi network SSID
#define MyWifiPassword "***********" // TODO: Change to your Wifi network password
#define Relay1 "**********" // Device ID of Relay1 , which is displayed on sinric.com dashboard
#define Relay2 "***********" // Device ID of Relay2 , which is displayed on sinric.com dashboard
#define Relay3 "***********" // Device ID of Relay3 , which is displayed on sinric.com dashboard
#define Relay4 "***********" // Device ID of Relay4 , which is displayed on sinric.com dashboard
#define Relay5 "***********" // Device ID of Relay5 , which is displayed on sinric.com dashboard
#define Relay6 "***********" // Device ID of Relay6 , which is displayed on sinric.com dashboard
#define Relay7 "***********" // Device ID of Relay7 , which is displayed on sinric.com dashboard
#define Relay8 "***********" // Device ID of Relay8 , which is displayed on sinric.com dashboard
#define Relay9 "***********" // Device ID of Relay9 , which is displayed on sinric.com dashboard
#define Relay10 "***********" // Device ID of Relay10 , which is displayed on sinric.com dashboard
#define Relay11 "***********" // Device ID of Relay11 , which is displayed on sinric.com dashboard
#define Relay12 "***********" // Device ID of Relay12 , which is displayed on sinric.com dashboard
#define Relay13 "***********" // Device ID of Relay13 , which is displayed on sinric.com dashboard
#define Relay14 "***********" // Device ID of Relay14 , which is displayed on sinric.com dashboard
#define Relay15 "***********" // Device ID of Relay15 , which is displayed on sinric.com dashboard
#define Relay16 "***********" // Device ID of Relay16 , which is displayed on sinric.com dashboard
#define Relay17 "***********" // Device ID of Relay17 , which is displayed on sinric.com dashboard
#define Relay18 "***********" // Device ID of Relay18 , which is displayed on sinric.com dashboard
#define Relay19 "***********" // Device ID of Relay19 , which is displayed on sinric.com dashboard
#define Relay20 "***********" // Device ID of Relay20 , which is displayed on sinric.com dashboard
#define Relay21 "***********" // Device ID of Relay21 , which is displayed on sinric.com dashboard
#define Relay22 "***********" // Device ID of Relay22 , which is displayed on sinric.com dashboard
#define Relay23 "***********" // Device ID of Relay23 , which is displayed on sinric.com dashboard
#define Relay24 "***********" // Device ID of Relay24 , which is displayed on sinric.com dashboard
#define Relay25 "***********" // Device ID of Relay25 , which is displayed on sinric.com dashboard
#define Relay26 "***********" // Device ID of Relay26 , which is displayed on sinric.com dashboard
#define Relay27 "***********" // Device ID of Relay27 , which is displayed on sinric.com dashboard
#define Relay28 "***********" // Device ID of Relay28 , which is displayed on sinric.com dashboard
#define Relay29 "***********" // Device ID of Relay29 , which is displayed on sinric.com dashboard
#define Relay30 "***********" // Device ID of Relay30 , which is displayed on sinric.com dashboard
#define Relay31 "***********" // Device ID of Relay31 , which is displayed on sinric.com dashboard
#define Relay32 "***********" // Device ID of Relay32 , which is displayed on sinric.com dashboard
could provide the libraries since some versions vary.
https://drive.google.com/file/d/1vjwkgDT...sp=sharing
This is the type of card I am selecting.
https://drive.google.com/file/d/1K6f3oMS...sp=sharing
I get this error trying to quote it.
Error compilando para la tarjeta NodeMCU 1.0 (ESP-12E Module).
thank you very much in advance for your support
Attached Files
master_Alexa.zip (Size: 5.94 KB / Downloads: 305)
Posts: 6,393
Threads: 830
Joined: Oct 2020
Reputation:
158
because Sinric.com will reach EOL ("End of Life") 2021-Sep-30 after running 3 years for free of charge. here is details:
https://www.sinric.com/login?returnUrl=%2F
now you can use this way without sinric, here is YouTube video tour link:
https://youtu.be/_w_jyZHOEEQ
Posts: 5
Threads: 1
Joined: Apr 2021
Reputation:
0
(09-14-2021, 12:16 AM) administración Wrote: porque Sinric.com alcanzará el EOL ("Fin de la vida útil") el 30 de septiembre de 2021 después de 3 años de funcionamiento sin cargo. aquí hay detalles: https://www.sinric.com/login?returnUrl=%2F
ahora puede usar de esta manera sin sinric, aquí está el enlace del video tour de YouTube:
https://youtu.be/_w_jyZHOEEQ
ok, pero necesito 27 salidas y aparentemente el video es solo para 10 salidas del dispositivo.
¿Podrías ayudarme con el código de los 27 contactos?
Thank you
Posts: 6,393
Threads: 830
Joined: Oct 2020
Reputation:
158
in code there is a MAX device define, you can change the number, now default is 10
Posts: 4
Threads: 1
Joined: Nov 2020
Reputation:
0
09-28-2021, 11:57 AM
(This post was last modified: 09-30-2021, 01:57 PM by elconfa .)
I use this for 32 light:
Code:
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#define ESPALEXA_MAXDEVICES 32
#include <Espalexa.h>
#define R2 2
// prototypes
boolean connectWifi();
//callback functions
void F1LightChanged(uint8_t brightness);
void F2LightChanged(uint8_t brightness);
void F3LightChanged(uint8_t brightness);
void F4LightChanged(uint8_t brightness);
void F5LightChanged(uint8_t brightness);
void F6LightChanged(uint8_t brightness);
void F7LightChanged(uint8_t brightness);
void F8LightChanged(uint8_t brightness);
void F9LightChanged(uint8_t brightness);
void F10LightChanged(uint8_t brightness);
void F11LightChanged(uint8_t brightness);
void F12LightChanged(uint8_t brightness);
void F13LightChanged(uint8_t brightness);
void F14LightChanged(uint8_t brightness);
void F15LightChanged(uint8_t brightness);
void F16LightChanged(uint8_t brightness);
void F17LightChanged(uint8_t brightness);
void F18LightChanged(uint8_t brightness);
void F19LightChanged(uint8_t brightness);
void F20LightChanged(uint8_t brightness);
void F21LightChanged(uint8_t brightness);
void F22LightChanged(uint8_t brightness);
void F23LightChanged(uint8_t brightness);
void F24LightChanged(uint8_t brightness);
void F25LightChanged(uint8_t brightness);
void F26LightChanged(uint8_t brightness);
void F27LightChanged(uint8_t brightness);
void F28LightChanged(uint8_t brightness);
void F29LightChanged(uint8_t brightness);
void F30LightChanged(uint8_t brightness);
void F31LightChanged(uint8_t brightness);
void F32LightChanged(uint8_t brightness);
// Change this!!
// WiFi Credentials
const char* ssid = "1111";
const char* password = "2222";
// device names
String Device_1_Name = "luce 1";
String Device_2_Name = "luce 2";
String Device_3_Name = "luce 3";
String Device_4_Name = "luce 4";
String Device_5_Name = "luce 5";
String Device_6_Name = "luce 6";
String Device_7_Name = "luce 7";
String Device_8_Name = "luce 8";
String Device_9_Name = "luce 9";
String Device_10_Name ="luce 10";
String Device_11_Name ="luce 11";
String Device_12_Name ="luce 12";
String Device_13_Name ="luce 13";
String Device_14_Name ="luce 14";
String Device_15_Name ="luce 15";
String Device_16_Name ="luce 16";
String Device_17_Name ="luce 17";
String Device_18_Name ="luce 18";
String Device_19_Name ="luce 19";
String Device_20_Name ="luce 20";
String Device_21_Name ="luce 21";
String Device_22_Name ="luce 22";
String Device_23_Name ="luce 23";
String Device_24_Name ="luce 24";
String Device_25_Name ="luce 25";
String Device_26_Name ="luce 26";
String Device_27_Name ="luce 27";
String Device_28_Name ="luce 28";
String Device_29_Name ="luce 29";
String Device_30_Name ="luce 30";
String Device_31_Name ="luce 31";
String Device_32_Name ="luce 32";
unsigned long Millis = 0;
unsigned long PreviousMillis = 0;
boolean Initialized = false;
boolean wifiConnected = false;
Espalexa espalexa;
void setup()
{
Serial.begin(115200);
pinMode(R2, OUTPUT);
pinMode(R2, LOW);
PreviousMillis = millis();
// Initialise wifi connection
wifiConnected = connectWifi();
if (wifiConnected)
{
// Define your devices here.
espalexa.addDevice(Device_1_Name,F1LightChanged);
espalexa.addDevice(Device_2_Name,F2LightChanged);
espalexa.addDevice(Device_3_Name,F3LightChanged);
espalexa.addDevice(Device_4_Name,F4LightChanged);
espalexa.addDevice(Device_5_Name,F5LightChanged);
espalexa.addDevice(Device_6_Name,F6LightChanged);
espalexa.addDevice(Device_7_Name,F7LightChanged);
espalexa.addDevice(Device_8_Name,F8LightChanged);
espalexa.addDevice(Device_9_Name,F9LightChanged);
espalexa.addDevice(Device_10_Name,F10LightChanged);
espalexa.addDevice(Device_11_Name,F11LightChanged);
espalexa.addDevice(Device_12_Name,F12LightChanged);
espalexa.addDevice(Device_13_Name,F13LightChanged);
espalexa.addDevice(Device_14_Name,F14LightChanged);
espalexa.addDevice(Device_15_Name,F15LightChanged);
espalexa.addDevice(Device_16_Name,F16LightChanged);
espalexa.addDevice(Device_17_Name,F17LightChanged);
espalexa.addDevice(Device_18_Name,F18LightChanged);
espalexa.addDevice(Device_19_Name,F19LightChanged);
espalexa.addDevice(Device_20_Name,F20LightChanged);
espalexa.addDevice(Device_21_Name,F21LightChanged);
espalexa.addDevice(Device_22_Name,F22LightChanged);
espalexa.addDevice(Device_23_Name,F23LightChanged);
espalexa.addDevice(Device_24_Name,F24LightChanged);
espalexa.addDevice(Device_25_Name,F25LightChanged);
espalexa.addDevice(Device_26_Name,F26LightChanged);
espalexa.addDevice(Device_27_Name,F27LightChanged);
espalexa.addDevice(Device_28_Name,F28LightChanged);
espalexa.addDevice(Device_29_Name,F29LightChanged);
espalexa.addDevice(Device_30_Name,F30LightChanged);
espalexa.addDevice(Device_31_Name,F31LightChanged);
espalexa.addDevice(Device_32_Name,F32LightChanged);
espalexa.begin();
}
else
{
while (1)
{
Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");
delay(5000);
}
}
}
void loop()
{
espalexa.loop();
delay(1);
}
//our callback functions
void F1LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,1,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,1,0");
digitalWrite(R2, LOW);
}
}
void F2LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,2,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,2,0");
digitalWrite(R2, LOW);
}
}
void F3LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,3,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,3,0");
digitalWrite(R2, LOW);
}
}
void F4LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,4,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,4,0");
digitalWrite(R2, LOW);
}
}
void F5LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,5,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,5,0");
digitalWrite(R2, LOW);
}
}
void F6LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,6,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,6,0");
digitalWrite(R2, LOW);
}
}
void F7LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,7,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,7,0");
digitalWrite(R2, LOW);
}
}
void F8LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,8,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,8,0");
digitalWrite(R2, LOW);
}
}
void F9LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,9,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,9,0");
digitalWrite(R2, LOW);
}
}
void F10LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,10,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,10,0");
digitalWrite(R2, LOW);
}
}
void F11LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,11,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,11,0");
digitalWrite(R2, LOW);
}
}
void F12LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,12,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,12,0");
digitalWrite(R2, LOW);
}
}
void F13LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,13,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,13,0");
digitalWrite(R2, LOW);
}
}
void F14LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,14,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,14,0");
digitalWrite(R2, LOW);
}
}
void F15LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,15,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,15,0");
digitalWrite(R2, LOW);
}
}
void F16LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,16,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,16,0");
digitalWrite(R2, LOW);
}
}
void F17LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,17,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,17,0");
digitalWrite(R2, LOW);
}
}
void F18LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,18,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,18,0");
digitalWrite(R2, LOW);
}
}
void F19LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,19,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,19,0");
digitalWrite(R2, LOW);
}
}
void F20LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,20,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,20,0");
digitalWrite(R2, LOW);
}
}
void F21LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,21,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,21,0");
digitalWrite(R2, LOW);
}
}
void F22LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,22,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,22,0");
digitalWrite(R2, LOW);
}
}
void F23LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,23,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,23,0");
digitalWrite(R2, LOW);
}
}
void F24LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,24,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,24,0");
digitalWrite(R2, LOW);
}
}
void F25LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,25,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,25,0");
digitalWrite(R2, LOW);
}
}
void F26LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,26,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,26,0");
digitalWrite(R2, LOW);
}
}
void F27LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,27,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,27,0");
digitalWrite(R2, LOW);
}
}
void F28LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,28,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,28,0");
digitalWrite(R2, LOW);
}
}
void F29LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,29,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,29,0");
digitalWrite(R2, LOW);
}
}
void F30LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,30,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,30,0");
digitalWrite(R2, LOW);
}
}
void F31LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,31,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,31,0");
digitalWrite(R2, LOW);
}
}
void F32LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,32,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,32,0");
digitalWrite(R2, LOW);
}
}
// connect to wifi – returns true if successful or false if not
boolean connectWifi()
{
boolean state = true;
int i = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
if (i > 20) {
state = false; break;
}
i++;
}
Serial.println("");
if (state) {
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
pinMode(R2, HIGH);
}
else {
Serial.println("Connection failed.");
pinMode(R2, LOW);
}
return state;
}
Posts: 13
Threads: 4
Joined: Sep 2021
Reputation:
1
Elconfa can you please use code tags it is hard to read when scroling takes ages
Posts: 5
Threads: 1
Joined: Apr 2021
Reputation:
0
(09-28-2021, 11:57 AM) elconfa ok muchas gracias lo intentaré. saludos desde Mexico Wrote: Yo uso esto para 32 luces:
Code:
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#define ESPALEXA_MAXDEVICES 32
#include <Espalexa.h>
#define R2 2
// prototypes
boolean connectWifi();
//callback functions
void F1LightChanged(uint8_t brightness);
void F2LightChanged(uint8_t brightness);
void F3LightChanged(uint8_t brightness);
void F4LightChanged(uint8_t brightness);
void F5LightChanged(uint8_t brightness);
void F6LightChanged(uint8_t brightness);
void F7LightChanged(uint8_t brightness);
void F8LightChanged(uint8_t brightness);
void F9LightChanged(uint8_t brightness);
void F10LightChanged(uint8_t brightness);
void F11LightChanged(uint8_t brightness);
void F12LightChanged(uint8_t brightness);
void F13LightChanged(uint8_t brightness);
void F14LightChanged(uint8_t brightness);
void F15LightChanged(uint8_t brightness);
void F16LightChanged(uint8_t brightness);
void F17LightChanged(uint8_t brightness);
void F18LightChanged(uint8_t brightness);
void F19LightChanged(uint8_t brightness);
void F20LightChanged(uint8_t brightness);
void F21LightChanged(uint8_t brightness);
void F22LightChanged(uint8_t brightness);
void F23LightChanged(uint8_t brightness);
void F24LightChanged(uint8_t brightness);
void F25LightChanged(uint8_t brightness);
void F26LightChanged(uint8_t brightness);
void F27LightChanged(uint8_t brightness);
void F28LightChanged(uint8_t brightness);
void F29LightChanged(uint8_t brightness);
void F30LightChanged(uint8_t brightness);
void F31LightChanged(uint8_t brightness);
void F32LightChanged(uint8_t brightness);
// Change this!!
// WiFi Credentials
const char* ssid = "1111";
const char* password = "2222";
// device names
String Device_1_Name = "luce 1";
String Device_2_Name = "luce 2";
String Device_3_Name = "luce 3";
String Device_4_Name = "luce 4";
String Device_5_Name = "luce 5";
String Device_6_Name = "luce 6";
String Device_7_Name = "luce 7";
String Device_8_Name = "luce 8";
String Device_9_Name = "luce 9";
String Device_10_Name ="luce 10";
String Device_11_Name ="luce 11";
String Device_12_Name ="luce 12";
String Device_13_Name ="luce 13";
String Device_14_Name ="luce 14";
String Device_15_Name ="luce 15";
String Device_16_Name ="luce 16";
String Device_17_Name ="luce 17";
String Device_18_Name ="luce 18";
String Device_19_Name ="luce 19";
String Device_20_Name ="luce 20";
String Device_21_Name ="luce 21";
String Device_22_Name ="luce 22";
String Device_23_Name ="luce 23";
String Device_24_Name ="luce 24";
String Device_25_Name ="luce 25";
String Device_26_Name ="luce 26";
String Device_27_Name ="luce 27";
String Device_28_Name ="luce 28";
String Device_29_Name ="luce 29";
String Device_30_Name ="luce 30";
String Device_31_Name ="luce 31";
String Device_32_Name ="luce 32";
unsigned long Millis = 0;
unsigned long PreviousMillis = 0;
boolean Initialized = false;
boolean wifiConnected = false;
Espalexa espalexa;
void setup()
{
Serial.begin(115200);
pinMode(R2, OUTPUT);
pinMode(R2, LOW);
PreviousMillis = millis();
// Initialise wifi connection
wifiConnected = connectWifi();
if (wifiConnected)
{
// Define your devices here.
espalexa.addDevice(Device_1_Name,F1LightChanged);
espalexa.addDevice(Device_2_Name,F2LightChanged);
espalexa.addDevice(Device_3_Name,F3LightChanged);
espalexa.addDevice(Device_4_Name,F4LightChanged);
espalexa.addDevice(Device_5_Name,F5LightChanged);
espalexa.addDevice(Device_6_Name,F6LightChanged);
espalexa.addDevice(Device_7_Name,F7LightChanged);
espalexa.addDevice(Device_8_Name,F8LightChanged);
espalexa.addDevice(Device_9_Name,F9LightChanged);
espalexa.addDevice(Device_10_Name,F10LightChanged);
espalexa.addDevice(Device_11_Name,F11LightChanged);
espalexa.addDevice(Device_12_Name,F12LightChanged);
espalexa.addDevice(Device_13_Name,F13LightChanged);
espalexa.addDevice(Device_14_Name,F14LightChanged);
espalexa.addDevice(Device_15_Name,F15LightChanged);
espalexa.addDevice(Device_16_Name,F16LightChanged);
espalexa.addDevice(Device_17_Name,F17LightChanged);
espalexa.addDevice(Device_18_Name,F18LightChanged);
espalexa.addDevice(Device_19_Name,F19LightChanged);
espalexa.addDevice(Device_20_Name,F20LightChanged);
espalexa.addDevice(Device_21_Name,F21LightChanged);
espalexa.addDevice(Device_22_Name,F22LightChanged);
espalexa.addDevice(Device_23_Name,F23LightChanged);
espalexa.addDevice(Device_24_Name,F24LightChanged);
espalexa.addDevice(Device_25_Name,F25LightChanged);
espalexa.addDevice(Device_26_Name,F26LightChanged);
espalexa.addDevice(Device_27_Name,F27LightChanged);
espalexa.addDevice(Device_28_Name,F28LightChanged);
espalexa.addDevice(Device_29_Name,F29LightChanged);
espalexa.addDevice(Device_30_Name,F30LightChanged);
espalexa.addDevice(Device_31_Name,F31LightChanged);
espalexa.addDevice(Device_32_Name,F32LightChanged);
espalexa.begin();
}
else
{
while (1)
{
Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");
delay(5000);
}
}
}
void loop()
{
espalexa.loop();
delay(1);
}
//our callback functions
void F1LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,1,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,1,0");
digitalWrite(R2, LOW);
}
}
void F2LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,2,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,2,0");
digitalWrite(R2, LOW);
}
}
void F3LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,3,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,3,0");
digitalWrite(R2, LOW);
}
}
void F4LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,4,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,4,0");
digitalWrite(R2, LOW);
}
}
void F5LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,5,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,5,0");
digitalWrite(R2, LOW);
}
}
void F6LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,6,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,6,0");
digitalWrite(R2, LOW);
}
}
void F7LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,7,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,7,0");
digitalWrite(R2, LOW);
}
}
void F8LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,8,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,8,0");
digitalWrite(R2, LOW);
}
}
void F9LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,9,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,9,0");
digitalWrite(R2, LOW);
}
}
void F10LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,10,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,10,0");
digitalWrite(R2, LOW);
}
}
void F11LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,11,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,11,0");
digitalWrite(R2, LOW);
}
}
void F12LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,12,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,12,0");
digitalWrite(R2, LOW);
}
}
void F13LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,13,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,13,0");
digitalWrite(R2, LOW);
}
}
void F14LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,14,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,14,0");
digitalWrite(R2, LOW);
}
}
void F15LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,15,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,15,0");
digitalWrite(R2, LOW);
}
}
void F16LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,16,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,16,0");
digitalWrite(R2, LOW);
}
}
void F17LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,17,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,17,0");
digitalWrite(R2, LOW);
}
}
void F18LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,18,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,18,0");
digitalWrite(R2, LOW);
}
}
void F19LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,19,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,19,0");
digitalWrite(R2, LOW);
}
}
void F20LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,20,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,20,0");
digitalWrite(R2, LOW);
}
}
void F21LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,21,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,21,0");
digitalWrite(R2, LOW);
}
}
void F22LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,22,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,22,0");
digitalWrite(R2, LOW);
}
}
void F23LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,23,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,23,0");
digitalWrite(R2, LOW);
}
}
void F24LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,24,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,24,0");
digitalWrite(R2, LOW);
}
}
void F25LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,25,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,25,0");
digitalWrite(R2, LOW);
}
}
void F26LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,26,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,26,0");
digitalWrite(R2, LOW);
}
}
void F27LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,27,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,27,0");
digitalWrite(R2, LOW);
}
}
void F28LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,28,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,28,0");
digitalWrite(R2, LOW);
}
}
void F29LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,29,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,29,0");
digitalWrite(R2, LOW);
}
}
void F30LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,30,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,30,0");
digitalWrite(R2, LOW);
}
}
void F31LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,31,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,31,0");
digitalWrite(R2, LOW);
}
}
void F32LightChanged(uint8_t brightness)
{
//Control the device
if (brightness)
{
if (brightness == 255)
{
Serial.println("RELAY-SET-255,32,1");
digitalWrite(R2, HIGH);
}
//Serial.print("ON, brightness ");
//Serial.println(brightness);
}
else
{
Serial.println("RELAY-SET-255,32,0");
digitalWrite(R2, LOW);
}
}
// connect to wifi – returns true if successful or false if not
boolean connectWifi()
{
boolean state = true;
int i = 0;
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
Serial.println("Connecting to WiFi");
// Wait for connection
Serial.print("Connecting...");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
// Serial.print(".");
if (i > 20) {
state = false; break;
}
i++;
}
Serial.println("");
if (state) {
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
pinMode(R2, HIGH);
}
else {
Serial.println("Connection failed.");
pinMode(R2, LOW);
}
return state;
}