vintlabs / fauxmoESP

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

The ESP device is not being discovered, unsure how to debug. #203

Open dav opened 2 years ago

dav commented 2 years ago

Hi.

I've got this set up as in the examples, and have been unable to get it to be recognized by my Alexa device.

It's not explained super clearly anywhere I have been able to find after well over an hour searching the web researching this, but I think how this is supposed to work:

  1. The ESP866 (running the fauxmo server) imitates being a 2012 model Philips Hue Bridge.
  2. When I ask Alexa to search for new devices, either through the iOS app or by talking to my Gen 1 Echo Show, there should be some sort of UDP multicast message sent on the network (presumably a M-SEARCH type with ssdp:discover, upnp:rootdevice or device:basic:1) which fauxmo will detect and respond to with the url to its description.xml.
  3. The Alexa device will then download that description.xml via TCP and list the fauxmo device as a recognized device it can interact with.
  4. Presumably it would immediately query fauxmo via TCP HTTP request to e.g. http://192.168.1.104:1901/api/lights in order to determine what devices it controls (this being the device(s) I have defined in the .ino code as in the example) and what they are to be called in voice interaction.

Since it wasn't working, I've gone into the library and updated fauxmoESP.h to enable debugging:

#define DEBUG_FAUXMO                Serial
[....]
#ifndef DEBUG_FAUXMO_VERBOSE_TCP
#define DEBUG_FAUXMO_VERBOSE_TCP    true
#endif

#ifndef DEBUG_FAUXMO_VERBOSE_UDP
#define DEBUG_FAUXMO_VERBOSE_UDP    true
#endif

I've also modified the debug output code somewhat to be clear about what devices on my network are making the requests.

So I am carefully watching the network traffic to the ESP server and it seems that it is never getting the initial discovery request from the Alexa device, e.g. I am not seeing the discovery attempt as described in step 2 above.

I have tried this both via my iOS device and directly interacting with the Echo Show.

When trying from the iOS device in the Alexa app (Add Device -> Light -> Philips Hue), I would expect that the M-SEARCH request would come from its IP address, and likewise when asking the Show to "add new device" I would expect an M-SEARCH request to come from its IP address.

This is not happening though.

All three devices (ESP8266, Echo Show and iPhone) are on the same 2.4GHz wireless network.

Is there something I am missing or misunderstanding about how this is supposed to work?

I realize that if my reasoning above is correct, the problem seems to be more on Alexa (app and device) failing to initiate the discovery properly as opposed to anything wrong with fauxmoESP, still I felt this might be a better place to start since at least hopefully someone who has worked on this and got it working can either confirm or correct my reasoning.

Some further details in case helpful:

The fauxmo server is receiving ssdp:discover from various other devices on my network, responding with:

HTTP/1.1 200 OK
EXT:
CACHE-CONTROL: max-age=100
LOCATION: http://192.168.1.104:1901/description.xml
SERVER: FreeRTOS/6.0.5, UPnP/1.0, IpBridge/1.17.0
hue-bridgeid: c45bbe4dc54c
ST: urn:schemas-upnp-org:device:basic:1
USN: uuid:2f402f80-da50-11e1-9b23-c45bbe4dc54c::upnp:rootdevice

The description.xml is served up fine:

curl http://192.168.1.104:1901/description.xml

<?xml version="1.0" ?>
<root
    xmlns="urn:schemas-upnp-org:device-1-0">
    <specVersion>
        <major>1</major>
        <minor>0</minor>
    </specVersion>
    <URLBase>http://192.168.1.104:1901/</URLBase>
    <device>
        <deviceType>urn:schemas-upnp-org:device:Basic:1</deviceType>
        <friendlyName>Philips hue (192.168.1.104:1901)</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>c45bbe4dc54c</serialNumber>
        <UDN>uuid:2f402f80-da50-11e1-9b23-c45bbe4dc54c</UDN>
        <presentationURL>index.html</presentationURL>
    </device>
</root>

The fauxmo API lists the lights:

