goruck / alexa-ip-cam

Use Alexa's Smart Home Skill API with standalone IP cameras without needing cloud service.
MIT License
161 stars 26 forks source link

Alexsa Account Linking #5

Closed koensayr closed 5 years ago

koensayr commented 6 years ago

How do you handle the account linking required by Amazon's Camera Skill? It looks like it needs an OAUTH 2.0 endpoint. Thoughts?

goruck commented 6 years ago

Hey,

I just needed to provide the account linking info in my smart home skill as described here. My lambda endpoint code does not actually perform access token validation. So in essence my lambda code fakes out access to a camera device cloud service. Its a hack for sure but that's the whole idea with this project - to use Alexa's Smart Home Skill API with standalone IP cameras without needing cloud service.

Hope that answers your question. If not let me know.

Thanks.

Lindo

koensayr commented 6 years ago

Ah! I should have looked at the code a bit closer. So I do setup the skill as a templated video/camera skill and then just point the account linking at the Lamba function. I'll play around with it and add some comments here on this is. Then I can try putting together a PR with deeper documentation.

koensayr commented 6 years ago

How did you can an URI for the Lamba function? Did you just stick an API Gateway in front? I'm currently working on that part but cannot get past enabling the skill in the app. The API Gateway is still telling me 403 and not hitting Lamba yet

koensayr commented 6 years ago

Okay, I've got it all connected together. Now though I'm left with the Lamba function returning the following when I attempt to test it:

2018-06-26T22:33:42.935Z faecbbd4-7990-11e8-8dc2-1999af94f919 TypeError: Cannot read property 'header' of undefined at exports.handler (/var/task/index.js:320:30)

koensayr commented 6 years ago

I've got this all working now except if it actually displaying the camera. I ended up using the Login with Amazon (LWA) to handle the OAuth bits. Now though when I saw "Show me the Backyard Camera" it starts to load, but then I simply get a "beep beep" error. I'm not really sure where to go next. Is is possible to get device side logs @goruck

goruck commented 6 years ago

@koensayr by device side do you mean logs from the Live555 proxy and stunnel? I can get that but can you check your lambda cloudwatch logs to see if you are getting an entry like this after invoking the Alexa skill:

2018-06-28T01:14:09.856Z 0070c7bb-1769-4a89-b0bb-90c939f59de2 [DEBUG] Control Confirmation:
{
    "event": {
        "header": {
            "correlationToken": "AAAAAAAAAACkDgXwIdlvVMwW40cU/p8cDAIAAAAAAAAVaoTKiz4iiXE+xg1zxRO2c6kj8HWmzBMiybrAYsSUwx2YtYsAEbDFnCPFVBv5dSwhavAvZT60OiVid0t+hE5kq0rMlJHX1hsaTcBFoJcexVXhMn/+Rk7oRaHJoXOJDl43v1ponp1YaFXMhM6wtowm/x+oSPivystjE+neRX649dhAXFDM+0l00MQtw5XrywwOFYR/Es8k8+9RnAeIajfeRVO7GisAT517RG002xN3U5lUj2OKd3p6sP7Amb28K4XcgxXilwU3bgM9m1gLb2qxDnVIRYZVVMU49+IgdQx/cbPLrDFAGeDqIZRrU8z8r8bqEIKrwoFDZR+J4WMlCVVfbYgD9FwjSn5E/bNiUqiGsLwhj9pHU+Iuoj9H64FELGw/3uLpg1ZnN/eESaUcWh82YEXBy6SSK1d9Cdy6ZJIQQ3u4AqogBqZobMvar6v8YrYpZwxMiPF5XyFIj8PCkcF/7WdOB+bEwxU2zJrYCQLDTGVJIPoA8L2tNKx//MjW2XUEzsnJZO1aR4f+K1yzP2NYKltHtbW/fNlC8qM1VSV7MqSSn0ZfTPi1U1nrKt/kNcYAJ4W+5kDL/EC5s6mnPBTPS5iy1z1NiKFd7o8xXc0bRSR5TVenDSDbSElWc7onlaUOhuulFEuy507oHV4ZW+TCtqa9M0Ys/nlxSIaLsvAa8fqdA3BrWXAgjkpHPQ==",
            "messageId": "ee352596-1bcb-4dca-913a-d18664591240",
            "name": "Response",
            "namespace": "Alexa.CameraStreamController",
            "payloadVersion": "3"
        },
        "payload": {
            "cameraStreams": [
                {
                    "uri": "rtsp://cam.lsacam.com:443/proxyStream-1",
                    "resolution": {
                        "width": 1920,
                        "height": 1080
                    }
                }
            ]
        }
    }
}

