Aircoookie / Espalexa

Alexa voice control for ESP8266/ESP32 (including brightness and color!)
MIT License
541 stars 134 forks source link

Echo Dot v2 won't find Espalexa #47

Open PyxelFox opened 5 years ago

PyxelFox commented 5 years ago

So I searched for a way to control my ESPs with an Alexa device, but as I wanted to try this out my Alexa just couldn't find my device. To be clear, it is an Wemos D1 mini "knock-off", so an esp8266 combined with an Alexa Echo Dot v2. Hear is the output of the ESP after trying to find it 3 times:

Connecting to WiFi Connecting..... Connected to Fuchsbau IP address: 192.168.188.32 Constructing device 1 Adding device 1 Espalexa Begin... MAXDEVICES 1 Done

And yes it is connected (output of /espalexa):

Hello from Espalexa!

Value of device 1 (TestLight): 0

Free Heap: 46352 Uptime: 1213997

Espalexa library v2.3.3 by Christian Schwinne 2019

I used the recent version of the library and the esp core v2.5.0. Both devices are defenitely on the same network.

The sketch is the same as the example color sketch, I just changed the ssid and password.

Aircoookie commented 5 years ago

Thank you for the report! I'm going to investigate this. Did you try the discovery via voice command or via the app? (there might be a difference). Just now I quickly tried to reproduce your issue (I hadn't tried core 2.5.0 before), but there are no discovery issues for me, everything working fine. During the discovery, some Got UDP! M-SEARCH packets should show up in the debug serial. If they don't, it is likely that your Echo is not sending them for some reason. Please try disconnecting the Echo from power, and after the reboot, retry the discovery via the app (Add Device ->Philips Hue -> Discover). I hope I'll be able to get the library working for you!

PyxelFox commented 5 years ago

Actually I tried both methods multiple times now and some other cores. My echo doesn't seem to send packets at all. Just now I tried to search for a Philips Hue Device but it won't find it either... Well whitch of the 3 given options should I use when trying to find a philips hue device?

Aircoookie commented 5 years ago

That is slightly worrying. I've never before heard of the Echo not sending any discovery packets at all. What 3 options do you mean? For me it works in the app if I go to Devices (bottom right corner), then click the + icon in the top right, click the hue icon and finally the blue discover devices button. There recently was a big overhaul of the Alexa app design (at least for Android), I don't remember the steps in the old version, but it was similar. If you feel confident using the program Wireshark, you could run that and set the filter to ssdp packets. If you then see some M-SEARCH packets, you know the Echo and network is working correctly. If you see none, you know it's either the Echo's or your network configuration's fault. If you don't want to install Wireshark, that's not a problem :)

PyxelFox commented 5 years ago

screenshot_amazon_alexa_20190207-185922

Basically my app looks like this after clicking the hue button, it is in german so I will translate it:

Title: Whitch type of Hue-Bridge are you using? Options: (I guess you can tell) last one is if I don't have a hub

I will look into wireshark, maybe it will help some others or you if there is some wierd issue. I Have to admit, my alexa always seems a bit unrelyable when it comes to connecting anything with it, maybe it is just broken or something, idk.

Aircoookie commented 5 years ago

Well that is interesting, I've never seen that screen before (maybe it is because I already connected an actual hue bridge to Alexa). Try selecting "Philips Hue V1 bridge (rund)", that's the one Espalexa is emulating. If it asks for a login, try to skip it or go back. If that doesn't work, try to select All Devices -> Light -> Other (scroll all the way down) and then discover.

Thanks for giving Wireshark a try! By the way, I am German as well, so no worries! I am only replying in English should other users need reference :)

PyxelFox commented 5 years ago

Yeah, that doesn't work either. I actually wanted to get a hue-bridge and some lights but to be honest, it is a bit expensive for me as a student. So I build my own "bridge" (so I can add my own effects and stuff) with a raspberry running a "json server" which interacts with the esps and mobile app I wrote for it by exchanging json strings. That works fine and all, but I really want to connect it to my alexa so I can kind of control the lights with my voice. Since the canFullfill stuff of the alexa skill api only works in the US I have to use something like this.

I could tell by our name in the credits of the /espalexa page but, yeah, not everyone understands german I guess :D

Gonna play around with wireshark since I never used it before.

Aircoookie commented 5 years ago

That JSON server and app stuff you did sounds super interesting! Have you heard of WS2812B light strips? I have a full ESP software for those, including almost 80 effects! http://wled.me (also supports Alexa, but I would be surprised if it worked for you, since it's based on Espalexa)

PyxelFox commented 5 years ago

I'm actually using those strips. I know about this software of yours, have seen it like literally 5 minutes after finding your post here. It would be a surprise if this works, but I guess I could give it a try.

