vintlabs / fauxmoESP

Add voice control of your ESP32 and ESP8266 devices using Amazon Alexa
MIT License
379 stars 70 forks source link

Discovery Issues #142

Closed konsumer closed 3 years ago

konsumer commented 3 years ago

I can't seem to get Alexa (via the app or an old Echo Dot) to connect to fauxmoESP. Not sure if this is a duplicate issue, or a new thing, as it seems to not work according to suggestions in other issues.

I am using this code:

#include "wifi_settings.h"
#define DEVICE_NAME "arch 1"

#include <ESP8266WiFi.h>
#include "fauxmoESP.h"

fauxmoESP fauxmo;

void setupWifi () {
  WiFi.mode(WIFI_STA);
  Serial.printf("[WIFI] Connecting to %s ", WIFI_SSID);
  WiFi.begin(WIFI_SSID, WIFI_PASS);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(100);
  }
  Serial.println();
  Serial.printf("[WIFI] STATION Mode, SSID: %s, IP address: %s\n", WIFI_SSID, WiFi.localIP().toString().c_str());
}

void setupFauxmo () {
  fauxmo.setPort(80); // This is required for gen3 devices
  fauxmo.enable(true);
  fauxmo.addDevice(DEVICE_NAME);
  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);
  });
 }

void setup () {
  Serial.begin(115200);
  Serial.println();
  Serial.println();

  setupWifi();
  setupFauxmo();
}

void loop () {
  fauxmo.handle();
}

Serial console correctly shows this:

[WIFI] Connecting to <MY_SSID> ....................
[WIFI] STATION Mode, SSID: <MY_SSID>, IP address: 192.168.86.35

and I can ping 192.168.86.35

Here are the paths in the app I tried:

Devices
+
Add Device
Phillips Hue (button under "Popular Brands")
no bluetooth
V1 bridge
Discover Devices
Devices
+
Add Device
Other
Discover Devices

If you want any other info (like wireshark logs, etc) let me know.

konsumer commented 3 years ago

Update: I got it to work with an Echo Dot, by unplugging the dot, then plugging it back in and saying "Detect new devices" as soon as it woke up.

When I try to control it by voice it says there are more than 1 with that name. When I try to do it in the app (there is only 1 "arch 1" listed) I get "Device doesn't support requested value"

pvint commented 3 years ago

Update: I got it to work with an Echo Dot, by unplugging it, then plugging it back in and saying "Detect new devices"

Good news!

When I try to control it by voice it says there are more than 1 with that name. When I try to do it in the app (there is only 1 "arch 1" listed) I get "Device doesn't support requested value"

Hm. Maybe if you try renaming your device, then do "Discover" again?

konsumer commented 3 years ago

Ok, after playing with it for a bit, it seems much more stable. Renaming it, and the previous restart seems to have made it work much better. Sort of unrelated: here is is wificonnectlite, ArduinoOTA and fauxmoESP all working together nicely on EM8266:


// the name of the config-wifi, the hostname, and the device-name (in Alexa)
#define DEVICE_NAME "archlights"

#include <WiFiConnect.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include "fauxmoESP.h"

WiFiConnect wc;
fauxmoESP fauxmo;

void handleAlexa(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);

  // built-in LED is swapped on EM8266
  digitalWrite(LED_BUILTIN, state ? LOW : HIGH);
}

void setupFauxmo () {
  fauxmo.setPort(80); // This is required for gen3 devices
  fauxmo.enable(true);
  fauxmo.addDevice(DEVICE_NAME);
}

void setupWifi() {
  // wc.resetSettings();

  if (wc.autoConnect()) {
    ArduinoOTA.setHostname(DEVICE_NAME);
    ArduinoOTA.begin();
    Serial.printf("Running as %s with IP: %s\n", DEVICE_NAME, WiFi.localIP().toString().c_str());
  } else {
    wc.setAPName(DEVICE_NAME);
    wc.startConfigurationPortal(AP_WAIT);
  }
}

void setup() {
  Serial.begin(115200);
  Serial.println("\n\n");
  setupWifi();
  setupFauxmo();
  fauxmo.onSetState(handleAlexa);

  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) {
    setupWifi();
  } else {
    ArduinoOTA.handle();
    fauxmo.handle();
  }
}

This gives you the ability to setup wifi in a captive portal, program the device over wifi (no direct connection needed.) This works great! Thanks for a wonderful library.