# Emulate a WeMo device with ESP8266

My daughters love to talk to (or with) my Amazon Dot [Amazon US] in their funny English: “Alexa, hello!”, “Alexa,  li-on!” (actually “light on”). It’s so easy to use it to switch on/off things at home using the fauxmo python script by Maker Musings. In his post about Amazon Echo and Home Automation more than a year ago he explains how he reverse-engineered the protocol of the WeMo switches that Alexa (Amazon Echo [Amazon US] or Amazon Dot [Amazon US]) supports.

I also have a server running the fauxmo script with an MQTT handler to control some of the Sonoffs I have at home, but this morning I woke up thinking: why should I use an external script to control my devices if I can code it in the firmware?

## The fauxmoESP library

You will never be the first. Aruna Tennakoon had already done it a few months ago. But his approach did not suit me. I wanted something that could be easily embedded into an existing solution (like my ESPurna firmware). So I’ve coded it into a library I could include in my other projects and have it run in 3 lines of code. Literally.

Lately I have been migrating ESPurna to the state-of-the-art ESPAsyncWebServer by core developer Hristo Gochkov (@me-no-dev). So I decided to go for his suit of asynchronous TCP and UDP libraries for this project (note: finally the ESPAsyncUDP library has been removed and its using the WiFiUdp instead). The result is a fast, sturdy library that is amazingly easy to use.

The result is the fauxmoESP library, named after Musings’ code.

The fauxmoESP library for ESP8266 is released as free open software and can be checked out at my fauxmoESP repository on Bitbucket.

## Installing and compiling it

Instructions here have been updated for version 2.0 of the library.

### Using PlatformIO

As I said, the fauxmoESP library depends on ESPAsyncTCP and ESPAsyncUDP libraries by Gochkov. You will need those first in order to compile it. You will also need the latest Arduino ESP8266 Core installation, at least from after July 11 2016. This is required to join the multicast group where the WeMo app (or Alexa) broadcast a message when searching for compatible devices.

You will need to install ESPAsyncTCP via the lib_deps option in the platformio.ini file or by typing:

pio lib install ESPAsyncTCP


### Using Arduino IDE

Same applies to the Arduino IDE. You will need to use the development version of the ESP8266 Arduino Core. Steps to use the library are:

1. Install the latest ESP8266 Arduino Core using the instructions here: https://github.com/esp8266/Arduino#using-git-version (remove before the stable version from your Boards Manager if any).
2. Copy or checkout the ESPAsyncTCP and ESPAsyncUDP libraries in your arduino/libraries folder, it should be under “My Documents/Arduino/libraries” in Windows or “Documents/Arduino/libraries” in Mac or Linux unless you have placed it somewhere else.
3. Same for the fauxmoESP library, check it out in the arduino/libraries folder.
5. Look for the fauxmoESP_Basic example under File > Examples > fauxmoESP > …
6. Choose your board and compile.

## Using it

Include the library, instantiate an object, set the device name define your devices and the message callback and you are done. It can’t be easier. Since all the networking stuff is asynchronous there is no need to manually poll for new messages. If you are using Amazon Echo [Amazon US] or Dot [Amazon US], once the device is running click on “Discover devices” from the “Smart Home” tab and your device name will be added to the list, now just say “Alexa, turn on/off” and enjoy!

You can change the device name on the fly and re-scan for new devices, the old one will be replaced.

The library allows you to define more than one device to be discovered and then perform different actions depending on which one was triggered. This was a suggestion by user Dave Myers in the comments below and has meant a change in the library API. Version 2.0 includes some discovery optimizations and has some API changes. The example below is taken from the 2.0.0 examples. As you can see the library requires a minimum setup.

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

#define SERIAL_BAUDRATE                 115200

fauxmoESP fauxmo;

// -----------------------------------------------------------------------------
// 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();

// Wifi
wifiSetup();

// Fauxmo v2.0
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
});

}

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


## Control your ESPurna device with Alexa

I’ve also worked on the integration of the fauxmoESP library in ESPurna. The code is there and it works but I have decided to disable support by default. Basically because of the required staging environment for the espressif8266 platform in PlatformIO. Right now to compile it with WeMo emulation support you have to change the platform to “espressif8266_stage” and add “-DENABLE_FAUXMO=1” to the build flags. Check my platformio.ini file above. Once PlatformIO updates the espressif platform I will probably enable it by default. As of version 1.4.1 of ESPurna it includes fauxmoESP 2.0 which does not require any special development environment and is included by default in every ESPurna built.

## 204 thoughts on “Emulate a WeMo device with ESP8266”

1. Dave Myers

