rgraciano / echo-sonos

Amazon Echo integration with Sonos
Other
713 stars 235 forks source link

Help please configuring Lambda #140

Closed chilloutboy closed 7 years ago

chilloutboy commented 7 years ago

Hi, i'm very new to this (not again, i hear you say). I've run through almost everything but am stuck at steps 5 to 7...

  1. Go into this repo's lambda/src directory and copy options.example.js to options.js. It's recommended you DO NOT edit the options.js file (leave all defaults), because it's easier to customize this later. (I think i did this correctly, by copying the contents of options.example.js into the code section by selecting 'Edit Code inline'. IS THIS CORRECT?) 6.In lambda/src, up everything. On Mac/Linux, cd src; chmod a+r .js sonosProxy/.js; zip src.zip .js sonosProxy/.js. Make sure you don't capture the folder, just the files. (this is where i really dont understand what Im supposed to do, im working on a Windows PC. CAN SOMEONE PLEASE EXPLAIN STEP BY STEP WHAT THIS ACTUALLY MEANS?) 7.Choose to upload the zip file for src.zip. (again totally confused here, PLEASE EXPLAIN)

I believe I've missed something out as when i test i get an error

"START RequestId: f6c318a0-01ec-11e7-8a91-7b35a3c0420f Version: $LATEST Handler 'handler' missing on module 'index' END RequestId: f6c318a0-01ec-11e7-8a91-7b35a3c0420f REPORT RequestId: f6c318a0-01ec-11e7-8a91-7b35a3c0420f Duration: 30.08 ms Billed Duration: 100 ms"

Thanks in advance :-)

jzajac2 commented 7 years ago
  1. Bottom line here, is you need an options.js which consists of the same contents as options.example.js. I'm sure there (was, or still is) a good reason for the two separate files. I'm not sure what you mean by 'edit code inline'. I would just copy/paste options.example.js to options.js (the contents of the file that is).
  2. For Windows, just select all the files under lambda\src directory, and zip them. I think he's just stressing you don't want to just zip the 'src' folder directly and send that up as your lambda function to aws; maybe the aws lambda function you created starting at step 3, is expecting the code files in root, not in root\src{theFiles} . What I did: selected files UNDER src, right-clicked, and created a zip file from them (and named that zip 'src.zip')

image

  1. Well you've had to go through several steps before this and be able to navigate the AWS Lambda Management console. By 'upload the zip file for src.zip' means just this:

image

jzajac2 commented 7 years ago

@rgraciano if my comments are correct maybe I can rework some parts of the readme and submit a pull request if that would help. Lots of people new to aws lambda services (myself included)

chilloutboy commented 7 years ago

Thanks jzajac2 You have been very helpful. I renamed the options.example.js to options.js zipped up the contents of the src folder and uploaded it.

I am still getting an error...

{ "errorMessage": "Cannot find module '/var/task/index'", "errorType": "Error", "stackTrace": [ "require (internal/module.js:12:17)" ] }

Thanks for you help ;-)

jzajac2 commented 7 years ago

When I had that error it was because of the structure of my zip I believe. Confirm yours is exactly as mine which works?: src.zip --sonosProxy (folder) --AlexaSkill.js --index.js --options.js

Also make sure you have pulled latest from master. I believe there was a recent update: https://github.com/rgraciano/echo-sonos/commit/43af5f952e306a76cae0585fe37e724be581aa82

chilloutboy commented 7 years ago

Thanks again jzajac2 for your help.

I'm getting closer, i did have a mistake with the zip file, all fixed now,

just getting an invalid application ID error now.

I've double checked the APPID is correct, i even tried inserting it directly into the options.js file but still get the same issue.

{ "errorMessage": "Invalid applicationId" }

Any help (again) would be appreciated :-)

jzajac2 commented 7 years ago

Make sure you don't forget these steps:

  1. Click Next to proceed. Once created, click "Triggers".
  2. Add a source. Choose "Alexa Skills Kit".