Since I like adding my own effects, just like setting up a JSON client on a raspberry 3 connected to a usb sound card with stereo line in for a stereo vu-meter under my tv. Looks super awesome.

The app actually just requests informations about all lights in the system, including scenes and rooms, just like hue and sends value change requests back. It is very simple though.

Maybe I could look into your code and use some of it later for my raspberry running the vu-meter (writen in python) if you won't mind.

PyxelFox commented 5 years ago

So I gave wireshark a try and was able to find the packets you mentioned. Wireshark shows me some M-SEARCH packets coming from my router and my pcs ip address while alexa is searching for devices. The esp running espalexa still won't see them though.

Mhh, while I am thinking about it... shouldn't come the M-SEARCH packets from alexa itself so I would see the ip address of my alexa?

What is odd as well is, I can't access the setting of my alexa via the app, something isn't right here.

Aircoookie commented 5 years ago

Yes, the M-SEARCH packets should be send by the Echo itself. Packets being send by the router or PC are not uncommon either, but they should also appear if you are not discovering devices. Also the espalexa debug log should still print out those packets... So I still don't know if this is your Echo's, network's or Espalexas fault. However, the fact that you can't access the device settings propably means there is something wrong with the Alexa software somehow...

eos1d3 commented 5 years ago

I read from faumoESP before Echo dot gen 2 or 3, the port being used is not 80. Can this be the problem?

PyxelFox commented 5 years ago

So I reset my alexa and did the setup again and can now see the M-SEARCH packets in wireshark. But the debug log of espalexa still stays the same, nothing changed.

PyxelFox commented 5 years ago

So to check if another device also receives the packages I setup a UDP Multicast client on my raspberry pi and got some results which looked like this: b'M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 15\r\nST:urn:Belkin:device:**\r\n\r\n' b'M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 15\r\nST:urn:Belkin:device:**\r\n\r\n' b'M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 15\r\nST:urn:schemas-upnp-org:device:basic:1\r\n\r\n' b'M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: "ssdp:discover"\r\nMX: 15\r\nST:urn:schemas-upnp-org:device:basic:1\r\n\r\n'

Aircoookie commented 5 years ago

Thank you! Those packets are definitely valid and should be received by Espalexa without issues...

@eos1d3 had a similar issue with the phone on 5Ghz, so try to connect your phone to a 2.4Ghz WiFi if possible (Alexa on 2.4Ghz is worth a try as well) Sorry for all the trouble!

PyxelFox commented 5 years ago

I am currently porting your lib to python so I can use it on my raspberry pi, which runs the server anyway and could handle all light (what it does at the moment anyways) commands from alexa.

Also I am looking into the problem a bit further and try to find some issues or something.

eos1d3 commented 5 years ago

@Aircoookie I tried these:

Phone on 5GHz or 2.4GHz, Alexa on 5GHz or 2.4GHz Router: Asus AC-86U Discovery on PC with Ethernet, or phone on 5GHz or 2.4Gz

Any above combinations work. Sometimes need to reset ESP module after network change. This says I never find a combination which does not work.

PyxelFox commented 5 years ago

@Aircoookie So as I'm trying to port this over to python I came across a problem while testing... After alexa sends a M-SEARCH packet the library responds with something like this, right? image

So what should Alexa send out after this? I'm not receiving any packets or http requests after that... How does Alexa discover the devices or better, which steps does alexa perform to find devices

And I'm kind of lost why the esp won't see any udp packets whatsoever while the raspberry can without any problems EDIT: Well, after disconnecting the raspberry pi3 from lan and using it over wifi it couldn't see any udp packets as well so I'm think it is my wifi whitch won't transfer the packets... I'm using a TP-Link Router as access point and very clueless why it wouldn't work

Aircoookie commented 5 years ago

@DarkPixelWolf Yes, that's correct! It seems like a proper response to the discovery packet. Alexa should send a request to http://192.168.188.36:80/description.xml next and Espalexa responds with something along the lines of:

<root xmlns="urn:schemas-upnp-org:device-1-0">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<URLBase>http://192.168.188.36:80/</URLBase>
<device>
<deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>
<friendlyName>Philips hue (192.168.188.36)</friendlyName>
<manufacturer>Royal Philips Electronics</manufacturer>
<manufacturerURL>http://www.philips.com</manufacturerURL>
<modelDescription>Philips hue Personal Wireless Lighting</modelDescription>
<modelName>Philips hue bridge 2012</modelName>
<modelNumber>929000226503</modelNumber>
<modelURL>http://www.meethue.com</modelURL>
<serialNumber>ecfabc20ff67</serialNumber>
<UDN>uuid:2f402f80-da50-11e1-9b23-ecfabc20ff67</UDN>
<presentationURL>index.html</presentationURL>
<iconList>
<icon>
<mimetype>image/png</mimetype>
<height>48</height>
<width>48</width>
<depth>24</depth>
<url>hue_logo_0.png</url>
</icon>
<icon>
<mimetype>image/png</mimetype>
<height>120</height>
<width>120</width>
<depth>24</depth>
<url>hue_logo_3.png</url>
</icon>
</iconList>
</device>
</root>