Great code! I’ve used the other wemo-emulation code for the esp8266 that you mention, but I like the library approach used here. One feature I’m trying to add to your code is ability to instantiate multiple instances of fauxmoESP within a single sketch / on a single ESP8266 device. (I.e., I want to advertise two separate faux WeMo devices in order to have separate control of GPIO pins.

I’ve successfully modified the code to incorporate the TCP port passed to the constructor within the WeMo uuid. However, I’m stuck with the UDP bind to the multicast address (within the ESPAsyncUDP class). Once the first instantiation binds to the multicast address, the second instantiation fails to bind – and hence only the first object responds to any of the Echo’s search requests.

Any ideas on how to modify to allow multiple binds or multiple callbacks when a specific multicast address is opened? And this is all complicated by each fauxmoESP object having its own _udp object….

Perhaps consider this a feature request. Having a single esp8266 be able to emulate multiple WeMos would be very handy if – for instance – the esp has several gpio outputs connected to relays.

1. Xose Pérez Post author

Actually it’s a really good idea. I’d rather implement it as a feature in the class instead of instantiate different objects of it. The UDP binding has to be unique and it can answer to a request providing different device addresses. Then there should be an ESPAsyncTCP instance for each device, listening to different ports. The API could be something like:

fauxmo.addDevice("switch1"); fauxmo.addDevice("switch2"); fauxmo.begin();

Will give it a try.

1. Dave Myers

Excellent! Tested and working.

I ran through some tests of extreme situations (18 devices) — Alexa has trouble discovering all – and is inconsistent about which of the 18 are discovered each time. The most I’ve been able to have discovered is 10 but many tests only found 8. I’ve read in other places that this is a limitation in the way Alexa’s discovery code works – likely too short of a timeout while waiting for UDP responses.

Since a practical limit of number of devices per ESP is likely less than 5, I think this should work.

Thanks again.

1. Xose Pérez Post author

Great!
I had not run any tests with so many devices, 4 was the maximum I thought of since I recall having seen 4 relay ESP8266 boards…

2. Dave Myers

Thanks again. The only reason I can think of for a higher number of devices (and actually an idea I’m working on implementing) is a 433MHz remote outlet WeMo bridge. Ie, wemo like control over (much) cheaper 433MHz outlets. Since the ESP module won’t be constrained by gpio pins (as it will only be connected to a 433 transmitter), the number of outlets for individual control is only limited by range and the number of outlets allowed by the RF protocol.

I’ll play with the debug logs and see if I can trace what is happening with the device search responses.

Thanks again.

3. DMS

I was also not able to get more than 8 devices discovered. If you figure out what’s going on I’d be grateful! Looking at logs it appeared that while all devices were returned in the UPnP request (2 of them in a row actually) only 6-8 returned with HTTP calls.

2. DMS

I did copy and compile the multidevice branch, added some lookup code to allow a string table to hold 16 some odd devices, increased TCP_MAX_CLIENTS to 16 and interfaced via rest APIs to a Chronos I RS232 bridge (another esp device). I was only able to get between 6 and 8 devices registered – the UPnP call returned all 16 but only 6-8 got HTTP call backs for information. Ran out of time to debug but wonder if the return of 16 caused a timeout on ECHO.

1. Beautifulsmall

Using the main branch, I have been trying several numbers of fauxmo.addDevice(“light one”);
I used light 0-16, Alexa reported finding 4 but responded correctly to 1-8, said 11 and 13 had multiple devices , 14 worked, 15,16 not recognised.

2. Xose Pérez Post author

Maybe it would be a good idea to add a delay between UDP responses. Will try it next week, I’m off for the weekend.

2. Andrew

I am able to upload the example sketch, and successfully connect to my local WiFi, but the device is not discoverable. I even tried to manual ping the IP address assigned to the esp8226 but I am not getting a response. Any ideas?

1. Xose Pérez Post author

I guess you are already monitoring the console output, don’t you? Check if there is any activity enabling the DEBUG_FAUXMO build flag.

1. developer411blog

I love the idea, but I’m having the same trouble that Andrew had. I build the code, upload it, and check the serial monitor. When I reset the ESP (12E) I see the device connect to my network, then nothing.

How do I enable the debug flag?

I’m, using VSCode with PlatformIO.

1. Xose Pérez Post author

1. developer411blog

Thanks Xose, but adding that causes the following to fail during a build:

In file included from C:\Users\pallsopp\.platformio\lib\FauxmoESP_ID1303\src\fauxmoESP.cpp:31:0:
C:\Users\pallsopp\.platformio\lib\FauxmoESP_ID1303\src\fauxmoESP.cpp: In member function ‘void fauxmoESP::_sendUDPResponse(unsigned int)’:
C:\Users\pallsopp\.platformio\lib\FauxmoESP_ID1303\src\fauxmoESP.h:76:48: error: request for member ‘printf’ in ‘1’, which is of non-class type ‘int’

My .ini now looks like this:
[env:esp12e]
platform = espressif8266
board = esp12e
framework = arduino
lib_deps = ESPAsyncTCP
build_flags =
-D DEBUG_FAUXMO = Serial

Thanks 🙂

2. Xose Pérez Post author

Maybe the compiler is not parsing the build flags right, there should be no spaces between the -D and the flagname and the “=” and the value:

build_flags = -DDEBUG_FAUXMO=Serial

3. Bobonion

Great code, thanks. I use the esp8266 to send its control over to an arduino nano which sends TV and Sky IR remote controls, works ok but needs one device per remore button hence the need for over 16. Need to implement “jump advert” and other code combinations, “Channel BBC1”. Not sure if devices is the best way but not come across any others.

1. Xose Pérez Post author

Thanks! Wow, 16 devices are a lot of devices. Did your Amazon Echo/Dot find them all?
I have to investigate on how to add more options, right now it only supports on/off kind of commands, but I’d like to add colors, intensities,… like ins your case it could be “Alexa, set device channel to 8”.

1. bobonion

No I can’t get more than six just now. It would be better to have the state pattern as the second word instead of on/off. I’ll try to look into this also. I’ll have to do a instructables if It all comes together. If I don’t use the number buttons still need 20 options ! .

4. Jez Merchant-Locke

Hi… I have just had an emotional few hours getting this to work (first time using the arduino and esp) I have the terminal stating light one on and off but how do i toggle a pin on the ESP?

1. Xose Pérez Post author

Cool! Congrats and welcome to the group 🙂
Now that you have the basics going on you can just use digitalWrite to toggle any pin:

 fauxmo.onMessage([](const char * device_name, bool state) {

 Serial.printf("[MAIN] %s state: %s\n", device_name, state ? "ON" : "OFF"); // GPIO2 is attached to the onboard LED in the ESP12 module: digitalWrite(2, state); 

 }); 

5. Bobonion.

Ive ended up deviating slightly and used the skills kit and lambda to catch my TV remote voice requests and just a url call with data to the esp http webserver from Lambda. Im getting ~ 1 second round trip with the Ireland AWS server. Not much in it between this and devices although ive an open port with no security. I can get all the commands I want though.

1. Xose Pérez Post author

I gave it a try the other day without luck. A skill looks like being the right path, but I’d like to know if there is a way to do something general, like an Alexa-to-MQTT skill…

1. Jesus

Already tested. Now I can switch on/off my light relays.
But I can’t get recognized more than 8 WeMo devices. I want to send IR commands to my Tv and air heating system, so getting more than 8 would be great.
Have you checked it?
Ha-Bridge could do this but I don’t want to have a Pi or Pc running all the time the java script.

1. Xose Pérez Post author

Can you checkout the v2 branch of the project and see if it works better for you? You will have to install ESPAsyncWebServer too and mind there is a change in the callback signature. Check the example for that branch.

1. Jesus

With V2 I got up to eleven devices detected !!!, some times are three or four devices marked “offline” but they work, the same as in first version.

It’s important to name the devices in groups of no more than eight units, I mean: “lamp one, lamp two, …, lamp eight” if you put more then Echo only recognizes the first eight ones. Seems that Alexa groups devices with the same starting name in table of no more that eight.
You can say : “Alexa lamp on” and she said “I found several devices that matches this name, which one did you want” then you must say “one” or “two”, etc.

I checked again your first version taking care of this syntax but the maximum number of devices was eight again.

When I “discover devices” in the Alexa web app some times I got a crash in ESP8266 unit printing the stack in the console and resets. Usually it happened after pressing “discover devices” four or five times.

2. Xose Pérez Post author

Good! I’ve also noticed that v2 is slightly more responsive, but the discovery process is very noisy so no wonder why not all of them get discovered the first time. The “offline” flag only means it was not seen during the last discovery process. But since it is already in you list, chances are it will work when invoked on it’s own, without so much noise. So, after all, it’s a matter of running the discovery process 2 or 3 times until all your devices have been added to the list.

Does the crash you mention happen with the first or second version?

3. Jesus

The crash happened with V2 and after pressing discovering devices many times.

Have you tested with more than one ESP8266 boards running your sketch ?

Will the limit of 8-11 devices for each ESP board or for the total ?

4. Xose Pérez Post author

That’s a good question. I don’t know… yet. Will do some tests. I don’t think there is a hard limit in the number of devices, the problems arise when there are too many requests, then some might get lost. If that’s the case the jam will be localised on every single ESP board.

6. Jeff Bacon

this is an excellent project and I’ve already built several small projects around it. One thing I notice though, only Alexa can recognize these devices. What would it take to get some other smart hub (such as Samsung SmartThings) to also recognize these?

Also, is there a mechanism where we could query the status of one of these devices (rather than just send commands, instead have it return the state of the device through a callback)?

1. Xose Pérez Post author

Hi, Thanks! It’s a matter of knowing the protocol. I don’t know much about SmartThings but it looks like it uses a simple HTTP protocol so it might not be hard to do. I’m sure someone has already done that. The WeMo support for Alexa is quite limited. That’s great since it doesn’t even checks whether it’s a real WeMo device but on the other hand it’s (afaik) only one direction.

7. Disneysw

I have just ordered some sonoff devices with the intention of re-flashing them to work with Alexa. For those who do not know sonoff produce a range of low cost smarthome devices based on the ESP8266 chip. The hardware gets resonable reviews and its hard to bet the price

Will let you know how I get on!

8. pdev

Hi, can we discover the esp8266 based device(s), if we are using a raspberry pi based Alexa voice service?

9. Paulo Cunha

Hello all im getting this errors when i try to compile fauxmoESP_Basic in arduino ide:

Arduino: 1.6.13 (Windows 10), Board: “Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 1M (64K SPIFFS), ck, Disabled, None”

C:\Users\Cunha\Documents\Arduino\libraries\ESPAsyncUDP-master\src\AsyncUDP.cpp: In member function ‘bool AsyncUDP::listenMulticast(ip_addr_t*, uint16_t, uint8_t)’:

C:\Users\Cunha\Documents\Arduino\libraries\ESPAsyncUDP-master\src\AsyncUDP.cpp:248:57: error: ‘udp_set_multicast_netif_addr’ was not declared in this scope

^

C:\Users\Cunha\Documents\Arduino\libraries\ESPAsyncUDP-master\src\AsyncUDP.cpp:249:36: error: ‘udp_set_multicast_ttl’ was not declared in this scope

udp_set_multicast_ttl(_pcb, ttl);

^

exit status 1
Error compiling for board Generic ESP8266 Module.

Any help would be great.
Thanks.

1. Xose Pérez Post author

Hi
No, that’s the current stable version. Please check the instructions in the link I provided.

1. Xose Pérez Post author

Really, you should have read the link I posted, the same link in the documentation of the library. It’s the same solution you have just linked.

10. John Melling

Great project and thanks for all your hard work – much appreciated.
Just received my Amazon Echo for Xmas and have reprogrammed a Sonoff device with added 433MHz transmitter to emulate a cheap Energenie remote control of 4 mains sockets. Echo found and recognised the devices by their names e.g. Lounge lights and turns them on/off as commanded. Wife very impressed! Keep up the good work. Thanks again.

1. Xose Pérez Post author

Hi
Thank you and good work you too. A great idea to hack the Sonoff as a bridge. I hope you will share your project.

1. John Melling

I’ll try and put some details together and send it to you probably early in the new year. I’m also looking at WEMO emulating an IR remote control to get Alexa to control the TV. Using the Sonoff gives the 3v3 power supply, ESP8266, and a suitable case all in one. I’ve upgraded the flash memory device so I can do OTA programming and removed the relay to give space for the 433MHz transmitter module.

1. Xose Pérez Post author

The thing with the Wemo emulation is that, so far, it seems to support only on/off commands. I have it controlling my xmas tree with commands line “rainbow mode on”, “turn on twinkle mode” and so on. It’d be cool to be able to use attributes like “Alexa, set xmas tree mode rainbow”, or in you case: “Alexa, change TV channel to…”

1. John Melling

Yes I agree it is rather a limitation but I’ll start with TV on/off,mute on/off, volume on/off to increase/decrease volume level and a few select channels e.g. BBC 1 HD on, ITV 1 HD on etc.and see how it goes from there. Will probably end up having an ‘Alexa shouting match’with my wife trying to pick channels but it will make a change from fighting over who should have the remote control!

11. Paulo Cunha

Im using AlexaPi and Alexa cant discover any devices. I have flashed my sonoff with arduino ide by selecting “generic esp8266”.
Help

12. pdev

Happy new year! Can this be integrated with Google Home? Based on Wemo’s announcement, the Wemo firmware version should be 10885 or higher for both iOS and Android. I am not sure if that would affect anything here. Anyway, your comments would be very much appreciated in this regard. Thanks!

1. Xose Pérez Post author

The fauxmo emulator is not 100% compatible with Wemo. Actually your device using fauxmoESP library won’t be visible from the WeMo app. But it happens that Alexa does not care about details like authentication, it just uses the minimum set of API to interact with the device and that’s just what the library exposes. So it will depend on the actual integration between Google Home and a WeMo device…

2. jzizmor

pdev, have you tried this with a google home yet? I’m considering replacing my echo dot with a google home but wanted to check on this same issue as well.

1. Xose Pérez Post author

The ESPurna firmware version 1.4.1 includes the required changes to use fauxmoESP 2.0, please update your ESPurna copy too.

13. George Ioakimedes

I get a compile error message:

Arduino: 1.8.0 (Windows 7), Board: "Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck, Disabled, None"

C:\Users\George\Documents\Arduino\ESP8266_Alexa\ESP8266_Alexa.ino: In function 'void setup()':

ESP8266_Alexa:57: error: no matching function for call to 'fauxmoESP::onMessage(void (&)(const char*, bool))'

fauxmo.onMessage(callback);

^

C:\Users\George\Documents\Arduino\ESP8266_Alexa\ESP8266_Alexa.ino:57:30: note: candidate is:

In file included from C:\Users\George\Documents\Arduino\ESP8266_Alexa\ESP8266_Alexa.ino:3:0:

C:\Users\George\Documents\Arduino\libraries\fauxmoESP\src/fauxmoESP.h:104:14: note: void fauxmoESP::onMessage(TStateFunction)

void onMessage(TStateFunction fn) { _callback = fn; }

^

C:\Users\George\Documents\Arduino\libraries\fauxmoESP\src/fauxmoESP.h:104:14: note:   no known conversion for argument 1 from 'void(const char*, bool)' to 'TStateFunction {aka std::function<void(unsigned char, const char*, bool)>}'

exit status 1
no matching function for call to 'fauxmoESP::onMessage(void (&)(const char*, bool))'

"Show verbose output during compilation"
option enabled in File -> Preferences.


Would you mind taking a look and helping me determine how I could fix this error?

14. George Ioakimedes

I found the reason for the error. As explained in your v2.0 notes, the callback function was changed. It added device_id so the adafruit example code function “callback” needs to be changed to this:

void callback(unsigned char device_id, const char * device_name, bool state) {
Serial.print("Device ID "); Serial.print(device_id);
Serial.print("Device "); Serial.print(device_name);
Serial.print(" state: ");
if (state) {
Serial.println("ON");
} else {
Serial.println("OFF");
}
}


Your example code should also be updated to version 2.0 support since for me that is what I downloaded following your instructions. At this point I have only compiled the code successfully, I have not actually tested it yet.

1. Xose Pérez Post author

The example code in the repo was updated with the version bump. I guess you mean the code in this post. You are right, I have just updated it to reflect version changes. Thank you!

15. Jesus

Hi, again Xose.

I’ve been using V2 FauxmoESP since two weeks ago and all is ok. Now I’ve seen that V2 has some changes, now don’t use AsyncUDP, is it?

So my question is if it’s worth to recompile and install this new version?

Now I just get 8 to 11 devices discovered, will this new version improve it?

Visc a Premià de Mar, crec que molt a prop teu, no?

1. Xose Pérez Post author

Well, they say “if it’s working, don’t change it”, right? I have had better discovery experience with v2. Testing with 16 devices it very often discovers all of them in the first round. Aside from that the other major “improvement” is that staging version of the Arduino Core for ESP8266 is no longer required. As a drawback now you have to poll for UDP messages manually calling the handle() method in your loop. I’d say it’s a matter of taste.

I tant! Jo estic a Sant Pol.

You are welcome!

1. Jesus

in my loop() there are loops with long delays that could take up to 15 seconds to finish due to my blinds program scenes, so, would be a problem to call the handle() function every, lets say 15 seconds?
Are there any way to have both libraries v1 and v2 at arduino libraries folder? now I’m replacing it each time I make some tests.

Thanks company !!!

1. Xose Pérez Post author

The handle() is only needed to pull UDP requests, so only when you are discovering devices. Something that will not happen very often and that’s under your control. On the other hand I would try to find a different solution for your loop. 15 second delays will break you WIFI connection for sure.

16. jzizmor

Have you tried this with multiple Arduinos? I have multiple light switches I want to control that are too far apart to be convenient.

1. Xose Pérez Post author

First thing the library is meant to work on an ESP8266 microcontroller. Not Arduino hardware. Second, yes I have several devices at home that I manage with voice commands but they are all in the range of my WiFi network. I don’t know what you mean by “too far apart”.

1. jzizmor

It was my understanding that this was meant to run on an Arduino with the ESP8266 attached to it.

I am unclear then where to do the “pio lib install”.

Also, how do I get the firmware for the ESP8266 on the Arduino IDE.

17. TimK

I purchased a Sonoff and Sonoff Dual in the hopes to get it working with Alexa. I read in a few places online that Sonoff has an effort to support Alexa sometime this year (around the Jan-Feb-March timeframe)… I’m afraid if I flash to espurna and I run into issues, the device would be useless to me. Is there any way to backup and restore the original ewelink firmware? I did find this interesting article that appears to have the original firmware; I’m new to all of this and of course I’m just worried: https://wiki.almeroth.com/doku.php?id=projects:sonoff.

1. Xose Pérez Post author

Wow! Great article. I did not know about it, thank you for pointing me to it.

Of course if you ever want to use the original firmware again you will need a way to back it up (if not the binary itself). I have not tested it. This forum thread could be of some help.

18. Doug Carr

Hi,

First thank you for your hard work! This is a fantastic contribution to the maker community.

I don’t have much experience programming or with electronics but I’d like to think I fan follow directions and Google my brains out when something goes wrong. I had the first version working very well. No problems at all. Then I saw that a new version of fauxmoESP was released and I decided to give it a go. I went back to the release of the ESP8266 core and installed the new fauxmoESP library. I then compiled the sample code and successfully uploaded to same Adafruit Feather HUZZAH that the old code was running on. All well and good so far. I opened the serial monitor and then asked Alexa to discover devices. This is the first time I’ve even seen a controller crash so I was very surprised.

Needless to say I have Googled my brains out on this one and I’m at a loss to solve this. Please see the crash dump below and offer any advise you can on how I can resolve this. Thank you.

===== Begin Crash Dump =====

Exception (3):

ctx: cont
sp: 3ffef440 end: 3ffef830 offset: 01a0

>>>stack>>>
3ffef5e0: 00000000 3fff076c 3ffee5c0 40204636
3ffef5f0: 3ffee71c 0000fff8 0000fff8 4010020c
3ffef600: 00000000 3fff076c 3ffef788 4010068c
3ffef610: 3fff076c 3fff076c 2e333032 402041b4
3ffef620: 00000008 00000000 3ffee5c0 4020319a
3ffef630: 50545448 312e312f 30303220 0d4b4f20
3ffef640: 4341430a 432d4548 52544e4f 203a4c4f
3ffef650: 2d78616d 3d656761 30343638 440a0d30
3ffef660: 3a455441 6e755320 3032202c 766f4e20
3ffef670: 31303220 30302036 3a30303a 47203030
3ffef680: 0a0d544d 3a545845 4f4c0a0d 49544143
3ffef690: 203a4e4f 70747468 322f2f3a 312e3430
3ffef6a0: 322e3534 312e3330 353a3631 31303032
3ffef6b0: 7465732f 782e7075 0a0d6c6d 3a54504f
3ffef6c0: 74682220 2f3a7074 6863732f 73616d65
3ffef6d0: 6e70752e 726f2e70 70752f67 312f706e
3ffef6e0: 222f302f 736e203b 0d31303d 2d31300a
3ffef6f0: 3a534c4e 34343420 44363535 45383034
3ffef700: 0d313037 5245530a 3a524556 736e5520
3ffef710: 69636570 64656966 5055202c 312f506e
3ffef720: 202c302e 70736e55 66696365 0d646569
3ffef730: 3a54530a 6e727520 6c65423a 3a6e696b
3ffef740: 69766564 2a3a6563 550a0d2a 203a4e53
3ffef750: 64697575 636f533a 2d74656b 2d305f31
3ffef760: 35343434 34443635 37453830 3a3a3130
3ffef770: 3a6e7275 6b6c6542 643a6e69 63697665
3ffef780: 2a2a3a65 0a0d0a0d 3fff0000 0000000f
3ffef790: 0000000f 322e3535 313a3035 0d303039
3ffef7a0: 3ffe8858 74cb91cc 3a706473 3ffef7d0
3ffef7b0: 3ffee5d4 00000000 3ffee5c0 40203248
3ffef7d0: 3ffe8858 14cb91cc 3ffe8858 14cb91cc
3ffef7e0: 0000dd3c 3ffef7d0 00000000 00000000
3ffef7f0: 3fff07ec feefeffe 40201c5c 3ffee7fc
3ffef820: feefeffe feefeffe 3ffee810 40100718
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v6000001c

1. Xose Pérez Post author

This is with the fauxmoESP_Basic code crashing? Does it say anything else before the crash?

1. Doug Carr

No, Other than the WIFI connection statement that’s the entire crash dump.

I have tried going back to the GIT version of the ESP8266 Core and get the same crash.

I Googled and Googled and found this which is similar but beyond my programming skills.

If you have any advice I’d greatly appreciate it but for now I’m going to try to get back to
the old version that worked for me.

Again I do thank you for your effort on this.

Doug

19. Doug Carr

Hi,

Yes this is with the sample code. No changes other than the credentials.h file. It will crash just as soon as I tell Alexa to scan for new devices. I crashes and then tries to rejoin the WiFi. It will sometimes find one or two devices though. As I said I’m at a loss here.

I’m at work now and can’t tell you if anything is displayed on the serial monitor before the crash but I will run it tonight and reply.

Doug

20. modmanpaul

First off thank you a million times. I tried to donate a small amount but the paypal is not in english or looks like normal so I might guess fields. can you give me a USA donate link?

So what I am trying to do is have “pin A” turn on for 3 seconds then off when “ON” command is received and “pin B” turn on for 3 seconds and then off when “OFF” command received. I like others have never used a usb-ttl or esp8266 but I got pretty far. I can get the esp-12e onboard led to turn on or off as step one but my research and attempts further are stuck.

thank you for anything you or anyone else here might suggest.
I haven’t coded anything for OFF until I had ON working obviously so its missing from the code below

Here’s my code:

#include
#include
#include
#include
#define SERIAL_BAUDRATE                 115200

fauxmoESP fauxmo;

void wifiSetup() {

// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);

// Connect
Serial.printf("[WIFI] Connecting to %s ", "FiOS-SGVFL");
WiFi.begin("FiOS-SGVFL", "jib7584rows3699tan");
// 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() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
digitalWrite(2, HIGH); //because led seems to work in reverse and we want off to start
// Init serial port and clean garbage
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
Serial.println();

// Wifi
wifiSetup();

// Fauxmo v2.0
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
digitalWrite(2, !state);
delay(3000);                  // waits for 3 second
digitalWrite(2, state);
});

}

