mabunixda / node-red-contrib-alexa-home

MIT License
32 stars 10 forks source link

Issue after updating to 1.x with device discovery #16

Closed tribbles3 closed 5 years ago

tribbles3 commented 5 years ago

Posting this here because it looks like the other issue thread has been closed.

I did the latest update and can longer access any of the nodes/devices. I tried discovering devices, nothing was found and then I tried creating a new device and that was not discovered either. I noticed that none of the nodes are displaying any status information under the node whereas before the was status information.

mabunixda commented 5 years ago

Did you also add the alexa home controller node?

I found a bug within my logic that the error message is just displayed when an input is processed by the node providing alexa functions. But this node is not detected by alexa if the controller node is not available.

I gonna readd a status error on the node to reflect that the controller node is missing. I removed this because it also can happen that node-red is initializing alexa-home nodes before the alexa-home-controller node is available and this status message appears - but is afterwards overriden.

mabunixda commented 5 years ago

@tribbles3 please retry with version 1.0.1

tribbles3 commented 5 years ago

When I add the controller I get the following error (and I am unable to name the controller as well):

TypeError: Cannot read property '_logger' of undefined

mabunixda commented 5 years ago

which node-red version are running? and which node/npm version is used to run node-red?

tribbles3 commented 5 years ago

node-red V0.18.7

npm 5.6.0

mabunixda commented 5 years ago

Ok - i just ran it with node-red v0.20 and npm 6.4 and node 10.15

I gonna test this with your versions ...

tribbles3 commented 5 years ago

node.js version = 8.11.3 (forgot to put that before)

Werner-G commented 5 years ago

I have the same problem. No device is detected by alexa, and the node-red-log always show: 6 Jun 21:38:45 - [error] [alexa-home-controller:84890d22.1ef118] TypeError: Cannot read property '_logger' of undefined

I am not able to include any name inside the alexa home controller node.

Node 10.15.1
Npm 6.7.0
Nodered 0.19.5
mabunixda commented 5 years ago

i removed the blocking logger stuff in version 1.0.2 - logging is now done entirely via node-red.

Please use this version and give me feedback .. Thanks!

tribbles3 commented 5 years ago

I am now able to add the controller and name it without getting an error but Alexa still cannot locate any of my devices (even tried adding a new device node).

Werner-G commented 5 years ago

I upgraded to V1.02. Logs are OK (no errors, no warnings). But in Node-Red, I still cannot add a name in the Controller, and Alexa cannot detect any device. But the Controller showing 'ok', like the devices.

tribbles3 commented 5 years ago

I just checked and as Werner-G has stated, I cannot actually name the controller node. You can type a name in but it will not stick after saving.

mabunixda commented 5 years ago

Ok the naming of the controller is easy fixable.

