Hello,
I'am trying to control the blue led on the ESP32 (dev kit 1) using alexa (Fauxmo),
unfortunately my Alexa (phone & sonos beam) coudn't detect my esp32 ![]()
Any thing wrong with my code hereunder?
Thank you.
#include <WiFi.h>
#include <AsyncTCP.h>
//-------------------------------
#include "fauxmoESP.h"
fauxmoESP fauxmo;
bool alexaTrigger = false;
byte alexaTurn = 0;
//--------------------------------------------------------------------------------------------------------------------------------
#define WIFI_SSID "Livebox-4156"
#define WIFI_PASS "covid2020"
//-------------------------------
#define LED "Blue"
//---------------------------------------------------------------------------------------------------------------------------------
void wifiSetup() {
WiFi.disconnect();
WiFi.mode(WIFI_STA);
// Connect
Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Wait
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(100);
}
Serial.println();
// Connected!
Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WiFi.SSID().c_str(), WiFi.localIP().toString().c_str());
}
//-----------------------------------------------------------------------------------------------------------------------------------
void setup()
{
wifiSetup();
pinMode(2, OUTPUT);
fauxmo.createServer(true);
fauxmo.setPort(80); //
fauxmo.enable(true);
fauxmo.addDevice(LED);
fauxmo.onSetState([](unsigned char device_id, const char * device_name, bool state, unsigned char value) {
Serial.printf("[MAIN] Device #%d (%s) state: %s value: %d\n", device_id, device_name, state ? "ON" : "OFF", value);
if ( (strcmp(device_name, LED) == 0) ) {
//Serial.println("ALEXA TRIGGERED");
alexaTrigger = true;
if (state) {
//Serial.println("LED ON");
alexaTurn = 1;
} else {
//Serial.println("LED OFF");
alexaTurn = 0;
}
}
});
}
//-----------------------------------------------------------------------------------------------------------------------------------
void loop()
{
fauxmo.handle();
if (alexaTrigger) {
alexaTrigger = false; //Reset the trigger
if (alexaTurn){
digitalWrite(2, HIGH);
}
else {
digitalWrite(2, LOW);
}}
}