void loop() {
// put your main code here, to run repeatedly:
fauxmo.handle();
}

I also tried this code for the pin:

if (state2Val != "ON") {
digitalWrite(2, HIGH);
delay(9000);                  // waits for a second
digitalWrite(2, LOW);
}
if (state2Val != "OFF") {
digitalWrite(2, LOW);
delay(9000);                  // waits for a second
digitalWrite(2, HIGH);
}

with declaring the variable state2Val in the head and making the value match the state with these codes respectively:

char state2Val;

String state2Val = String(state ? "ON" : "OFF");

1. Xose Pérez Post author

Hi
I wasn’t aware the Paypal page was not localised. My bad. I have lost a fortune!!! 🙂
I switched to a different Paypal extension that lets me define the locale and it should be american English now. Please do try again. Thank you!

About your code. First: do not do many things in the callback or it will complain. A long delay like the one you are using is almost always a bad idea (anywhere in the code). There is a handy library called “Ticker” than is included in the Arduino Core for ESP8266 (so you already have it) and it basically lets you defer actions or execute them at a given interval.

First you include it and instantiate the object:

#include <Ticker.h>
Ticker defer;


Next you define you callback methods (the ones you will call after 3 seconds), I’m doing it easy here passing the pin number:

void turnON(int pin) {
digitalWrite(pin, HIGH);
}
void turnOFF(int pin) {
digitalWrite(pin, LOW);
}