And if you 'publish' new versions, seems you need re-add that trigger each time. (so I stopped publishing new versions)

try to keep it out of the options.js file. It will work.

chilloutboy commented 7 years ago

Thanks once again jzajac2 for your help, without you I wouldn't have got this far.

I've managed to get Lambda working, i recreated both the Lambda function and also the Alexa skill. I think the issue was that previously i created the Alexa skill and changed the Language to English (UK), by recreating the skill and using the default English (US) Lambda is OK.

I still have a couple of issues: - Alexa wont perform any "ask sonos" functions, she just says "Hmm something went wrong, try again in a few minutes" I believe this is caused by the second issue, which is a configuration problem.

I don't understand how the custom slot types work, i understand that these are used for selecting options however, I am assuming that NAMES are all my ARTIST names as specified in my sonos music library, is this correct?

SERVICES - within this list are the music services, i assume i would be using LIBRARY if i want to play music from my sonos library? Also is the PRESETS option here to allow a subset of the custom slot type PRESETS?

PRESETS - is this used for genre or playlists or am i missing something here?

I have been testing using the Service Simulator in the Amazon developer in my Alexa skill. The only thing i can actually get to work are playlists. So if i type "start playlist test in bedroom" this creates a call to http://mydns:5005/bedroom/playlist/test and works correctly. However if i ask Alexa "ask sonos start playlist test in Bedroom" she tels me "something went wrong" I have tested my DNS and this all works correctly.

So I'm making good progress but still failing.

Any advice appreciated. Thanks in advance :-)

jzajac2 commented 7 years ago

I can't answer all of this right now, however, start with just using presets and Favorites. I have been most successful with Favorites. Presets are what you define in your node-sonos-http-api repo AFAIK

loftgren commented 7 years ago

So I'm super embarrassed, even though I'm a newbie... however, I cannot locate the file options.example.js. Pulling my freakin hair out! Can anyone please help?

jzajac2 commented 7 years ago

Relative to the download of this repo's master branch: lambda/src/options.example.js

https://github.com/rgraciano/echo-sonos/blob/master/lambda/src/options.example.js

loftgren commented 7 years ago

Thanks for the reply, but the link is 404. I'm simply stuck at step 5 of the process. I can locate the options.example.js on github, but I cannot figure out what to copy and paste it to? I assume I am looking locally for the file options.js, and adding the contents of options.example.js... as described in the instructions. However, I cannot find options.js locally anywhere...

chilloutboy commented 7 years ago

Hi loftgren

Try this https://github.com/rgraciano/echo-sonos/tree/master/lambda/src

loftgren commented 7 years ago

