i have a Echodot gen4 and that's work good , after some days it's not working , i'm use Nodemcu
please help me
this is my code :
(And this is your code with code tags - use them next time. It's the </> button on the menu. Thanks! Moderator.
And remove the extra blank lines too.)
#ifdef ARDUINO_ARCH_ESP32
#include <WiFi.h>
#endif
#include <Espalexa.h>
// define the GPIO connected with Relays
#define RelayPin1 5//D1
#define RelayPin2 4 //D2
// prototypes
boolean connectWifi();
//callback functions
void firstLightChanged(uint8_t brightness);
void fan(uint8_t brightness);
// WiFi Credentials
const char* ssid = "Abdullah_Fibber";
const char* password = "18181818";
// device names
String Device_1_Name = "Room light";
String Device_2_Name = "fan";
boolean wifiConnected = false;
Espalexa espalexa;
void setup()
{
Serial.begin(115200);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
// Initialise wifi connection
wifiConnected = connectWifi();
if (wifiConnected)
{
// Define your devices here.
espalexa.addDevice(Device_1_Name, firstLightChanged); //simplest definition, default state off
espalexa.addDevice(Device_2_Name, fan);
espalexa.begin();
}
else
{
while (1)
{
Serial.println("Cannot connect to WiFi. Please check data and reset the ESP.");
delay(2500);
}
}
}
void loop()
{
espalexa.loop();
delay(1);
}
//our callback functions
void firstLightChanged(uint8_t brightness)
{
//Control the device
if (brightness == 255)
{
digitalWrite(RelayPin1, LOW);
Serial.println("Device1 ON");
}
else
{
digitalWrite(RelayPin1, HIGH);
Serial.println("Device1 OFF");
}
}
void fan(uint8_t brightness)
{
//Control the device
if (brightness == 255)
{
digitalWrite(RelayPin2, LOW);
Serial.println("Device2 ON");
}
else
{
digitalWrite(RelayPin2, HIGH);
Serial.println("Device2 OFF");
}
}
// 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());
}
else {
Serial.println("Connection failed.");
}
return state;
}