And then code inside the fauxmo callback would be like this:

if (state) {
digitalWrite(2, HIGH);
defer.once_ms(3000, turnOFF, 2);
}


Like in your example this is only for pin 2: turning it on when an ON message is received and off after 3000 milliseconds. Note that the pin parameter is passed as the third argument in the once_ms method.
Also note I’ve just written the code here. It’s untested.

Hope it helps!

1. modmanpaul

Paypal worked perfectly thank you. I’m glad to be able to give a what I can considering the contribution you made to people.

The code also worked great. I still had an issue in development of the led not turning back off but then it hit me. For convience I was using the onboaqrd led for developement, but that pin does more than what I want lol. Sure enough when I switched to another pin (12) and an external led setup, all worked perfect.

Sadly my project was to control a device called a vent-miser and I failed to take into account the power requirements of an always on wifi device. It’s a project killer as the idea was to have about 12 vents in my home grouped in alexa smart home device groups and if they sleep all hell will break loose when it comes time to work haha

1. Xose Pérez Post author

Thank you too! It is great to know people give credit to things you do 🙂

Maybe you could use a different approach and sleep them in short intervals. It will be almost real time. Another option would be to use a less power hungry radio device. Check this post about using Moteinos as low power sensors: Moteino Door Monitor.

2. Bill

I’ve used delay before in a sketch to control sprinklers, but found using it with Alexa integration, was a problem. I’d try the sleep function.

21. Bill

It’s been quite awhile since I did any programming with the esp8266, but now that the wemo spoofing is available I’m trying to set up an esp8266-01 to control a 2 channel relay. I did a basic web server that works ok, by pulling pin 0 and 2 low to activate the relays. I can’t figure the correct syntax to do the same in your sketch so I can call to Alexa. I can get Alexa to discover the fauxmo.addDevice(“light one”);
//fauxmo.addDevice(“light two”); but don’t know how to assign, say, “light one” to pin 0, and “light two” to pin 2. Any help would be appreciated.
Thanks,
Bill

1. Xose Pérez Post author

You have to define a callback method that will be called when any of the virtual devices you define is triggered along with the new status. Like this:

fauxmo.addDevice(“light one”);
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
if (device_id == 0) digitalWrite(0, state);
if (device_id == 1) digitalWrite(2, state);
});


So, whenever you say “Alexa, turn light one on” you will receive a message for client_id 0 (first device defined), with status set to true and it will turn on relay in GPIO0 And remember to call fauxmo.handle() in you loop.

1. Xose Pérez Post author

Is it a problem with the device name (sometimes Alexa is a little picky), with the library or with your code?

1. Mike Wils

I’m still doing my triggering from device_name, not from device_id, and it still works. Is there an advantage to using the device_id?

1. Xose Pérez Post author

The only advantage is that is easier to check against an integer than compare C-strings.

1. Mike Wils

Got it. With multiple devices defined, you can use “switch case(device_id) instead of having to use a series of “if strcmp==”. I like it.

2. getsurreal

What about taking a separate parameter to the addDevice that assigns the pin? Then you wouldn’t even need onMessage it could just be handled internally. It could be an overloaded function so you could do it either way in case you needed a more complex callback.

fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
if (device_id == 2) {
digitalWrite(0, state);
}
});

1. Xose Pérez Post author

Yeah, what that would be too specific. What if you want to do something different than toggling a pin?

1. getsurreal

An overloaded function can let you do both. Keeps it simpler for the pin toggle functionality which is more of a true WeMo immulation. But still allows for more complex orchestration if needed.

22. Elliott

Hi Xose

I’m quite a fan of tzapu’s WiFiManager library for creating a captive portal to configure wifi on the ESP. It even has the ability to add additional fields to configure the device name, for example.

I noticed that your fauxmo library requires the ESPAsyncWebServer whereas the WiFiManager uses the ESP8266WebServer. Without knowing too much about how these work I can already tell that they’re incompatible and it’s impossible to have both.

Is there any way I could still use the captive portal system to configure my switches the first time they are powered on? Or is there another method you would recommend? I’d like to be able to change the wifi network they connect to and the device name without cracking my switches open to reprogram them every time.

1. Mike Wils

I have them both working together. The only problem I found, which I thought had something to do with version 2, is that the ip of the 8266 needs to be static and set below .100. This isn’t really a problem to me since I prefer to keep devices like this below the DHCP pool.

23. Mike Wils

I read that there is going to be a WEMO dimmer coming out soon. Hopefully its protocol will fit into an ESP8266.

1. Xose Pérez Post author

Do you mean using Alexa to set different dimming levels? Not at the moment using the Wemo emulation. But Wemo has announced a new Alexa compatible dimming switch, maybe the have implemented it in the same fashion… In the meantime you can use Alexa Skill Kit to achieve that.

1. Mike Wils

I’m anxiously awaiting the dimmer version of the Wemo. Until then, what I’ve done is create a high, medium, and low pwm setting which I step through each time the “on” command comes in. I also created a separate device call “night light” that sets two separately defined devices to a very low brightness setting. It’s all about making do with what you have to work with.

24. ja4test

Hi,

I’m having problems with my echo dot discovering my esp8266.
When I connect both on my home router (arris) Alexa won’t discover my esp8266.
When connected both to my mobile hotspot of my phone (android) it will discover my devises.

What can i do to make my Alexa discover the esp8266 on my home wifi network?

1. Xose Pérez Post author

Could it be that your router is isolating the devices in different networks? Discovery will only work if the devices are in the same network segment.

1. Ryan Sieber

Still no luck. I’m on the same network segment and UPnP is enabled on my router. This is the first home automation device I’ve tried to add to the Echo. I may have to dig out an old router to see if my ISP supplied cable modem/router is the culprit. Are there any other setting other than UPnP which needs to be enabled for discovery to work? I can ping the IP of my FauxMo just fine.

Can’t wait to get into ESPurna!

1. Xose Pérez Post author

Do you have Alexa support enabled in ESPurna? It’s in the “General” menu. Double check it’s ON and save settings. You don’t need any special skill to use it from an Echo and I very much doubt the router is the culprit as long as you are in the same network.

25. Paul J Mcmaster

Sorry I missed your comments. I wish there was comment reply notification (i’m so needy) or maybe there is and I don’t see it.

Anyhow, here’s the code Xose helped me build. all credit to him really once you see it. It works super great with an optoisolator to push ANY buttons with on off commands. I wish I could use open/close or up/down etc. as well but for .71 cents each from aliexpress plus another .10 for the opto-iso you can’t beat it!

#include
#include
#include
#include
#define SERIAL_BAUDRATE                 115200
char state2Val;
fauxmoESP fauxmo;

void wifiSetup() {

// Set WIFI module to STA mode
WiFi.mode(WIFI_STA);

// Connect
Serial.printf("[WIFI] Connecting to %s ", "FiOS-SGVFL");
WiFi.begin("XXXXXXXXXXXXXX", "XXXXXXXXXXXXXXXXXXXXXXXXX");
// 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() {
// put your setup code here, to run once:
pinMode(2, OUTPUT);
digitalWrite(2, HIGH);
// Init serial port and clean garbage
Serial.begin(SERIAL_BAUDRATE);
Serial.println();
Serial.println();

// Wifi
wifiSetup();

// Fauxmo v2.0 vent "open" command
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
String state2Val = String(state ? "ON" : "OFF");
digitalWrite(2, !state);
delay(3000);                  // waits for 3 second
digitalWrite(2, state);
});

}

void loop() {
// put your main code here, to run repeatedly:
fauxmo.handle();
}

1. Xose Pérez Post author

Hi

That 3 seconds delay in the callback is not a good idea. You better set a volatile flag to true there and handle it in the loop with a non-blocking delay.

1. Bill Gillies

This is my actual working code for individual pin control.

    // Fauxmo

fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");
if (device_id == 0) digitalWrite(0, LOW), digitalWrite(2, HIGH);
if (device_id == 0) defer.once_ms(10000, turnOFF, 0);
if (device_id == 1) digitalWrite(2, LOW), digitalWrite(0, HIGH);
if (device_id == 1) defer.once_ms(10000, turnOFF, 2);
if (device_id == 2) digitalWrite(0, HIGH), digitalWrite(2, HIGH);

});

1. Bill

“motor one” turns one way and makes sure the other pin is off.
“motor two” turns the other way and makes sure the other pin is off.
“motor three” stops the motor.
the timing is set for ten seconds, needs to be custom set for individual purposes.

26. Bill

I’m stumped, anyone have an idea how to turn pins on and off in sequence? Example
digitalWrite(led1, LOW), digitalWrite(led2, HIGH);
defer.once_ms(10000, turnOFF, led1);
if (led1= HIGH), digitalWriter(led2, LOW)

Thanks,
Bill

1. Xose Pérez Post author

The code has some typos and it’s hard to know what you are trying to do. What does “in sequence” mean?

1. Bill

thanks for the response Xose, What I’m trying to do is get led1 to turns on for a time, then turn off, when it turns off led 2 turns on for a time then turns off.

1. Xose Pérez Post author

This should do: every 10 seconds the relays will flip.

 #include Ticker flipper; bool state = false; void flip() { state = !state; digitalWrite(LED1, state); digitalWrite(LED2, !state); } void setup() { pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); flip(); flipper.attach(10, flip); } void loop() { } 

1. Bill

got code working in the fauxmo code, now to start with both pins off, and end with both pins off. I use filpper.once(10, flip); which works for turning on two devices in sequence but program starts with one pin on (LOW in my case) and ends with other pin on. the “state=false;” doesn’t compile, I get ‘state’ does not name a type error. Any advice would be appreciated.

2. Xose Pérez Post author

Obviously there was a “bool” missing before that sentence. I have updated my previous comment.

3. Bill

thanks Xose, I did that but it doesn’t seem to change the way the program acts. What I’m trying to do is start the program with both pins off, then with the call to “turn on test one”, led 4 turns on for 10 sec. then off, then led 5 turns on for 10 sec. then off. then stop untill my next call to “turn on test one” Here’s my code
for now.

#include

fauxmoESP fauxmo;
bool state = false;

void flip()

{

state = !state;
digitalWrite(4, state);
digitalWrite(5, !state);

}

// -----------------------------------------------------------------------------
// 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();

// Wifi
wifiSetup();

//LED
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);

pinMode(5, OUTPUT);
digitalWrite(5, HIGH);

flip();

// Fauxmo

fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF");

if (device_id == 0) flipper.once(10, flip);

});

}

void loop() {

fauxmo.handle();

}

4. Xose Pérez Post author

Mmmm… first set the pin4 in the fauxmo callback and defer action:

if (device == 0) {
digitalWrite(4, HIGH);
flipper.once(10, flip);
}


The in the “flip” method check your state and do accordingly:

function flip() {
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
flipper.once(10, flip);
} else {
digitalWrite(5, LOW);
}
}

27. Mike Wils

I tried these 3.3 volt switching regulators I found on Ebay. http://www.ebay.com/itm/281678046714. They work perfectly with the 8266. The only additional capacitor I used was a .1uF across the VCC and GND pins of the 8266.
I paid for the expedited shipping and got them in 2 weeks to New York. It came to less than \$10 for 4 of them. Definitely a good deal.
For anyone making LED dimmers I found the Fairchild FDP6030BL mosfet works with 3.3 volts directly without a need for a level shifting interface.

28. Steve C

Hi everyone,

Is anyone else experiencing problems with the FauxMo ESP8266 library right now? I’ve had code running since December last year perfectly, yet over the last 5 days or so it’s suddenly stopped functioning.

I think fauxmo.addDevice(…); call is failing since my echo is showing all devices as offline and won’t rediscover them. I can say from the debug messages that the ESP is definitely connecting to my LAN okay.

Has anyone else experience problems of late, alternatively does anyone have this working as of today (20th March)? For what it’s worth my echo is on version 5264 and I have a genuine WeMo device on my network that is still operating just fine.

1. Xose Pérez Post author

I have several devices using ESPurna with the fauxmoESP library and they are working just fine…
You could try compiling your code with the “-DDEBUG_FAXUMO=Serial“ flag set to monitor debug messages from the library in the debug console.

29. Markus

Is there a way to control the ESP8266 also via the Belkin WeMo app or via GET-parameters?

Cheers!

1. Xose Pérez Post author

I’m not aware of a wemo emulation that works with the wemo app. But you can flash my ESPurna firmware that integrates the fauxmoESP library and supports REST-like requests too.

30. Brian T Mickley