Thanks very much, but I have already located options.example.js. What i am having trouble with is what to do next. The instructions say to copy and paste it to options.js, but I cannot find that file anywhere (i assume I'm looking locally?) Then Im supposed to upload it to Lambda, but Im not actually sure what file Im supposed to upload. Sorry to be a pain...

GregRocket commented 7 years ago

@loftgren Just rename the file options.example.js to options.js

Then you are going to create a zip file called src.zip. Include in the zip file the options.js file along with index.js, AlexaSkill.js and the directory sonosProxy (along with all the files in sonosProxy)

loftgren commented 7 years ago

So are these to be downloaded to my mac, then uploaded in a zip file? When I try to download them they are a .html. Is that correct?

GregRocket commented 7 years ago

Download master.zip file and unzip master.zip to your computer. The files you need are contained in this zip file. https://github.com/rgraciano/echo-sonos/archive/master.zip

Once you unzip the master.zip file, the files you are looking for will be in the directory echos-sonos-master/lambda/src/ on your computer. They are not html files. The will all end in .js

loftgren commented 7 years ago

ok. making progress! I think I have that set... now Im looking for a place to enter my appid?

loftgren commented 7 years ago

Any idea where I enter that? It says to do so, but I find no area to enter appid or host.

chilloutboy commented 7 years ago

Still in the 'CODE' tab once you have uploaded your zip file, just below the code you see an Environment Variables section Enter APPID in the left hand side and on the right paste your Application ID from the Developer Console. Likewise enter HOST on the left below the APPID and your DNS address on the right

GregRocket commented 7 years ago

You will need to setup an Amazon AWS account. Then go to lambda to setup APPID. https://console.aws.amazon.com/lambda/

Once you've setup your lambda function, the first tab Code is where you enter environment variables. Scroll down to the bottom of the Code page and look for Environment variables section.

You will have to type in the information. You should see a field for Key and one for Value. For Appid you would type APPID in the Key field and your Amazon appid amzn1.echo-sdk-ams.appxxxxx in the Value field. You will need to add all the key and values needed. ADVANCED_MODE ture/false, USE_SQS true/false etc.

loftgren commented 7 years ago

Seems like I have it right, but I keep getting this message: Array.from requires an array-like object - not null or undefined any idea what that refers to?

chilloutboy commented 7 years ago

Hi GregRocket, we both answered the same question... I have only been able to play playlists, have you had much luck with radio stations, albums or individual tracks?

GregRocket commented 7 years ago

@loftgren Sorry I don't know what that message means. Did you follow all the instructions to complete the setup?

loftgren commented 7 years ago

Yes. Im sure i have it all correct, but it won't let me create the function... keep giving me that error.

loftgren commented 7 years ago

screen shot 2017-03-31 at 2 53 58 pm

GregRocket commented 7 years ago

@chilloutboy Yes I can play radio stations, sonos playlists and local playlists using preset.jsons. I can also ask for artist or album (although I don't use that feature much.)

loftgren commented 7 years ago

screen shot 2017-03-31 at 3 07 34 pm

GregRocket commented 7 years ago

@loftgren I'm not sure what that means. I would suggest you step away for a bit. Then read all the instructions again. Start from the beginning and just do the whole process again.

loftgren commented 7 years ago

ok thanks. I really appreciate your help!

chilloutboy commented 7 years ago

GregRocket so can you please just explain the custom slot types you have used... NAMES - All of your artists? PRESETS - Genres? SXMCHANNELS - ? SXMSTATIONS - Radio names or Sonos favorites radio names

Thanks

GregRocket commented 7 years ago

@chilloutboy Names - I just put in the default ones. I don't think this is needed much anymore. But if you have an artist that does not work, stick it in here.

PRESETS - Exact same name as preset.json For example is preset.json is named eagles.json then I put eagles in the list. I don't have generic preset for rock, pop etc. I only put the exact name of each on my preset.json files. In this example my eagles.json calls an amazon prime music station eagles radio. The preset.json, custom slot name and sonso favorite must all match exactly.

Some of my presets: all 80s - An Amazon Prime Station beatles - An Amazon Prime Station classic hits - An Amazon Prime Station classic rock - An Amazon Prime Station classic soft rock - MP3.m3u on my NAS box Disney's greatest - MP3.m3u on my NAS box eagles - An Amazon Prime Station easy pop - An Amazon Prime Station

I don't use SXM so I can't help you there, but I do use Amazon prime music and pandora. Just put the name you have in your sonos favorite for the radio station.

To search for an artist or album, I've only used that on my local mp3 files. But this should be the same method for some radio stations that are supported for search. I just issue the command "Alexa, ask sonos to change music to library." Then to play an artist "Alexa, ask sonos to play ARTIST NAME in the ROOM." If I ask for Rod Stewart and assortment of song from him come up, after a pause while the search is made, and start playing. When I'm done I issue the command "Alexa, ask sonos to change music to presets"

chilloutboy commented 7 years ago

Thanks Gregrocket that has really helped me. I will give it a go.

Thanks

chilloutboy commented 7 years ago

@GregRocket you are a star :-) I can now play library items, playlists and radio stations.

Also thanks @jzajac2 for all your help getting me through the install/configuration

GregRocket commented 7 years ago

@chilloutboy Awesome! 👍

rgraciano commented 7 years ago

@jzajac2 - definitely, please do feel free to submit a PR for README tweaks if you can see areas to be improved