julianh2o / RokuAlexaLambdaSkill

An Alexa Skill that allows voice control of your Roku
MIT License
104 stars 55 forks source link

Issue connecting Echo to External IP #3

Closed greensha12 closed 8 years ago

greensha12 commented 8 years ago

Hello julianh2o,

I was attempting to run your demo with an Amazon Echo that I have, running the server code on a Raspberry Pi, but ran into a bit of a snag in communication. I went through the process of setting up an external IP for my Raspberry Pi and set up port forwarding on my router. I was able to confirm that the external IP is reachable via Ping, Telnet, and even via the online tool http://www.canyouseeme.org/ that reported back that the connection was open and reachable. I was even able to confirm that the server can communicate directly with the Roku (to try and decipher where the break in communication occurred). I modified the server code so that I can test a simple button press to take the Roku back to its home screen. (Which worked fine.) However, when I try to invoke the keypresses from the lambda function on the Amazon side, I always get timeouts. I put debugging code in the index.js file to figure out where things get hung up. It seems that the http request never quite reaches the endpoint even with a timeout of 30 secs, which should be more than enough time for transmission.

With all that said, did you run into similar issues? I'm really trying to figure out the issue here, but can't seem to pinpoint it. I saw that there is a slight discrepancy between the ports used in your server.js and serverinfo_example.js files. One says port 1234, while the other says 12345. I assumed this was a overlook and was meant to be matching ports? I also made sure that the file is called serverinfo.js instead of the example file name so that the import could be consistent with the serverinfo require statement in your index.js file.

Not sure what I left out or did wrong. Any help would be greatly appreciated.

Regards,

Shalom

julianh2o commented 8 years ago

Yes, the ports should match and you did the right thing by renaming that file.

It's possible that the first command is taking long enough that it causes a timeout on the Echo's side.

Could you try moving the line

response.end("OK");

in each of the handlers to the beginning of the function call? (eg. before the call to "postSequence")

greensha12 commented 8 years ago

Thanks for the quick response! I tried your suggestion, but I'm not certain it's even making it to the handler properly. In addition to moving the response line to the top of the functions, I increased the timeout on the lambda function to 45 secs. In your testing what was the average time for a response back to the Echo?

julianh2o commented 8 years ago

Hmm, I'm not sure I remember.. Usually not too long, I've carefully set things up so that it doesn't wait around very long, even a second would be a bit on the high side, I think.

Try it manually, navigate your browser to http://<your ip>:<your port>/roku/playlast

You should be able to note two things, first of all.. whether or not that works. Second, how long it takes for your browser to decide that the page has finished loading.

It's definitely a bit strange that you don't think anything is getting to the handlers.. Is it possible that you haven't set your internal/external ports correctly in the forwarding? If you can reach your pi with SSH and ping, those will be on different ports. The question is whether you can access the Node's port from outside your network.

If your phone is on a 3g (or other cell network) internet connection, you can use that to try testing from outside your home network. Again, navigate your browser using the URL above. Make sure you disable WiFi while doing this to force the external connection.

You can also try hitting those endpoints from within your network using the local addr/port.

Let me know which of these work for you.

greensha12 commented 8 years ago

I tried posting via my laptop that's on the network, as well as via 3G connection on my phone. It works on my laptop, but not via the 3G network...So it's looking like my external IP is not set up properly. Either that, or my port forwarding settings aren't correct. Do you have any suggestions in confirming proper setup of an external IP, as well as port forwarding?

The port forwarding seemed pretty straight forward. I went to my router's IP in the browser, made sure portforwarding was enabled on my WLAN network, also made sure that the proper IP adress was entered for my Raspberry Pi with a port range of 8060:8061 and local port of 8060 (which is used for the server) setup as a TCP connection. I read online that UPnP should be enabled (which was done by default), so I confirmed that. Is there anything you think I may be missing?

julianh2o commented 8 years ago

Hmm, have you confirmed your external IP address? The easiest way I know is http://www.wimi.com

One possible thing to try is to forward a single port rather than a range. If you're using 8060, have you updated all of the other ports as well? (in server.js and in that serverinfo.js file?)

Maybe try snapping a screenshot of your router's port forwarding settings? It sounds like it's probably set up correctly.. but I'm running out of ideas.

greensha12 commented 8 years ago

The external IP address should be that of my Raspberry Pi, right? http://www.wimi.com shows me my router IP address. Should I be using this instead?

julianh2o commented 8 years ago

Yeah, use your router's external IP address when configuring your Alexa skill.

Because Amazon's servers are outside of your network, they need to direct traffic to your router.

Once the request gets to your router, the port forwarding that you set up will direct it to your RaspberryPi.

(When you configure your forwarding, you are basically saying.. "When external traffic comes in for X port, direct it to this Y local IP address on Z port)

greensha12 commented 8 years ago

Ok...I just answered my own question. I was supposed to be using the router address this whole time not the Raspberry Pi. I just confirmed it using my phone on 3G.

In my own defense, this is my first experience with port forwarding. lol. But I know now!

Thanks for the help! I really appreciate the quick responses.

julianh2o commented 8 years ago

No problem, enjoy!

Also, check out kawillia's fork: https://github.com/kawillia/RokuAlexaLambdaSkill

He's added some features that you may find useful.

greensha12 commented 8 years ago

Will do. Thanks again!