Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discovery fails for a new "amazon echo device" on Echo Plus 2 #41

Closed
Catfriend1 opened this issue Jul 2, 2019 · 8 comments
Closed

Discovery fails for a new "amazon echo device" on Echo Plus 2 #41

Catfriend1 opened this issue Jul 2, 2019 · 8 comments

Comments

@Catfriend1
Copy link

Catfriend1 commented Jul 2, 2019

ECHO DEVICES
  • Echo Plus 2nd generation
MODULE VERSION

most recent from ioBroker repo

Hi,
I didn't change anything in my flow diagram. It's just three amazon echo devices, one echo hub and simple outputs to an adapter data point. It still works, but when I added the third "virtual" device using this plugin, Alexa was unable to discover it. Went to shell of the Debian machine via SSH and noticed the incoming Alexa connection on port tcp#80 for some seconds by running "lsof -i -P | grep :80 | grep node-red".
Is this an incompatiblity introduced by Amazon's auto firmware upgrade?
I can still switch existing "lights" on and off but no longer discover a new one.
Deleted "light 2" of my three and re-ran discovery and didn't find light 3 and light 2. light 1 is still there (because I didn't delete it) and it works through node-red and this plugin.
Kind regards
Catfriend1

EDIT: Found my flow config.

[
    {
        "id": "af6e4652.da7d48",
        "type": "tab",
        "label": "OG-cf",
        "disabled": false,
        "info": ""
    },
    {
        "id": "9bdfa8d8.2f7368",
        "type": "amazon-echo-hub",
        "z": "af6e4652.da7d48",
        "port": "80",
        "enableinput": false,
        "x": 90,
        "y": 20,
        "wires": [
            [
                "68d402f0.ecb80c",
                "706f80f8.1a7c9",
                "9b95931e.8fc94"
            ]
        ]
    },
    {
        "id": "68d402f0.ecb80c",
        "type": "amazon-echo-device",
        "z": "af6e4652.da7d48",
        "name": "Lampe",
        "topic": "Lampe",
        "x": 430,
        "y": 20,
        "wires": [
            [
                "c4d9ecdb.0d521"
            ]
        ]
    },
    {
        "id": "79c82d45.977244",
        "type": "ioBroker out",
        "z": "af6e4652.da7d48",
        "name": "Lampe",
        "topic": "ham.0.OG-CF-Lampe.OG-CF-Lampe.On",
        "ack": "false",
        "autoCreate": "false",
        "x": 1130,
        "y": 20,
        "wires": []
    },
    {
        "id": "c4d9ecdb.0d521",
        "type": "change",
        "z": "af6e4652.da7d48",
        "name": "on_off_true_false",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "on",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "off",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 810,
        "y": 20,
        "wires": [
            [
                "79c82d45.977244",
                "c7917ffb.abf58"
            ]
        ]
    },
    {
        "id": "c7917ffb.abf58",
        "type": "debug",
        "z": "af6e4652.da7d48",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 1150,
        "y": 700,
        "wires": []
    },
    {
        "id": "706f80f8.1a7c9",
        "type": "amazon-echo-device",
        "z": "af6e4652.da7d48",
        "name": "Lautsprecher",
        "topic": "Lautsprecher",
        "x": 450,
        "y": 240,
        "wires": [
            [
                "5a7e7da2.0631a4"
            ]
        ]
    },
    {
        "id": "5a7e7da2.0631a4",
        "type": "change",
        "z": "af6e4652.da7d48",
        "name": "on_off_true_false",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "on",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "off",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 810,
        "y": 240,
        "wires": [
            [
                "c7917ffb.abf58",
                "151cf221.18985e"
            ]
        ]
    },
    {
        "id": "151cf221.18985e",
        "type": "ioBroker out",
        "z": "af6e4652.da7d48",
        "name": "Lautsprecher",
        "topic": "ham.0.SW-OG-CF-Sound.SW-OG-CF-Sound.On",
        "ack": "false",
        "autoCreate": "false",
        "x": 1150,
        "y": 240,
        "wires": []
    },
    {
        "id": "3cd4e538.098aea",
        "type": "change",
        "z": "af6e4652.da7d48",
        "name": "on_off_to_shell_param",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "on",
                "fromt": "str",
                "to": "enable-ssid SSID",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "off",
                "fromt": "str",
                "to": "disable-ssid SSID",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 820,
        "y": 480,
        "wires": [
            [
                "c7917ffb.abf58"
            ]
        ]
    },
    {
        "id": "9b95931e.8fc94",
        "type": "amazon-echo-device",
        "z": "af6e4652.da7d48",
        "name": "Gast-WLAN",
        "topic": "Gast-WLAN",
        "x": 450,
        "y": 480,
        "wires": [
            [
                "3cd4e538.098aea"
            ]
        ]
    }
]
@verjus
Copy link

verjus commented Jul 3, 2019

I don't have a 2nd generation Echo (only 3rd) but it appears that Alexa is looking for a (emulated) Hue server on port 80. However, port 80 requires elevated privileges. Are you running node-red as root? Otherwise, for this to work you need to run a reverse proxy such as nginx.
Here is my configuration for an Ubuntu machine:

file /etc/nginx/conf.d/alexa.conf:

For Hue emulation via Node-Red

