fauxmoESP: ESP8266/ESP32 Not Found by Alexa

Hi All, I’m trying to get FauxmoESP running on an ESP8266 with my Alexa and am having some troubles. The sample sketch compiles and appears to run alright (it connects to my home network) but when I try to discover via the Alexa app no new devices are found. Below is my configuration:

Alexa: Amazon Fire TV Cube (2nd Gen I think), connected to router via ethernet cable. Board: Adafruit Huzzah ESP8266 Breakout, connected to 2.4GHz WiFi Arduino IDE 1.8.13 (Windows Store 1.8.42.0) ESP8266 Core: 2.4.2 (also tried 2.7.4 with no luck) FauxmoESP V3.1.1 ESPAsyncTCP current as of 10/26/2020 lwIP variant set to “v1.4 Higher Bandwidth” For code, I started the sample fauxmoESP_Basic. I added #define DEBUG_FAUXMO Serial and removed 3/5 devices based on other peoples issues. Below is the serial output.

SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:1.4.0rc2/BearSSL:6d1cefc      
[WIFI] Connecting to WiFi_SSID scandone      
..scandone      
state: 0 -> 2 (b0)      
state: 2 -> 3 (0)      
state: 3 -> 5 (10)      
add 0      
aid 4      
cnt       
connected with WiFi_SSID, channel 11      
dhcp client start...      
..................ip:192.168.1.241,mask:255.255.255.0,gw:192.168.1.1      
[WIFI] STATION Mode, SSID: WiFi_SSID, IP address: 192.168.1.241      
[MAIN] Free heap: 48464 bytes      
pm open,type:2 0      
[MAIN] Free heap: 47944 bytes      
[MAIN] Free heap: 47944 bytes      
[MAIN] Free heap: 47944 bytes      
[MAIN] Free heap: 47944 bytes

Thank you for any advice, Lightbulb14

Source Code:

#include <Arduino.h>
#ifdef ESP32
    #include <WiFi.h>
#else
    #include <ESP8266WiFi.h>
#endif
#include "fauxmoESP.h"

// Rename the credentials.sample.h file to credentials.h and 
// edit it according to your router configuration
#include "credentials.h"

fauxmoESP fauxmo;

// -----------------------------------------------------------------------------

#define SERIAL_BAUDRATE     115200

#define LED_YELLOW          4
#define LED_GREEN           5


#define ID_YELLOW           "yellow lamp"
#define ID_GREEN            "green lamp"


#define DEBUG_FAUXMO Serial

// -----------------------------------------------------------------------------

// -----------------------------------------------------------------------------
// Wifi
// -----------------------------------------------------------------------------

void wifiSetup() {

    // Set WIFI module to STA mode
    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() {

    // Init serial port and clean garbage
    Serial.begin(SERIAL_BAUDRATE);
    Serial.println();
    Serial.println();

    // LEDs
    pinMode(LED_YELLOW, OUTPUT);
    pinMode(LED_GREEN, OUTPUT);

    digitalWrite(LED_YELLOW, LOW);
    digitalWrite(LED_GREEN, LOW);


    // Wifi
    wifiSetup();

    // By default, fauxmoESP creates it's own webserver on the defined port
    // The TCP port must be 80 for gen3 devices (default is 1901)
    // This has to be done before the call to enable()
    fauxmo.createServer(true); // not needed, this is the default value
    fauxmo.setPort(80); // This is required for gen3 devices

    // You have to call enable(true) once you have a WiFi connection
    // You can enable or disable the library at any moment
    // Disabling it will prevent the devices from being discovered and switched
    fauxmo.enable(true);

    // You can use different ways to invoke alexa to modify the devices state:
    // "Alexa, turn yellow lamp on"
    // "Alexa, turn on yellow lamp
    // "Alexa, set yellow lamp to fifty" (50 means 50% of brightness, note, this example does not use this functionality)

    // Add virtual devices
    fauxmo.addDevice(ID_YELLOW);
    fauxmo.addDevice(ID_GREEN);


    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, ID_YELLOW)==0) {
            digitalWrite(LED_YELLOW, state ? HIGH : LOW);
        } else if (strcmp(device_name, ID_GREEN)==0) {
            digitalWrite(LED_GREEN, state ? HIGH : LOW);
        } 

    });

}

void loop() {

    // fauxmoESP uses an async TCP server but a sync UDP server
    // Therefore, we have to manually poll for UDP packets
    fauxmo.handle();

    // This is a sample code to output free heap every 5 seconds
    // This is a cheap way to detect memory leaks
    static unsigned long last = millis();
    if (millis() - last > 5000) {
        last = millis();
        Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap());
    }

    // If your device state is changed by any other means (MQTT, physical button,...)
    // you can instruct the library to report the new state to Alexa on next request:
    // fauxmo.setState(ID_YELLOW, true, 255);

}

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 118 (38 by maintainers)

Commits related to this issue

Most upvoted comments

I’m done a little testing and have not been able to get the ECHO Discovery process to fail in ways that I was not expecting.

ESP8266 D1 Mini 12F fauxmoESP - Master

1st Pass/Fail = New discovery 2nd Pass/Fail = Alexa Voice control after the discovery

test Echo Rev 2 - D1 Mini 12F - Test run in this chronological order Pass Fail Pass Fail
1 New UniquieID (1st D1 Mini 12F). New Device Name (name never used in the past) x x
2 Same UniquieID as previous discovery. Same Device Name as previous discovery, different sketch (a) x x
3 Same UniquieID as previous discovery. Different Device Name than previous discovery, did not delete the test2 devices (b) x x
4 Same UniquieID as previous discovery. Same Device Name as test3 previous discovery, after deleting test2 device names © x x
5 NEW UniquieID than previous discovery (2nd D1 Mini 12F). Different Device Name than test4 previous discovery (d) x x
6 Same UniquieID as previous test5 discovery (2nd D1 Mini 12F). Same Device Name as test4 above, after deleting device names from test5. Different UniquieID same Device Names. (You would never do this , but your users would.) x(e) x(f)

a.  Reused the same device names on the same D1, with a different sketch. b.  Did NOT delete the old device names in Alexa App. c.  Deleted the Divice Name in Alexa App d.  Did not delete the #4 Device Names in the Alexa App. e.  Discovery only found the 2nd fauxmoESP device (fauxmo 1st and 2nd is simply the order listed in the sketch).  The 1st fauxmoESP device was not found.

I think just stepped into the rabbit hole… I don’t think this is a fauxmoESP issue. Maybe an enhancement.

f. The Echo discovery process got very confused with the same Device Name associated with difference UniquieID (8266). Alexa is now doing some weird things.

And, yes, I did fall deeper into the rabbit hole. If you think its relevant, @pvint , I will happily share the next set of observations.

(this was hard to write up, so if things could be made clearer, please help me out)

Upgraded to 3.1.2 and everything works well again. Thank you.

Hi all.

After a number of unsuccessful attempts over the last year to get fauxmoESP running, I tried it again yesterday, and it now works for me.

Here’s what I’m using :

  • Arduino IDE 1.8.13

    • FauxmoESP library installed from Arduino IDE library manager – by Xose Perez Version 3.1.2
  • ESP8266 – Wemos D1 Mini

    • Board: LOLIN(WEMOS) D1 R2 & mini
    • IwIP Variant: “1.4 Higher Bandwidth”

I’m doing the discovery/add via the Alexa app on iOS (iPhone 6S).

I do the add/discovery via:

Devices -> (+) -> Add Device -> Other -> Discover Devices

or:

Devices -> (+) -> Add Device -> Plug -> Other -> Discover Devices

The only thing I noticed is that the device comes up as Type: Other. It would be nice if it could come up as a Plug or Light so it could be added to my light groups, etc.

2020-12-17 - 002

Hope this helps.

-Jon

@kbssa I just unplugged all of my Echo devices and tested from my Android phone in the Alexa App, and it did not discover.

Honestly, I’ve never tried that before, so I’m not sure what to expect. Note that it did work when I did “discover” on the phone in the app when I had 3 Echo devices plugged in. I can look at this more later.

Will get one echo on the next days and I will try that and let you know.

Thank you for testing it for me, saved me a lot of time.

I have been using IwIP “v2 Higher Bandwidth”, I switch to “v2 Lower Memory” No Success! Switch to IwIP “v1.4 Higher Bandwidth” Discovery SUCCESS! I’ll do some more testing with different Echo Dots and the App and different sketches and post an update.

Update:: I was able to discover devices with Dot Gen2, Dot Gen3 and the Alexa app (screen add device only).
It appears to be as expected.

I’m assuming the use of IwIP v1.4 vs v2 depends on the flash memory chip? Maybe I just have an older version flash chip.

Thx @pvint , I’ll try master branch today. My issue was I used latest platformio lib… Hope my issues are solved by using master instead. I’ll report later today 👍

If You like, You can use this library in attached… that works for me.

@adbensi The library you spoke of was not attached. If you have something workiing right now, I sure some people would be interested. thanks

Update: Just tried again and eveything has been discovered including old device names which are no longer in any fauxmo code I have. All I did was to restart ‘discover devices’ via alexa.amazon.com and then 10 seconds in I restarted one of the fauxmo ESP devices. Strange behaviour, some kind of caching perhaps in local router or echo devices? Anyhow, I can now get back to project. Still happy to try out any suggestions, as I dont think I have seen the last of this issue.

@pvint the discoveryIssue works for me, and found old devices names too; No problem to delete them, thanks!

I didn’t find much time for testing during the week, but spend quite a while with this today. So far, it looks pretty promising. I was using the Master branch code without any change. This is on ESP8266/NodeMCU v0.9 and with Echo Dot 2G. Discovery seems to work stable. The only issue I came across is that one about old devices that appeared again. I narrowed it down to some extent: In the past, I did a “Remove all” in the Alexa app, but it seems that this was the issue. When I remove all, they come back with discovery (but with old names, instead of new ones). Now if I just remove selected ones (e.g. my device ID 2 and 5 because I gave them new names) and do discovery again, then it seems to work perfectly fine. I was able to discover and control 8 devices using fauxmoESP

I don’t have any ESP8266 modules available to test at the moment, but I’m expecting more today or tomorrow and I’ll be testing with them.

@pvint - the code you placed in the discoveryissue branch works for me. Great. Many thanks. Discovery worked without alexa reboot and all devices got discovered now. Will do a bit more testing, but wanted to give quick feedback and send my thanks to you!

Thanks for the work everyone, but my Alexa is still unable to discover the fauxmoESP device. I downloaded the discoveryIssue branch and replaced the fauxmoESP.cpp and templates.h in my Arduino libraries folder with ones from the discoveryIssue download. Could me using an Amazon Fire Cube make a difference?

Also, the changes that pvint listed in the comment for templates.h should be changed to "\"uniqueid\":\"%s\","

I got a déjà vu from reading this…

Is this related to the issue & proposed changes from espalexa described here? https://github.com/xoseperez/espurna/issues/1904#issuecomment-529957777 https://github.com/Aircoookie/Espalexa/commit/9d57e2cbc706c503e71acc651ed47e6e09496614#diff-60d0a10c47ca0f0800ce9f6773faec4aR166

Resulting string is constructed as: uint32_t id = (mac[3] << 20) | (mac[4] << 12) | (mac[5] << 4) | (idx & 0xF);

Where the changed replaced uniqueid number with: mac last 3 bytes -dash- deviceId+1 (also note it’s encoded as decimal)

Not using Alexa to test / verify this, ESPurna just happens to use fauxmoESP since it was Xose’s project as well 😊

@pvint Thanks for the reply. I did try the delete History in the Alexa Amazon app. That by itself did not make the discover new devices work. I can confirm that the power off/on of the Echo dot Gev3 does allow Alexa to find new devices but only one time per off/on cycle. I think it just a fluke that that the discover devices still works at all.

Maybe the real issue is the End of Support (EOS) for the Philip Hue Bridge 2012 the code is emulating. If I’m reading the ‘templates.h’ correctly, the JSON in the FAUXMO_DESCRIPTION_TEMPLATE[] is using the modelName and modelNumber of the Hue Bridge V1

"<modelName>Philips hue bridge 2012</modelName>" "<modelNumber>929000226503</modelNumber>"

The EOS for that Bridge was announced April 29, 2019 and was followed on by April 30, 2020 with no more updates to the Hue Bridge V1. See my posts of 2 days ago for the links to the EOS articles. About that time, April 2020, Amazon Alexa came out with a Gen 4 release with all their updates and just maybe FauxmoESP and the Hue Bridge V1 suffered in the aftermath.

FauxmoESP is not the only Library having this issue right now. Aircoookie/Espalexa https://github.com/Aircoookie/Espalexa is experiencing the same issues of NOT discovering new devices. It was thanks to @seriouz on Aircoookie/Espalexa that brought the EOS issue to my attention with his post on March 9, 2020.

Maybe we can use the Hue Bridge V2? I suspect the JSON format for the V2 is different than the V1.

I’m not going to be much help with the code, but I would be happy to help any other way.

I got mine to work this morning on a Gen 2 Echo Dot - I have not tested heavily yet, but I had noticed that a couple times when I discovered it found an old device that was not even online, so I went to Amazon and deleted device history, here:

Amazon ca: Manage Your Content and Devices - Google Chrome_067

Please go to https://www.amazon.ca/hz/mycd/myx#/home/alexaPrivacy/deviceHistory (substitute .com .de or whatever in the URL for your location) and try deleting smart home devices history and retry discovery. (I don’t know if it’s relevant, but I rebooted my Echo before trying discovery)

Let me know Paul