Proxy your Nest Camera through rtsp-simple-server so you can view it on any RTSP reader
Project description
google_nest_camera_proxy
Proxy your Nest Camera through mediamtx
so you can view it on any RTSP reader.
How Google Nest Cameras Work
Unfortunately, Google does not let you just connect to an RTSP stream, or even and RTSPS string, and read your cameras. It is much more complicated than that. There are a few hoops that you have to jump through:
- Go through the Google Device Access Registration Process
- Get your Google Authentication Tokens
- Create your configuration files
- Install mediamtx
- Run the google-nest-camera-proxy application
Once this process is running what it does is reaches out to Google and gets an authentication token for the RTSPS stream, however that token only lasts for 5 minutes. It also includes an extension token, and this code will extend the token every 4 minutes so that you can record a continuous stream.
Google Device Access Registration Process
This is a fairly onerous process, so make sure to read the details before you begin. (There is some more nice documentation of going through the process with screenshots at https://geoffhudik.com/tech/2023/03/04/trying-google-nest-api-with-postman-and-python/)
The biggest roadblock is that access to this API requires registering with Google for Device Access https://developers.google.com/nest/device-access/registration. This has a one time $5 fee.
The documentation https://developers.google.com/nest/device-access/get-started walks you through the rest of the process.
I'm not going to cover all the details on how to get this done, because it is documented better elsewhere. Some addition documentation from Google about using their APIs is here:
- https://developers.google.com/nest/device-access/authorize
- https://developers.google.com/nest/device-access/use-the-api
- https://developers.google.com/nest/device-access/api/thermostat
Basic Instructions
These instructions were taken from the python-google-nest package (https://pypi.org/project/python-google-nest/) which provides the underlying libraries that I use to connect to the cameras. At a high level it involves:
- Making sure your Nest devices are linked to your Google account
- Set up GCP (Google Cloud Platform) account https://console.cloud.google.com/
- Set up a new GCP project
- Create an Oauth landing page and add your email as a test user
- Enable the Smart device management API
- Create an Oauth credential with the settings called from web server and https://www.google.com as the authorized redirect URI. Note the client ID and secret from this step.
- In https://console.nest.google.com/device-access create a new project and add oauth client ID from step 3.3
- Follow the series of queries in https://developers.google.com/nest/device-access/authorize to authorize devices. Note This step handled by this library.
Be careful as you follow along the guide in https://developers.google.com/nest/device-access/get-started, since you're dealing with so many similar accounts and keys it can be easy to mix something up, and you won't get particularly useful errors.
You should end up with the following pieces of information:
-
project_id : ID of the project you created in https://console.nest.google.com/device-access
-
client_id : value from setting up OAuth in https://console.cloud.google.com/ project
-
client_secret : value from setting up OAuth in https://console.cloud.google.com/ project
You will need those values in the next section.
Configuration
Most of the configuration lives in a configuration file. Below is a sample file:
[AUTH]
client_id = MYCLIENTID
client_secret = MYSECRET
project_id = MYPROJECTID
access_token_cache_file = /Users/ME/.config/nest/token_cache
[RTSP_SERVER]
executable = /usr/local/bin/mediamtx
config_filename = /Users/ME/.config/nest/rtsp.yml
client_id : This is the client_id from your project (from the credentials page on the Google console)
client_secret : The client secret (from the credentials page on the Google console)
project_id : The project ID (from the project page on the Google console)
access_token_cache_file : Where the token cache is stored
executable
: The location you installed the mediamtx
executable.
config_filename
: The location of the mediamtx
configuration file. This program adds all the cameras to the configuration file
Authentication
As part of the pyhon-google-nest package installation that is a dependency of this project, it creates a nest
application. The first time you run nest show
it will tell you to go to a URL (https://nestservices.google.com/partnerconnections with some parameters), and then you will step through selecting and authorizing the cameras that you want to stream. When you finish this process your browser will have a URL that looks like https://www.google.com/?state=SOME_STATE_VALUE&code=SOME_AUTHENTICATION_CODE&scope=https://www.googleapis.com/auth/sdm.service that you need to copy and paste into the callback, which is then stored in the ~/.config/nest/token_cache file.
Installation
- You need to install
mediamtx
, which you can download at https://github.com/bluenviron/mediamtx. This is the rtsp proxy that I use to translate from Google RTSPS to RTSP. Make a note of where you install it for the configuration file - Install this module
$ pip install google_nest_camera_proxy
- Edit the configuration file, whose default location is
~/.config/nest/config
. See the Configuration section above for the details.
Usage
Usage: google_nest_camera_proxy [OPTIONS]
Configures the proxy rtsp server, and keeps it updated
Options:
-c, --configuration-file PATH Where the configuration for this program is located
-d, --debug Turn on debugging output
--help Show this message and exit.
mediamtx
Configuration
mediamtx
comes with a default configuration file that you can leave alone except for changing a few parameters. The only ones you have to change are readUser
and readPass
. You should put in a username and password, and those will need to be provided to the program that reads the camera.
In addition, mediamtx
provides a lot of options that you won't need, so you can turn them off. This is optional, but here are my settings for these fields:
protocols: [tcp]
rtmp: no
hls: no
webrtc: no
When you run google-nest-camera-proxy
it regularly modifies the mediamtx
configuration file, adding the camera configuration to the bottom of it. Do not edit below this line"
# NEST EDITS BELOW -- DO NOT EDIT THIS LINE OR BELOW
Configuring SecuritySpy
I have found SecuritySpy (https://bensoftware.com/securityspy/) the best product to view and record cameras. To configure SecuritySpy to view the cameras:
- Open Settings in SecuritySpy
- Go to the Cameras tab
- On the bottom left, hit the
+
and selectAdd Network Device
- In the
Address
box, put the IP address of the box that is running themtxmedia
server. In my case, I use 127.0.0.1, since both the server and SecuritySpy are running on the same host - Unless you've changed the
rtspAddress
parameter in themediamtx.yml
file, put8554
in theRTSP port
box. - Select
Manual Profile
from theProfile
dropdown. - If you look in the
mediamtx.yml
file at the bottom, there are lines that look like this. The tag is the name of the camera, and the source is the rtsps stream that changes regularly. Use the name in the file as the name of the camera, and put it in theRequest
box.
Backyard:
source: rtsps://stream-ue1-bravo.dropcam.com:443/sdm_live_stream/CiUA2vuxr2D61w4Y5ZU2awZvBxZoVD5zE-WgFM5ofLJiMML9NnXLEnEAEGF6Sh1PFqMRG4ynOX1qGu4MgBGjmBwDHgWpkCsHKWybOA?auth=g.0.eyJraWQiOiIyMzhiNTUxZmMyM2EyM2Y4M2E2ZTE3MmJjZTg0YmU3ZjgxMzAzMmM4IiwiYWxnIjoiUlMyNTYifQ.eyJpc3MBhaOhZ0Y5utipHFESKsG4499KfxIs_xuQ8HF1f6vzicaQ9zBGu3yFAWq6bx5hkd5rcrJRmRDjTgfKO96fy9UIYZZAmJptW9r8KGw
FrontDoor:
source: rtsps://stream-us1-foxtrot.dropcam.com:443/sdm_live_stream/CiUA2vuxr32E11B1alS1QRyq7w4mwEX8NRJEhMnJ_m2mTO9EiXXCEnEAEGF6SmAHpELf7bUIco7Dx3enLdzFi5I?auth=g.0.eyJraWQiOiIyMzhiNTUxZmMyM2EyM2Y4M2E2ZTE3MmJjZTg0YmU3ZjgxMzAzMmM4IiwiYWxnIjoiUlMyNTYifQ.eyJpc3MiOiJuZXN0LXNlY3VyaXR5LWF1dGhwcm94eSIsInN1YiI6Im5lc3RfaWQ6bmVzdC1waG9lbml4LXByb2Q6MTQxNDQwMSIsInBvbCI6IjNwLW9hdXRoLXNjb3BlLUFQSV9TRE1fU0VSVklDNzfcmq51D5VEk8P8ksPEeUNld-xl7BgO0844T-FjXMk7MKqMDYoum6qwYYwtwVGSP5V0KkMgg50E8PP_rUfm6bKp4KG2i50PGxcNOWFi2Uz0EVH1Q8rmCfX6TWHJb-n3I9I2XH6zv3Z-zjLba7fxvSdgmMjPgRfEF61xNOwnOkja3lqva7I6cWkw
- Click
Apply Preferences
and in just a few minutes it should start receiving the video.
Contributing
Interested in contributing? Check out the contributing guidelines. Please note that this project is released with a Code of Conduct. By contributing to this project, you agree to abide by its terms.
License
google_nest_camera_proxy
was created by Xev Gittler. It is licensed under the terms of the MIT license.
Credits
google_nest_camera_proxy
was created with cookiecutter
and the py-pkgs-cookiecutter
template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file google_nest_camera_proxy-0.9.11.tar.gz
.
File metadata
- Download URL: google_nest_camera_proxy-0.9.11.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b282b415dcbde5600f30f50a2e861d208e007896e1a29040b3bd7b02adad2937 |
|
MD5 | bb98d81e2f401d9d7bfed644ddbf0004 |
|
BLAKE2b-256 | 9d0e95f277413724e1131c277ad9012fc49eaa5d3cbdd5e0c79a3522a7936a8c |
File details
Details for the file google_nest_camera_proxy-0.9.11-py3-none-any.whl
.
File metadata
- Download URL: google_nest_camera_proxy-0.9.11-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91fd228be8deae61a1852df81a7ff263c6f3da882204a1c78a70257b4956bb4c |
|
MD5 | 778931832908ae9d12bbcdb041a23feb |
|
BLAKE2b-256 | 0775c7878c936b2a5758d761d87a5d435a77e8a7cb775d7a01be501121f579c6 |