I am using the fauxmoESP library to control two relays via the Amazon Echo Dot. This is working fine. Thanks!

Relays are named ‘Lamp 1’ and ‘Lamp 2’. The ‘Alexa, turn ON/OFF Lamp 1/2’ command works fine.

Next I added a third ‘device’ which I called ‘ALERT DAD’ (for my handicapped and bedridden mother to beckon my father when she is in distress). The ‘ALERT DAD’ device is recognized by the Echo Dot and controls the proper GPIO pin successfully.

PROBLEM HERE: I’m having trouble creating a loop when the ‘ALERT DAD’ name is recognized by Echo Alexa. I would like the code to rapidly cycle the GPIO from HIGH to LOW with a delay between cycles. Basically, the BLINK routine.

I have tried every way I know to get a successful blinking of one relay – without any luck.

1. Xose Pérez Post author

It would be good to see the code but if you are trying to add the loop inside the fauxmo callback you’d probably run into problems like the one you describe.
Maybe you can try using the Ticker library to set a recurring timer to a toggle function, something like this (caution: untested):

#include <Ticker.h>

#define LED_PIN 4

static unsigned char count = 0;
count = (count + 1) % NOTIFICATION_TIMES;
}

function setup() {
...
fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) {
...
...
});
...
}

31. Kenny

Hi Xose, I’ve flashed a sonoff with your code, and alexa can turn it off and on, which is great. The button on the sonoff no longer turns the device on or off. I have tried to reflash with another firmware, but since installing this one, I get errors when attempting an upload. Do you know how I can solve this? Many thanks.The error is espcom_open failed.

1. Xose Pérez Post author

That’s weird. The button in the Sonoff (assuming it’s a Sonoff basic or TH, not a TH10 or TH16) is tied to GPIO0. Most sonoffs use GPIO0 for the button since it doubles as flash mode setter. You just have to power the board while pressing the button. The error you are getting is probably due to the board not being in flash mode but you said you already flashed it once so I guess you know how to do it…

32. Shane

Any chance we can use different state commands? Open/close rather than on/off?

1. Xose Pérez Post author

You would have to write a custom skill for that. The Wemo devices only accept ON/OFF at the moment.

33. Tom K.

Hi Xose,

Great that you have this page up for us all. I have my Alexa controlling 3 lights, a ceiling fan, and my garage door thanks to you.

The ESP’s that control the lights are installed inside the switch box where the light switch would normally go and I set up a button to control the light as well.

I do have one problem I’ve run in to so far. If my wireless router is not active when I power up the ESP they never connect up unless I power cycle them. This is a real pain because my router is on the same breaker as the devices that are in the wall now, not easy to get to to power cycle them.

I’m not sure if the wireless connect is not looping correctly to keep trying to find the wireless router or if the code is locking up. To get around it for now I just powered my router from a different plug using an extension cord.

1. Xose Pérez Post author

Thanks! The device should try (re-)connecting to a defined SSID after 2 minutes (that’s the WIFI_RECONNECT_INTERVAL in the general.h file). Those two minutes should give room enough to connect to the AP point it creats when it fails to connect to the router and change the WIFI configuration (this is important if you have mistyped the password or SSID in the WIFI configuration page, for instance).

34. Bill Webb

ESP worked flawlessly form the first installation for me, until last night. Suddenly my commands were ignored. I rebooted the ESP many times and finally reloaded the program. Still no luck. It connects to my network just fine. I did a forget and now the ESP devices will not discover. Free heap remains a 40368. Could something have changed on the “Wemo” end to lock out these DYI devices? I really have no ideas on how to troubleshoot this further.

1. Xose Pérez Post author

I have no evidence they had changed anything. Have you tried running a discovery process again? Is Alexa support enabled in the device?

1. zanechua

Same thing is happening to me. Might wanna add a note so that this doesn’t happen to everyone. I am not really sure why they are refusing to pick up the existing devices though.. Something weird is going on here.

35. Bill Webb

Yes, I tried all of the above without success. Eventually by mindless fiddling, I discovered that the problem was my Cable Modem / Router had suddenly decided to block UPnP. It is under the control of my ISP so there is a limit to what settings I can change even as administrator. I discoved that UPnP was not blocked for the first few minutes after a reboot of the router. Doing discovery in that small window works.

I have no idea why Time Warner / Spectrum suddenly started blocking UPnP and there is little chance of finding out.

1. Xose Pérez Post author

Yeah, that’s why I like to flash custom firmware on my devices… to really own them.

36. Jake K

I’m absolutely loving this project! Already rigged it up to a few light sources around the house, but I’ve got a project for someone else, where I need it to just output a short trigger over a transistor (350 ms or so), otherwise it’ll just hold it to go and stop over the course of the time of the “light” being on.

Is there any way to put this in a sequence for the ESP to handle after just sending an “Alexa, turn X on”?
I’ve already tried several scenarios, and I only seem to make it output a toggle instead of a trigger.

1. Xose Pérez Post author

You can use the ticker library to defer an action for 350ms. You can then switch it on, set the defer (once_ms method) and switch it off in the callback.

37. Ryan Sieber

Very cool and useful project. I’m having trouble discovering my FauxMo device though. I’ve tried both the Alexa app and http://alexa.amazon.com/spa/index.html#appliances

I assume I must enable the Alexa WeMo Smart Home Skill before the FauxMo will be discoverable?

“Enable smart home skills to control devices with Alexa. If you’ve already enabled your skill, discover devices below.”

I’ve tried enabling the WeMo skill but Amazon tries to link accounts with WeMo and requests my SSID and the MAC address of the WeMo before continuing.

Has the loophole been closed or is there a workaround?

1. Jonathan Littlejohn

I’m having the same issue as Ryan.

The libraries look fantastic, but I can’t discover my device…

Code compiles fine, all the libraries are the latest, I can see my device on the network and ping it, but I can’t discover it? Serial port debug show the device connected to the network and the “free heap” ticker is ticking away..

I really love this project and concept. Anyone have a work around for this yet?

1. Xose Pérez Post author

Are you using any of the sample code or your own? You have to call “handle” method in you loop for it to work.

If you still don’t know what’s going on or you think it’s a bug please file an issue on bitbucket. Thank you.

1. Jonathan Littlejohn

I am just using the sample code. I didn’t modify anything.

I don’t believe this is a bug with your code, I believe this is an issue with the amazon app, possibly due to an update? Not sure.

I haven’t had a ton of time for this, but after a bit of fiddling, I’ve tried/discovered the following:

I bought an legitimate WeMo device (light switch) so that I could install the skill. This may or may not have been necessary, but I needed one anyway. After installing the skill I still couldn’t see the devices when scanning through the Alexa app.

it turns out that the Alexa device CAN see the units, I just can’t see them in the Alexa App on my phone. I.e. if I ask “Alexa, scan for automation devices”, it correctly identifies the unit and I can control then through voice. However I still can’t see them on my app and the app still can’t see them when it scans.

After discovering them through using an Alexa voice command I can see them through https://alexa.amazon.com/spa/index.html#appliances, just not through the app.

Anyway, good enough for me. I can control them, just not through the app (oh well). Not sure why.

Automated sprinklers here I come…

Thanks again. This project rocks!

Jon

38. daniel gaitan

First of all, thank you Xosue for sharing your work, vizca catalunia !!
this is my code for a esp8266-01, with one button for toggle, and also a webpage with websockets, so you can control the led state (or relay, etc etc) in three way: Alexa, toogle button and webpage
sorry for any mistakes I made, I an a newbie in the micro controllers world .
it is a collection of pieces of code from different coders over the internet, and it is now well documented or commented by my, but i hope it will help to somebody

https://gist.github.com/anonymous/ac1e8194b292b1f5048e1e9a2ece9707

39. zoomx

Maybe there is an error in the Bitbucket repository Overview page

In usage sketch
void loop() {
fauxmoESP.handle();
}

should be

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

40. developer411blog

Hey Xose. have you had any compatibility issue using your library along with MQTT? I have your library working on one of my ESP-12e modules, along with a relay that get’s triggered when the ESP receives a message. I wanted to publish the state of the relay to an instance of OpenHAB, so added in the Adafruit MQTT library. The problem is, when I tell Alexa to send the ON/OFF command to the device, as soon as I publish the state, the ESP reboots. I’m doubtful that there is an incompatibility here, but thought I’d ask while I have a night off coding. I think it may be a memory issue.