Can you test if port 1900/udp is open? On Linux/*nix it should be

netstat -ulnp 

In the current version you will find an output at info level logging of node-red "alexa-home - Starting SSDP"

First assumption is that the announced SSDP URI is not correct. Please turn debug level on node-red and this should output [debug] announcing: http://$HOST:$PORT/setup.xml

My guess is that this will result in http://undefined/setup.xml

You can shortfix this by using an env variable ALEXA_IP and point it to the correct address/host/ip. I am fixing the algorithm behind this!

tribbles3 commented 5 years ago

On the road so I won't be able to test anything till tonight.

tribbles3 commented 5 years ago

Is the debug level set in settings.js and if so, what is the exact setting that needs to be changed (can't find it)?

stephjj commented 5 years ago

Same problems :

mabunixda commented 5 years ago

the purpose of this node is that alexa discovers instances via udp broadcast. Not each command node should run a udp service - this should only run once. This was previously < 1.x created in the background was not controllable. So this node is not for configuration - this providers the broadcast from alexa to node-red.

@stephjj Can you define an environment variable DEBUG=node-ssdp:server ? This will generate debug output about the discovery process. There will be a lot of output but there is also the response included which gets to alexa back. When you click http://.../setup.xml is a response generated?

@tribbles3 you can turn on logging by this configuration. @stephjj did you already turn on logging?

stephjj commented 5 years ago

the response on http://192.168.1.14:1880/setup.xml is Cannot GET /setup.xml after a very long time

The log for SSDP (partial) : node-ssdp:server Sending an advertisement event +10s node-ssdp:server Sending a message to 239.255.255.250:1900 +1ms node-ssdp:server Sending an advertisement event +1ms node-ssdp:server Sending a message to 239.255.255.250:1900 +0ms node-ssdp:server Sending an advertisement event +1ms node-ssdp:server Sending a message to 239.255.255.250:1900 +0ms node-ssdp:server Sending an advertisement event +10s node-ssdp:server Sending a message to 239.255.255.250:1900 +1ms node-ssdp:server Sending an advertisement event +1ms node-ssdp:server Sending a message to 239.255.255.250:1900 +0ms node-ssdp:server Sending an advertisement event +1ms node-ssdp:server Sending a message to 239.255.255.250:1900 +0ms node-ssdp:server Outgoing server message: { message: 'NOTIFY HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nNT: upnp:rootdevice\r\nNTS: ssdp:alive\r\nUSN: uuid:f6543a06-da50-11ba-8d8f-5ad3fb5c3f142c::upnp:rootdevice\r\nLOCATION: http://192.168.1.14:1880/setup.xml\r\nCACHE-CONTROL: max-age=1800\r\nSERVER: node.js/8.16.0 UPnP/1.1 node-ssdp/4.0.0\r\n\r\n', id: '93af07b0a39d1339' } +5ms node-ssdp:server Outgoing server message: { message: 'NOTIFY HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nNT: urn:schemas-upnp-org:device:basic:1\r\nNTS: ssdp:alive\r\nUSN: uuid:f6543a06-da50-11ba-8d8f-5ad3fb5c3f142c::urn:schemas-upnp-org:device:basic:1\r\nLOCATION: http://192.168.1.14:1880/setup.xml\r\nCACHE-CONTROL: max-age=1800\r\nSERVER: node.js/8.16.0 UPnP/1.1 node-ssdp/4.0.0\r\n\r\n', id: '521ad3064ab35620' } +2ms node-ssdp:server Outgoing server message: { message: 'NOTIFY HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nNT: uuid:f6543a06-da50-11ba-8d8f-5ad3fb5c3f142c\r\nNTS: ssdp:alive\r\nUSN: uuid:f6543a06-da50-11ba-8d8f-5ad3fb5c3f142c\r\nLOCATION: http://192.168.1.14:1880/setup.xml\r\nCACHE-CONTROL: max-age=1800\r\nSERVER: node.js/8.16.0 UPnP/1.1 node-ssdp/4.0.0\r\n\r\n', id: '733f942c1a27cf78' } +1ms node-ssdp:server Outgoing server message: { message: 'NOTIFY HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nNT: upnp:rootdevice\r\nNTS: ssdp:alive\r\nUSN: uuid:f6543a06-da50-11ba-8d8f-b1cd33f412df68::upnp:rootdevice\r\nLOCATION: http://192.168.1.14:1880/setup.xml\r\nCACHE-CONTROL: max-age=1800\r\nSERVER: node.js/8.16.0 UPnP/1.1 node-ssdp/4.0.0\r\n\r\n', id: '7344750e79c582df' } +5ms node-ssdp:server Outgoing server message: { message: 'NOTIFY HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nNT: urn:schemas-upnp-org:device:basic:1\r\nNTS: ssdp:alive\r\nUSN: uuid:f6543a06-da50-11ba-8d8f-b1cd33f412df68::urn:schemas-upnp-org:device:basic:1\r\nLOCATION: http://192.168.1.14:1880/setup.xml\r\nCACHE-CONTROL: max-age=1800\r\nSERVER: node.js/8.16.0 UPnP/1.1 node-ssdp/4.0.0\r\n\r\n', id: '8fa13a4e9d875f3d' } +1ms node-ssdp:server Outgoing server message: { message: 'NOTIFY HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nNT: uuid:f6543a06-da50-11ba-8d8f-b1cd33f412df68\r\nNTS: ssdp:alive\r\nUSN: uuid:f6543a06-da50-11ba-8d8f-b1cd33f412df68\r\nLOCATION: http://192.168.1.14:1880/setup.xml\r\nCACHE-CONTROL: max-age=1800\r\nSERVER: node.js/8.16.0 UPnP/1.1 node-ssdp/4.0.0\r\n\r\n', id: '37dcc4d165b6c908' } +1ms

mabunixda commented 5 years ago

Thanks - so alexa gets the correct url announced, but the node is not responding.

@stephjj is your node-red available under http://192.168.1.14:1880 ? Can you try to enable debug logging within node-red as next step?

I did redesign the alexa-home-controller to be a full node to make it visible and available. But i gonna make it available on the fly again that you are not forced to reconfigure this. May be i should add a debug switch on this node, that this process of discovery gets more transparent/debugable

stephjj commented 5 years ago

Yes, it's the address of the NodeRed

stephjj commented 5 years ago

BTW, the alexa-home-controller node must be a config node and not a function node with 0 input and 0 output. That is you will have exactly one node automatically

mabunixda commented 5 years ago

@stephjj config nodes are unique but cannot have any logic as far as i know right now ...

If anyone is able to provide some debug logs i could fix this. I have this version running in my deployment - but i am using a docker image within kubernetes to run my node-red installation.

tribbles3 commented 5 years ago

Here is the debug info:

8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] No Alexa Home Controller available 8 Jun 22:43:49 - [debug] Determining httpAddress... 8 Jun 22:43:49 - [debug] httpAddress using interface address: 10.0.0.100:1880 8 Jun 22:43:49 - [info] [alexa-home-controller:ec2a7717.6b8148] alexa-home - Sta rting SSDP 8 Jun 22:43:49 - [debug] announcing: http://undefined/setup.xml

stephjj commented 5 years ago

The config nodes are like the other but lives on the config tab not the editor. They can have a GUI. Look at the core node. 10-mqtt.js for example. The node mqtt-broker has all the logic for the communication with the MQTT protocol. Then the mqqt in and mqtt out has only the logic to deal with messages and decode the message

SamNitro commented 5 years ago

Hello, is there any way to get it started?

AndreyKindin commented 5 years ago

Hi hier is my fix for announcing: http://undefined/setup.xml

\home\pi.node-red\node_modules\node-red-contrib-alexa-home\alexa\alexa-home-controller.js row 146

`AlexaHomeController.prototype.getHttpAddress = function () {

    if (process.env.ALEXA_IP) {
        var publicIP = process.env.ALEXA_IP;
        if (publicIP.indexOf(":") > 0) {
            RED.log.debug("httpAddress using env.ALEXA_IP: " + publicIP);
            return publicIP;
        }
        RED.log.debug("httpAddress using env.ALEXA_IP and node-red uiPort: " + publicIP + ":" + RED.settings.uiPort);
        return publicIP + ":" + RED.settings.uiPort;
    }
    if (RED.settings.uiHost && RED.settings.uiHost != "0.0.0.0") {
        RED.log.debug("httpAddress using node-red settings: " + RED.settings.uiHost + ":" + RED.settings.uiPort);
        return RED.settings.uiHost + ":" + RED.settings.uiPort;
    }
    RED.log.debug("Determining httpAddress...")
    var os = require('os');
    var ifaces = os.networkInterfaces();

    var httpAddress;

    Object.keys(ifaces).forEach(function (ifname) {
        var alias = 0;

        ifaces[ifname].forEach(function (iface) {
            if ('IPv4' !== iface.family || iface.internal !== false) {
                // skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
                 RED.log.debug("skip");
                return;
            }

            if (alias >= 1) {
                // this single interface has multiple ipv4 addresses
                if (alexa_home.isDebug) {
                    RED.log.debug(ifname + ':' + alias, iface.address);
                }
            } else {
                if (alexa_home.isDebug) {
                    RED.log.debug(ifname, iface.address);
                }
                RED.log.debug("httpAddress using interface address: " + iface.address + ":" + RED.settings.uiPort);
                httpAddress = iface.address + ":" + RED.settings.uiPort;
                return;
            }
            ++alias;
        });
    });
    return httpAddress;     
}`
SamNitro commented 5 years ago

i have change the alexa-home-controller.js now if i search for device, the Alexa-home-controller write
--lights list requested 50 and than --setup requested

but I can't control any device.

mabunixda commented 5 years ago

@AndreyKindin yeah i did a similar fix already in the codebase 9af4ac53bd6d7d244840cdcdcb6490e779d4e8bc

@SamNitro do you see the devices within alexa app? for more details, you must enable debug logging on node-red.

I want to release 1.0.3 when that issue is asap fixed. You can use the dev branch to get the latest stuff.

AndreyKindin commented 5 years ago

@mabunixda i try your dev release it works good for me 👍. @SamNitro try to delete Alexa home Controller node from your flow and add it again.

SamNitro commented 5 years ago

Yes, now it works, but in the old version I could get double names with a ";" separate.

In German (Rollo Wohnzimmer; Rolladen Wohnzimmer)

this is not possible anymore

mabunixda commented 5 years ago

Ok - did not even know that this work :-D I use link - nodes to do kind of groups/scenes

mabunixda commented 5 years ago

i just pushed version 1.0.3 to npm .. please verify if ssdp location is now fixed and nodes are detected again by alexa

tribbles3 commented 5 years ago

1.0.3 and still can't access any devices and Alexa doesn't discovery any devices.

stephjj commented 5 years ago

Upgraded to 1.0.3 doesn't work. Log: 10 Jun 19:21:53 - [debug] No Alexa Home Controller available 10 Jun 19:21:53 - [debug] No Alexa Home Controller available 10 Jun 19:21:53 - [debug] No Alexa Home Controller available 10 Jun 19:21:54 - [debug] Alexa Controller - Determining httpAddress... 10 Jun 19:21:54 - [debug] Alexa Controller - httpAddress using interface address: 192.168.1.14:1880 10 Jun 19:21:54 - [info] [alexa-home-controller:Alexa Controller] Alexa Controller - alexa-home - Starting SSDP 10 Jun 19:21:54 - [debug] Alexa Controller - announcing: http://192.168.1.14:1880/setup.xml 10 Jun 19:21:54 - [info] Assigning alexa-home nodes to this controller 10 Jun 19:21:54 - [info] Started flows

Cannot get http://192.168.1.14:1880/setup.xml Error 404 : Cannot GET /setup.xml

mabunixda commented 5 years ago

@tribbles3 Is there any change in the controller node status shown? --lights list requested --setup requested

Do you have debug on node-red enabled? If yes, then you will find a log output as [debug] Alexa Controller - announcing: http://..../setup.xml Can you access this setup.xml file?

@stephjj @AndreyKindin which versions of node,npm and node-red are you using? As far as i understand the node is working for @AndreyKindin and myself but - at least - not for @stephjj and @tribbles3

stephjj commented 5 years ago

10 Jun 19:21:43 - [info] Node-RED version: v0.20.5 10 Jun 19:21:43 - [info] Node.js version: v8.16.0 10 Jun 19:21:43 - [info] Linux 4.9.35-v7+ arm LE

tribbles3 commented 5 years ago

Controller node shows "lights list requested: 25" Yes, I can access setup.xml

mabunixda commented 5 years ago

@stephjj @tribbles3 do you have inputs wired to the alexa nodes so that these get set already?

stephjj commented 5 years ago

no Capture

tribbles3 commented 5 years ago

Yes for me as well.

mabunixda commented 5 years ago

Ok - just to summarize Alexa finds your node-red by udp/upnp via ssdp because setup.xml file is requested ( setup requested ) and Alexa also fetches lights items list ( lights list requested: ... )

@stephjj how many alexa nodes have you configured?

tribbles3 commented 5 years ago

Your summary is correct for my situation.

mabunixda commented 5 years ago

@tribbles3 @stephjj can you send me the content-length of following url curl -sv http://$NODE_RED/api/abc/lights 2>&1 | grep Content-Length

Be aware that alexa devices seem not to support gzip compression. So testing this url in your browser might bring up an incorrect content-length

tribbles3 commented 5 years ago

I'm on windows.

mabunixda commented 5 years ago

no problem - here we go:

$r = Invoke-WebRequest  "http://$NODE_RED/api/abc/lights"
Write-host $r.Headers["Content-Length"]
stephjj commented 5 years ago
 $ curl -sv http://192.168.1.14:1880/api/abc/lights
* Hostname was NOT found in DNS cache
*   Trying 192.168.1.14...
* Connected to 192.168.1.14 (192.168.1.14) port 1880 (#0)
> GET /api/abc/lights HTTP/1.1
> User-Agent: curl/7.38.0
> Host: 192.168.1.14:1880
> Accept: */*
>
< HTTP/1.1 404 Not Found
< X-Powered-By: Express
< Content-Security-Policy: default-src 'self'
< X-Content-Type-Options: nosniff
< Content-Type: text/html; charset=utf-8
< Content-Length: 153
< Date: Mon, 10 Jun 2019 20:05:14 GMT
< Connection: keep-alive
<
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot GET /api/abc/lights</pre>
</body>
</html>
* Connection #0 to host 192.168.1.14 left intact
mabunixda commented 5 years ago

@stephjj aehm ... what the hack is going on there - you are on arm right? raspi?

stephjj commented 5 years ago

yes Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

mabunixda commented 5 years ago

Ok i got a zero w somewhere which i can use to test this behavior..

tribbles3 commented 5 years ago

Alexa has now recognized all of my devices and I can access them, thank you! :)

Will I need to add another controller once I reach a certain number of device nodes?