If so then your lambda code is probably working Ok.

If that's Ok then try opening up the rtsp stream locally using VLC or another media player. We can go from there depending on what you find.

koensayr commented 6 years ago

Yes I see those messages in my CloudWatch logs so I feel confidant the Lamba is working correctly:

        "payload": {
            "cameraStreams": [
                {
                    "uri": "rtsp://192.168.1.10:88/videoMain",
                    "resolution": {
                        "width": 666,
                        "height": 375
                    }
                }
            ]
        }

I'm not using the Live555 or stunnel encoder because it appears my cameras can deliver RTSP natively. I noticed though perhaps it doesn't want to load because I'm not using SSL on the connection type? If thats a good hunch do you have any idea where the device (the Echo itself) would log or notify you about this?

goruck commented 6 years ago

I think I understand your problem - the port is wrong.

The Smart Home Camera API requires the feed to use TCP socket encryption on port 443. Looks like you are using port 88. If you can configure your camera to use port 443 it may work but that is normally used by https so you may have to redirect other services that use that port. Also this will only work for a single camera. In may case I have several which is why I used Live555 as to aggregate all the camera feeds then I used stunnel to map the Live555's rtsp port to port 443.

Try changing the port to 443 and let me know if that works!

koensayr commented 6 years ago

Its funny, I caught that too after I posted that and switched to port 443. Still the same result.

Funny enough I stumbled upon monoclecam.com. I get a little further and even tried using the proxy with them. I found this tip about Foscam Cameras so I tried the proxy work around. I get a little bit further but the video never comes up. In fact, the Echo Show kinda gets locked up and I have to power cycle it.

goruck commented 6 years ago

How are you encrypting the feed? Does your camera do that using TLS and if so how are the certs handled? The smart home camera API has some very specific requirements.

Can you elaborate on the echo lock up?

On Sun, Jul 1, 2018, 9:56 PM Josh bernstein notifications@github.com wrote:

Its funny, I caught that too after I posted that and switched to port 443. Still the same result.

Funny enough I stumbled upon monoclecam.com. I get a little further and even tried using the proxy with them. I found this tip about Foscam Cameras https://monoclecam.com/support/incompatible so I tried the proxy work around. I get a little bit further but the video never comes up. In fact, the Echo Show kinda gets locked up and I have to power cycle it.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/goruck/alexa-ip-cam/issues/5#issuecomment-401672479, or mute the thread https://github.com/notifications/unsubscribe-auth/ALkFIOES_C3oui17Jw6TcgNM2EnToHHVks5uCafkgaJpZM4UytY0 .

koensayr commented 6 years ago

I thought that perhaps the camera isn't handling the TLS properly and perhaps the port 443 is just in the clear. Poor assumption on my part.

Anyway, I've moved over to try to encrypt things through stunnel as you suggested but I'm not getting very far there. According to the stunnel logs I don't even see a connection attempt incoming.

When I was using the MonocleCam site I mentioned I got further and ultimately caused the device to lock up. The screen should change to say "connecting to camera" and then basically just get stuck there. Trying to wake the device with "Alexa" did nothing, and the button presses were seemingly ignore. If its interesting to you, I'd be happy to post a video.

goruck commented 6 years ago

With regards to your stunnel issues turn on debugging in its config file and send me a log. I'll have a look. You turn on debugging by un-commenting the following lines in your stunnel.conf:

; Some debugging stuff useful for troubleshooting
debug = 7
foreground=yes

Note that the certs used by stunnel have to be valid (not self signed) for the encrypted connection to work with the Alexa service.

Yes, please send me the video. I work at Amazon and want to make sure we track this down. The device should never lockup. Sorry about that.

koensayr commented 6 years ago

I'll get you a video this week. Perhaps you can hit me up on Chime? I'm at AWS @thejosh

goruck commented 6 years ago

thanks, i'll try chiming you and let me know how the stunnel debug went.

goruck commented 5 years ago

closing. handled offline.