My code is below:
 #include #include #include "Adafruit_MQTT.h" #include "Adafruit_MQTT_Client.h" #include "fauxmoESP.h" #include "credentials.h"

 #define SERIAL_BAUDRATE 115200 #define SWITCH_GPIO 5 // Set up Fauxmo and WiFi fauxmoESP fauxmo; WiFiClient client; // Set up MQTT client const char *client_id = "ESP-01"; Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, MQTT_PORT, client_id, MQTT_USER, MQTT_PASS); // Set up MQTT publisher const char *pub_topic = "/hab/sockets/1"; Adafruit_MQTT_Publish hab_sockets_1 = Adafruit_MQTT_Publish(&mqtt, pub_topic); // Set up MQTT subscriber const char *sub_topic = "/hab/sockets/1/extern"; Adafruit_MQTT_Subscribe hab_socket_1_extern = Adafruit_MQTT_Subscribe(&mqtt, sub_topic); // forward decl void MQTT_Connect(); /** * wifiSetup * Configure WiFi module to network */ 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()); } /** * Setup program logic and states */ void setup() { // Init serial port and clean garbage Serial.begin(SERIAL_BAUDRATE); Serial.println(); Serial.println(); // Wifi wifiSetup(); // Switch output pinMode(SWITCH_GPIO, OUTPUT); digitalWrite(SWITCH_GPIO, HIGH); // Start WeMo listening fauxmo.enable(true); // Add WeMo device char UDN[15]; unsigned char device_1 = fauxmo.addDevice("socket one"); sprintf(UDN, "444556%06X%02X\0", ESP.getChipId(), device_1); // "DEV" + CHIPID + DEV_ID Serial.printf("[MAIN] Created device with UDN Socket-1_0-%s\n", UDN); // On message from Alexa, change and publish device state fauxmo.onMessage([](unsigned char device_id, const char * device_name, bool state) { Serial.printf("[MAIN] Device #%d (%s) state: %s\n", device_id, device_name, state ? "ON" : "OFF"); digitalWrite(SWITCH_GPIO, !state); // Publish state change to MQTT broker const char *msg = ("State changed to %s", state ? "ON" : "OFF"); bool published = hab_sockets_1.publish(msg); if (!published) { Serial.println("Failed to publish SWITCH_GPIO state"); } }); // Set up subscriber mqtt.subscribe(&hab_socket_1_extern); } /** * Main loop, to listen and keep everything alive */ void loop() { // Poll for UDP packets fauxmo.handle(); // Maintain MQTT broker connectivity MQTT_Connect(); // Check for MQTT subscription messages Adafruit_MQTT_Subscribe *subscription; while ((subscription = mqtt.readSubscription(3000))) { if (subscription == &hab_socket_1_extern) { if (strcmp((char *)hab_socket_1_extern.lastread, "ON") == 0) { digitalWrite(SWITCH_GPIO, LOW); } else if (strcmp((char *)hab_socket_1_extern.lastread, "OFF") == 0) { digitalWrite(SWITCH_GPIO, HIGH); } else { Serial.println((char *)hab_socket_1_extern.lastread); } } else { Serial.println("Unknown subscription, ignoring!"); } } // If we cannot ping the MQTT broker, call disconnect so we free up out client ID if (!mqtt.ping()) { mqtt.disconnect(); } // Simple heartbeat message static unsigned long last = millis(); if (millis() - last > 5000) { last = millis(); Serial.printf("[MAIN] Free heap: %d bytes\n", ESP.getFreeHeap()); } } /** * Connect to the MQTT broker */ void MQTT_Connect() { int8_t ret; // connection return code (can be negative) uint8_t retries = 3; // retry counter uint8_t retry_interval = 5; // time is secs to retry // Stop if already connected. if (mqtt.connected()) { return; } Serial.printf("Connecting to MQTT as %s... ", client_id); // If we fail to connect to the MQTT broker 3 times in a row, we'll // reboot the device while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected // Notify state Serial.println(mqtt.connectErrorString(ret)); Serial.printf("Retrying MQTT connection in %d seconds...", retry_interval); Serial.println(); // Retrying mqtt.disconnect(); delay(retry_interval * 1000); retries --; 

 if (retries == 0) { // basically die and wait for WDT to reset me while (1); } } Serial.println("MQTT Connected!"); } 

1. Xose Pérez Post author

I have lot of devices running fauxmoESP with PubSubClient or AsyncMqttClient without problems. Try not to add too many things in the fauxmo callback. The callback should exit as fast as possible. Set a flag (a boolean) and do the publish stuff in the main loop.

41. dans

Hi,

Great work here, trying to get it to work with my Alexa not happening.

I am using 2.4.0-rc1 version with an earlier version of ESpasyncTCP and all compiles fine but does not get detectected by Alexa. If I update the ESpasyncTCP library to the latest version compile errors are encountered. I am running this on a nodemcu v3 board.

Any ideas or recommendation.

Big thanks

Dans

1. Xose Pérez Post author

Can you monitor the debug log to see what’s going on? There was an issue on the 2.2.0 fauxmoESP library with the latest Alexa firmware update. I recommend you to update to 2.2.1 and try again.
Also, if you are using 2.4.0-RC2 (the latests available) you should checkout [email protected] (latest at the moment, actually a PR by me :). But it should work with 2.3.0 (stable) using [email protected] from Sept 11th.

42. dans

Fixed,

Downloaded earlier version of ESPasyncTCP library all up and operational awesome stuff.

Is there a way to send Alexa a voice message to speek? this would be awesome for alerting of sensor status around my house etc.

I am adding MQTT to my program so that Alexa controls my devices dependent on message command received. So far I have 12 devices within the sketch recognized pretty awesome.

Brilliant work you are a hero.

Dans

1. Xose Pérez Post author

Well, thank you (blush). AFAIK the Alexa device must begin the communication, so there is no way to “send” a text to speak to Alexa unless the device asks for it first.

1. Xose Pérez Post author

The library emulates the communication protocol between an Alexa device and a WeMo switch. At the moment I don’t know the way a wemo dimmer works, so it’s not supported.

43. dans

Xose,

Where do you configure the device name that connects to Alexa or do you leave it as is?

Trying to get an idea of how many different ESP8266 devices I could add this implementation in to and have connected to my network.

From what I gather you should not have more than 8 devices added under a single Fauxmo instance.
Could you clarify this buddy.

I now have MQTT implemented and can tell Alexa to turn on my Neo pixels or garden landscape lights through voice to MQTT control. Pretty awesome, looking to see how far I can push this.

Big thanks

Dans

1. Xose Pérez Post author

I have tested it with up to 16 devices without issue. You can define the name in the addDevice method, but I normally create aliases from the alexa web app.

44. Sinisa

Pleas help, i have this error when compiling.

Build options changed, rebuilding all
In file included from C:\Users\Sinisa\Desktop\NodeMCU\dot\dot.ino\dot.ino.ino:1:0:

C:\Users\Sinisa\Documents\Arduino\libraries\xoseperez-fauxmoesp-54c90baec1fb\src/fauxmoESP.h:113:9: error: ‘WiFiEventHandler’ does not name a type

WiFiEventHandler _handler;

^

Multiple libraries were found for “WiFiUdp.h”
Used: C:\Users\Sinisa\Documents\Arduino\libraries\WiFi
Not used: C:\Users\Sinisa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\Sinisa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\Sinisa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
Not used: C:\Users\Sinisa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.4.0-rc2\libraries\ESP8266WiFi
Not used: C:\Program Files (x86)\Arduino\libraries\WiFi
exit status 1
Error compiling for board WeMos D1 R2 & mini.

1. Xose Pérez Post author

Mmm… Looks like your Arduino IDE is puzzled by different instances of the WifiUDP library and it’s using the wrong one…

45. Ben

Hi Interesting code. However i followed your install steps but seem to be getting a whole load of compile time errors from the ESPAsyncTCP library you linked to.

Any ideas ?

sample errors:

Arduino: 1.8.5 (Windows 10), Board: “Generic ESP8266 Module, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck, Disabled, None”

C:\Users\Admin\Documents\Arduino\libraries\ESPAsyncTCP-master\src\ESPAsyncTCP.cpp:78:28: error: invalid conversion from ‘long int (*)(void*, tcp_pcb*, pbuf*, long int)’ to ‘tcp_recv_fn {aka signed char (*)(void*, tcp_pcb*, pbuf*, signed char)}’ [-fpermissive]

tcp_recv(_pcb, &_s_recv);

^

C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/lwip/include/lwip/tcp.h:318:18: error: initializing argument 2 of ‘void tcp_recv(tcp_pcb*, tcp_recv_fn)’ [-fpermissive]

void tcp_recv (struct tcp_pcb *pcb, tcp_recv_fn recv) ICACHE_FLASH_ATTR;

^

C:\Users\Admin\Documents\Arduino\libraries\ESPAsyncTCP-master\src\ESPAsyncTCP.cpp:79:28: error: invalid conversion from ‘long int (*)(void*, tcp_pcb*, uint16_t) {aka long int (*)(void*, tcp_pcb*, short unsigned int)}’ to ‘tcp_sent_fn {aka signed char (*)(void*, tcp_pcb*, short unsigned int)}’ [-fpermissive]

tcp_sent(_pcb, &_s_sent);

^

C:\Users\Admin\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0/tools/sdk/lwip/include/lwip/tcp.h:319:18: error: initializing argument 2 of ‘void tcp_sent(tcp_pcb*, tcp_sent_fn)’ [-fpermissive]

void tcp_sent (struct tcp_pcb *pcb, tcp_sent_fn sent)ICACHE_FLASH_ATTR;

^

46. Kaushik Ray

Is it possible to send different commands to the same device other than just on and off ?
I am trying to make a RGB led controller using voice command but I need something more than just on and off. Please let me know if it is possible.

I really appreciate the great work.

Thank you

47. Amit Dogra

Great work! Does this work on Amazon Echo Plus? I made few attempts but my Echo Plus device doesn’t discover any new smart home device. I am using a NodeMCU. Any guidance is much appreciated.
Thanks,
Amit

1. Ralf Jahns

If anybody in the world searches the internet for “how to build something that can be controlled by Amazon Echo”, he will probably find fauxmoESP. Almost all instructions I found, rely on this project. But now it is dead. Not working any more. What a pity.
This should be no criticism in any way. You developed something great and you shared it. Thank you for that. Do you have any recommendation for an alternative?

1. Xose Pérez Post author

I have moved to control my devices using Alexa from Node-RED. It gives me more options (including an anlog value so I can control the brightness). The problem with fauxmoESP is that, apparently, the way the new Echo devices talk to the Wemos have changed and it has not been reverse engineered yet. I don’t own any second generation Echo so it’s really hard for me to test it 🙂

48. Stephen Mann

Possible bug?
FauxmoESP has really been a delight to work with, and it’s running on one of the tiny esp8266-01 modules. I have ten esp8266 nodes including a few Sonoff Switches in my home network. I have written the code for every node, so if the problem is on my end, it will be easy to fix. I also use Node-red on a Raspberry Pi to control my nodes.

Here’s my issue. When I tell Alexa to discover my nodes, many of them turn on. A minor inconvenience except that I often work well into the AM hours while my wife sleeps. If I add a node and tell Alexa to discover, then the light in the bedroom is one of the nodes that turns on.

Have you seen this?

1. Xose Pérez Post author

Are you using the latest version of the library? This bug was fixed with 2.2.1

49. mukeshtalks

Hello Perez,
I tried to emulate Wemo device usinf fauxmo library. But when i am trying to discover the device using alexa nothing is listed there. I am getting below message on serial consol of ESP8266
HTTP/1.1 200 OK
CACHE-CONTROL: max-age=86400
DATE: Mon, 22 Jun 2015 17:24:01 GMT
EXT:
LOCATION: http://192.168.0.100:52001/setup.xml
OPT: “http://schemas.upnp.org/upnp/1/0/”; ns=01
01-NLS: 44455618975B01
SERVER: Unspecified, UPnP/1.0, Unspecified
X-User-Agent: redsonic
ST: urn:Belkin:service:basicevent:1
USN: uuid:Socket-1_0-44455618975B01::urn:Belkin:service:basicevent:1

I there anything i need to change in my router or i need to change any IP address or need any cloud connectivity. I am trying this in India.

1. Xose Pérez Post author

What kind of Alexa device do you have. New v2 devices are not compatible (yet).

1. Xose Pérez Post author

Yes, looks like the protocol changed from v1 to v2. Unfortunately I don’t own any v2 device so I cannot test it at the moment. There is an open issue on bitbucket about this.

50. Thomas J.

I also have an Echo Plus here and it works fine with fauxmoESP. On my first connect there was a similar output on serial monitor as shown by mukeshtalk, but on second time it works fine. So I dont think there is a problem with v2. If i should test somethink, please feel free to ask.

Best regards

1. Xose Pérez Post author

There is an open issue on Bitbucket about this. Please report there. Unfortunately I have no chance to test on new v2 devices so I’m somewhat blind here.

51. Chris

@Dave Meyers

Hi there, you were looking for the same solution that I’am looking for now…..did you ever find it? I have loads of RF controllers that I want to control with an ESP8266 nd RF transmitter, any help greatfully received!

you said:
The only reason I can think of for a higher number of devices (and actually an idea I’m working on implementing) is a 433MHz remote outlet WeMo bridge. Ie, wemo like control over (much) cheaper 433MHz outlets. Since the ESP module won’t be constrained by gpio pins (as it will only be connected to a 433 transmitter), the number of outlets for individual control is only limited by range and the number of outlets allowed by the RF protocol.

Thanx and regards
Chris

52. Paul Gregory

Hi there please forgive my lack of knowledge in this area but I have been playing with the fauxmoESP code and controlling a 4 channel relay via Alexa the code I have been using involves hard coding my SSID details but from what I gather your code does not need your SSID is that right. Thankyou

1. Xose Pérez Post author

I usually create a separate file for “personal” data, normally “credentials.h”. I don’t add that file to the repository, instead I add a “credentials.h.sample” or similar that is a template for you to create your own. Just duplicate the file, rename the duplicate to “credentials.h”, edit it and change the data inside to match you network.

1. Paul Gregory

Ok I see, I was hoping there was a way to send your wifi details to the NodeMCU from an app similar to the way you do with a commercial wifi plug or device.

1. Xose Pérez Post author

The firmware has options to allow remote configuration but there is no such app. In the close future I plan to add WPS.

53. Bruce

Hi Xose – I found my way here after purchasing the adafruit feather Huzzah board with the ESP8266 as I wanted to control the board using Alexa. After weeks of hair pulling it appears that “something fuzzy” has happened with Alexa and all the ESP8266 examples have stopped working as no one can get the Alexa app to recognize the ESP8266 boards. Can you give me an update on what has happened and if there is a confirmed work-around yet?

54. Dalton Hall

Is fauxmo still working with first gen Alexa? I can not seam to get it to work, but I may be doing something wrong getting it set up on my Sonoff. All I want is to have GPIO14 switch the Sonoff when grounded and Alexa to also be able to switch on and off, but cannot figure that out. I have Tasmota on it now and GPIO14 works, but cannot figure how to add fauxmo to it.

1. Xose Pérez Post author

It should. But TBH I don’t use it anymore, moved the logic to Node-RED.

55. PAULO RAPOSO

Dear Mr. Xose Perez,

I´d like please request your help, using your Emulate a WeMo device with ESP8266 project to control 24 diferents switchs. (relays). I was studing some possibilities, the first one is to use 3x esp8266 (each 8266 has 8 digital port/each), but my problem is how does Alexa will understand relay 01…24 (turn on -off ?). The second we will use only one ESP8266 (4 IOs digital port) triggering decoders and they would act on the relays like (74HC238), but my problem is to configure all devices and alexa also. Have you some ideia ? Could you help me ? Informe me the books and sites that we may connect the exemples of codes to configure these one and two possibilities. Thanks in advanced. Paulo

1. Xose Pérez Post author

Both options are possible. But you will have to do some manual mapping. Using some I/O expander and creating specific names for each device is very feasible.

I used the code given in the post but Alexa is not finding any devices. ESP8266 is connected to WiFi and got the IP as well. I am using DLink router which assigns static IP (192.168..) to devices on network, could that be an issue here?

1. Xose Pérez Post author

Try enabling the DEBUG_FAUXMO to Serial when compiling to get a debug log, then execute the discovery process again, you should be seeing the broadcasted messages and responses.

57. Kim Nyholm

Alexa (dot g3) is also not finding devices. When I try a Sonoff s20 with Espurna sha b0e6048a8e72f8f771acca891ca69a32fc3d1605 (1.13.3) she says: “I couldn’t find any new smart home devices. If you have Philips hue press the button on bridge and rerun discovery.”
When I enable DEBUG_FAUXMO I get the following in the terminal:

[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Responding to M-SEARCH request
[FAUXMO] Client #0 connected
[FAUXMO] Handling /description.xml request
[FAUXMO] Client #0 disconnected
[083921] [WEBSERVER] Request: POST /api
[083922] [WEBSERVER] Missing apikey parameter
[088942] [WEBSERVER] Request: POST /api
[088942] [WEBSERVER] Missing apikey parameter
[093969] [WEBSERVER] Request: POST /api
[093970] [WEBSERVER] Missing apikey parameter

Any clue what I am missing?

1. Xose Pérez Post author

I’m aware of the issue. There are working scenarios but I still have to document them properly.

This site uses Akismet to reduce spam. Learn how your comment data is processed.