curl http://192.168.1.104:1901/api/lights
{"1":{"type": "Extended color light","name": "blue light","uniqueid": "C4:5B:BE:4D:C5:4C:00:00-00"}}
dav commented 2 years ago

I forgot to mention, I do see the Alexa Show device occasionally broadcasting the following:

NOTIFY * HTTP/1.1
USN: uuid:2e791a91-71e5-354a-b851-1e39df3c3c51::upnp:rootdevice
CACHE-CONTROL: max-age=1800
NT: upnp:rootdevice
HOST: 239.255.255.250:1900
LOCATION: http://192.168.1.24:60000/upnp/dev/2e791a91-71e5-354a-b851-1e39df3c3c51/desc
SERVER: Linux/3.14.55-x86_64-L1-R405-g0bd4fc8 UPnP/1.0 Cling/2.0
NTS: ssdp:alive

It doesn't seem to be related to device discovery though.

develarts commented 2 years ago

Same problem, need help.

suloku commented 2 years ago

I had a similar problem, in the end it seemed like my router doesn't support too many devices being connected at once for alexa to discover the fauxmo devices. Maybe this will help: https://github.com/vintlabs/fauxmoESP/issues/199

Once discovered by alexa everything works fine alexa->device, but any device->alexa communication seems to not work anymore (i.e. setting a device to ON/OFF state from the device itself)

riban-bw commented 2 years ago

A few ideas (which may be red herrings but worth considering).

Some Alexa devices will only work on HTTP port 80. I see you are using port 1901. Worth trying on port 80.

Discovery seems to be implemented within the handle() function so that needs to be called regularly. As far as I can tell, this is the only use of handle() and it might be good to move that to the async handler too but...

I am experiencing regular ESP8266 crash which seems to be triggered by discovery + handle() function. When discovery occurs there is a core dump and restart. This was occuring regularly so I disabled the handle() call and things have been stable for 4days, 11 hours so far.... I will report on a separate ticket. I would have thought you would have observed this in your debug output from the ESP8266 if you are experiencing this issue.

Discovery seems to be done via multicast. As mentioned by @suloku, this involves the router directing messages to members of the multicast group. If the router has an issue then the messages may not be transmitted, e.g. the router may have a bug where it doesn't clear its list of multicast members and fills the memory space available for multicast mebership. (Most routers reserve little space for broadcast messages and drop them before other messages. Multicast may be treated similarly.) In most home routers multicast may be poorly implemented.

I have suffered this issue with intermittent, seemingly random success on discovering devices. It is frustrating!

fabiopdm commented 2 years ago

Same problem here.

Can't find devices via Alexa App on iOS. I've tried Phillips Hue and other modes for discovery.

START /Users/Documents/Projetos/Alexa_Clone_RF.ino from Dec 31 2021 Using library version 3.5.0 Setup ConcluídoReady to send IR signals at pin 13 [WIFI] Connecting to xxxx .. [WIFI] STATION Mode, SSID: xxxx, IP address: 192.168.1.12 [FAUXMO] Enabled [FAUXMO] UDP server started [FAUXMO] Device 'ligar ventilador' added as #0 [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [FAUXMO] Responding to M-SEARCH request [FAUXMO] Responding to M-SEARCH request [FAUXMO] Responding to M-SEARCH request [FAUXMO] Responding to M-SEARCH request [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236672 bytes [MAIN] Free heap: 236688 bytes

amitesh-singh commented 2 years ago

I am also facing the same issue on esp8266. what's the fix?

suloku commented 2 years ago

I am also facing the same issue on esp8266. what's the fix?

Maybe this helps: https://github.com/vintlabs/fauxmoESP/issues/203#issuecomment-956132903

Hadn't had any problems since then, but I haven't added any new device either.

amitesh-singh commented 2 years ago

Thanks @suloku . I don't have Dot devices in my network. I am trying to locate fauxmoESP (esp8266) devices using Alexa android app, and the app could not find any device. I'd tried with other lib espalexa and it also did not work. It seems that there is a change somewhere.