Ok, interesting that the Raspberry doesn't receive anything on WiFi either! That means it is not the libraries fault, but probably your router's! Do you have another old router you could use as a test accesspoint?

PyxelFox commented 5 years ago

I expected that! Ok, I ported your whole library to python and the result of ´/description.xml` is the same as with a esp. So that works... Yes, I think it is not your libraries but my routers fault. That would explain why alexa won't request the description.xml after responding to the M-SEARCH packet, what the raspberry clearly did. I will try to resolve the issue with another router or some changes in the settings of the current one.

I guess I will upload the python version of your library when it works, of course only if that is ok with you. Maybe someone needs something like this as well, who knows.

EDIT: one quick question: the serialNumber and the end of the uuid is the mac as hex, right? (like ecfabc20ff67)

Aircoookie commented 5 years ago

Nice! Of course, it would be awesome to have a python version of the library! I'd imagine there are many users who want Alexa capability on a Raspi!

Yes, that's correct! It doesn't have to be the mac though, you just have to make sure it's unique for every Espalexa installation in the same network.

PyxelFox commented 5 years ago

So I wired up a FRITZ!Box 7490 and set it up as an access point and connected the esp to it and it seems to work, well it receives udp packets now and shows them in the log, but I just can't get my echo dot to connect to the wifi, it just won't connect and exits out with an error every time.

PyxelFox commented 5 years ago

After some time the setup mode of my alexa just stopped and alexa connected to the wifi it was unable to connect some minutes ago. I tried to discover my esp and it worked right away! So it was in fact the fault of my TP-Link access point/router... Which works just fine now, it just needed a new setup. As this seems to work perfectly now I will test my python implementation next.

PyxelFox commented 5 years ago

I came across some stuff while testing:

-> ALEXA: UDP Packet - M_SEARCH -> CLIENT: UDP Packet - HTTP OK -> ALEXA: HTTP CALL /description.xml -> CLIENT: HTTP XML - description.xml -> ALEXA: HTTP CALL - API - lights -> CLIENT: JSON - lights

This should be the steps for the discovery. right? My problem is that my alexa won't send an api call after receiving the xml (works with the esp). I checked my xml output with the one of an esp and it is the same (except the serial of course).

PyxelFox commented 5 years ago

Allright, my alexa now sends the api call and all seems fine and working. Only thing I noticed is that the color change won't work, even with the ESP. The color always remains white.

HTTP Request:

AlexaApiCall
/api/E3goBZxwG4ZPovV37lKxYmCVFdWwtTgO1jwxQ3UW/lights/2/state
{ "on": true, "xy": [0.654386890477478,0.28398351120196125] }
Blueforcer commented 4 years ago

Allright, my alexa now sends the api call and all seems fine and working. Only thing I noticed is that the color change won't work, even with the ESP. The color always remains white.

HTTP Request:

AlexaApiCall
/api/E3goBZxwG4ZPovV37lKxYmCVFdWwtTgO1jwxQ3UW/lights/2/state
{ "on": true, "xy": [0.654386890477478,0.28398351120196125] }

Hi @DarkPixelWolf . What did you change that Alexa send the api call? I try to adapt this lib to java. It works on my computer, but doesnt work on a friends computer. After sending the description.xml no further api call happen.

PyxelFox commented 4 years ago

Allright, my alexa now sends the api call and all seems fine and working. Only thing I noticed is that the color change won't work, even with the ESP. The color always remains white. HTTP Request:

AlexaApiCall
/api/E3goBZxwG4ZPovV37lKxYmCVFdWwtTgO1jwxQ3UW/lights/2/state
{ "on": true, "xy": [0.654386890477478,0.28398351120196125] }

Hi @DarkPixelWolf . What did you change that Alexa send the api call? I try to adapt this lib to java. It works on my computer, but doesnt work on a friends computer. After sending the description.xml no further api call happen.

This issue is already over a year old, so I can't really recall anything important I did to make it work. In addition I switched to Google Home for my in home lighting. Based on that I can't help you with it, I'm sorry.

You could look into my (maybe outdated) python code if you like: Espalexa-Python

Blueforcer commented 4 years ago

Okay, it was worth a try. Thanks anyway. :)