Hello,
I'm trying to do a project that uses a ESP8266 relay to control an outlet with using an echo dot. The project is based on GreatScott!'s video on Youtube for simple home automation. Since the first thing he tried didn't work I went straight to the sinric solution. Whenever I try to upload the sketch to the arduino that I'ms using to write the code to the relay I keep on getting the same error of "'WebsocketsClient' does not name a type". What can I do to solve this problem. I'll include the code.
switch_example.ino (5.2 KB)
Hi,
I usually use fauxumo esp library for such tasks. It is very easy to use. I am uploading a simple code that should turn on and off an led on pin D1. Give it a try and maybe adapt it for your application. Best of luck with your project.
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <fauxmoESP.h>
fauxmoESP fauxmo;
const char* ssid = "your wlan";
const char* password = "your pass";
void setup() {
Serial.begin(115200);
if (connectWifi()) {
// Setup fauxmo
Serial.println("Adding LED device");
fauxmo.setPort(80);
fauxmo.enable(true);
fauxmo.addDevice("Led");
pinMode(5, OUTPUT);
fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
// Callback when a command from Alexa is received.
// You can use device_id or device_name to choose the element to perform an action onto (relay, LED,...)
// State is a boolean (ON/OFF) and value a number from 0 to 255 (if you say "set kitchen light to 50%" you will receive a 128 here).
// Just remember not to delay too much here, this is a callback, exit as soon as possible.
// If you have to do something more involved here set a flag and process it in your main loop.
Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
// Checking for device_id is simpler if you are certain about the order they are loaded and it does not change.
// Otherwise comparing the device_name is safer.
if (strcmp(device_name, "Led") == 0)
digitalWrite(5, state ? HIGH : LOW); // turns on and off depending on state
});
}
}
void loop() {
fauxmo.handle();
}
boolean connectWifi() {
// Let us connect to WiFi
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(".......");
Serial.println("WiFi Connected....IP Address:");
Serial.println(WiFi.localIP());
return true;
}