server {
listen 80;
server_name mydomain_or_myip;

location / {
    proxy_pass                            http://localhost:8081/;
    proxy_set_header Host                 $http_host;
    proxy_set_header X-Real-IP            $remote_addr;
    proxy_set_header X-Forwarded-For      $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto    $scheme;
    proxy_buffering off;

}
}


I am running this node red module on unprivileged port 8081 and the reverse proxy sends all traffic to port 80.

Check that the server works by doing:
http://192.168.1.130:80/api/pi
or
http://192.168.1.130/api/pi
and
http://192.168.1.130:8081/api/pi

You should see a json file starting with 'lights'

(192.168.1.130 is where I run node-red).

Also, make sure that everything is on the same local network!

@Catfriend1
Copy link
Author

Thanks for your help ful post. I've got two iobroker servers , one ran it as root and the other is now running it as user iobroker. Port 80 is reachable from the network and alexa is also on this net. Somehow, I have a feeling that an alexa autoupdate broke things as everything worked with my two devices and rediscovery after deletion from the alexa app also worked fine. I deleted all devices and only the first got rediscovered by alexa (lampe). Lautsprecher and Gastnetz weren't discovered. I can still use speech commands for lampe, the first device. I setup a new amazon account and again, after setting up alexa echo plus 2 it only discovered the first device. Do you have any hints e.g. on Wireshark where and how to look at alexas local net comm?

@verjus
Copy link

verjus commented Jul 4, 2019

I am not sure I understand the role of iobroker in your setup. You could try to remove it for debugging purposes and start from scratch with Node Red and this module only. Add three Amazon Echo Devices (and name them as before - Lampe, Lautsprecher and Gastnetz). Restart node-red and see if Alexa discovers them. Most of my issues were cleared with a full restart of node-red. The module emulates a Hue Bridge, so nothing else is needed for the discovery. The discovery process goes like this:

1 - Receive - SSDP M-Search
2 - Send - SSDP Discovery Response
3 - Receive - GET :80/description.xml
4 - Send - Description response
5 - Receive - HTTP request: :80/api/pi/lights
6 - Send - Description of all devices

Where is the ip address of the machine running the node red server.

To debug, you could either log traffic with nginx or modify the code to make it print what it's receiving. For example, you could add the line
hubNode.warn(req);
in index.js

The part of the code relevant to discover appears to be:

` //
// SSDP
//
function ssdp(port, config) {

    var ssdpService = require('node-ssdp').Server
      , server = new ssdpService({
          location: {
            port: port,
            path: '/description.xml'
          },
          udn: 'uuid:' + getHueHubId(config)
        })

    server.addUSN('upnp:rootdevice');
    server.addUSN('urn:schemas-upnp-org:device:basic:1');

    server.start();
}

`

Hope this helps a bit.

@Catfriend1
Copy link
Author

Thanks, I'll make a Debugging session with your tips and report back. :-)

@Barabba11
Copy link

Thank you mates for your efforts here, the main creator here still not answer and we need to fix ourselves.
I'm not that expert and I've a question, where is the http server executable? Is it a library of Raspbian invoked? Or node.js?
My goal is to filter Echo IP to don't let it discover some devices (different floors, 2 Echo, same device name "blinds")

@verjus
Copy link

verjus commented Jul 5, 2019

No library. Everything is contained in the author's module. The server is defined in the file index.js. In the following lines:

        var httpServer = stoppable(http.createServer(app), graceMilliseconds);
 
        httpServer.on('error', function(error) {
          hubNode.status({fill:"red", shape:"ring", text:"Unable to start on port " + port});
          RED.log.error(error);
          return;
        });

to see the traffic, you can add the line hubNode.warn(req) in the area of the code that process requests from the Echo (commented here):

       app.put('/api/:username/lights/:id/state', function (req, res) {
 
	//hubNode.warn(req);
        setDeviceAttributes(req.params.id, req.body, hubNode.context().flow);

        var template = fs.readFileSync(__dirname + '/api/hue/templates/lights/set-state.json', 'utf8').toString();

        var data = getDeviceAttributes(req.params.id, hubNode.context().flow);

        var output = Mustache.render(template, data);
        output = JSON.parse(output);

        res.json(output);

        payloadHandler(hubNode, req.params.id, req.body);
      });

Hope this helps get you started.

@Barabba11
Copy link

Thank you! Which file is this "app"? http.createServer(app)
Where is the code of it? This is interesting for me to understand.
I'm still a beginner with javascript, I consider a bit difficult to implement that.. and what scary me more is to debug what I?m writing, I mean, I suppose to stop node red, upload the index.js and start node red again.. and if there is any mistake? I risk to create problems to node red I suppose. How to debug it safely and faster? Anyway, maybe someone can help me here. I've clear in my mind how this should work, but just I don't know how to write it in javascript. I don't want to go off topic, so if somebody is interested we were discussing here (before the author disappered) #17

@Catfriend1
Copy link
Author

Ok, I wanted to debug this but before I could start to observe anything my first manual command "alexa, search for devices" immediately brought devices 2 and 3 back (as I repeatedly tried a week ago without success and just got device 1 discovered).This leads me to the assumption an Amazon Firmware Update temporarily caused the discovery problem. I didn't touch the debian server vm with iobroker+nodered in the meantime because of lack of time.
Will save your instructions to disk in case I need them for another debugging in a future case. Thanks for your help :-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants