Skip to content
This repository was archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
Merge branch 'dotenv'
Browse files Browse the repository at this point in the history
# Conflicts:
#	app.js
  • Loading branch information
stevenflesch committed Oct 2, 2020
2 parents 2ebe8dd + 8367e9d commit 0e34631
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 60 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
R2ATV_IP_ADDRESS=192.168.1.1
R2ATV_DISPLAY_TIME=10
R2ATV_API_TOKEN=
31 changes: 21 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ A `nodejs` application that acts as a bridge between `ring-client-api` and the [

![](https://raw.githubusercontent.com/stevenflesch/ring-to-android-tv/master/extras/sample-tv-shot.jpg)

## Updates

### v2.0.0 - Oct 01, 2020

- **BREAKING CHANGES**: Use of `token.txt` and script variables are deprecated. These values are now stored in a .env file. See `.env.example` for an example.

## Requirements

- Android TV
Expand All @@ -24,17 +30,22 @@ A `nodejs` application that acts as a bridge between `ring-client-api` and the [
> `cd ring-to-android-tv`

> `npm install`
6. Generate an API token and save it to `token.txt`. Copy the key value only, no quotes. *Note: keep this secret, as it allows complete access to your Ring account.*
6. Copy the .env.example file to .env to configure your installation.
> `cp .env.example .env`
7. Open `.env` in your editor and replace the `R2ATV_IP_ADDRESS` variable with the IP of your AndroidTV.
8. Generate an API token and save it to `.env`. Copy the key value only, no quotes. *Note: keep this secret, as it allows complete access to your Ring account.*
> `npx -p ring-client-api ring-auth-cli`
7. Test the script using `--test` flag.

> *Save token to `.env` line like so:*

> `R2ATV_API_TOKEN=`**MYAPITOKEN**
9. Test the script using `--test` flag.
> `node app.js --test`

>*Note: If you want to test a different camera, you can use a different camera by specifying a location,camera like `--test 0,0`. List your locations by typing `node app.js --list`.*
8. Configure `app.js` with your Android TV's IP address and change other options, if desired. *See configuration below.*
8. Run the application!
10. Run the application!
> `node app.js`
9. *TODO: persist app after server restarts with forever.js and crontab*
10. *TODO: Automatic updates with crontab and `git pull`*
11. *Optional:* Install the app as a service with instructions below.

#### ADB Shell over Network

Expand Down Expand Up @@ -71,8 +82,9 @@ To update the script, simply `cd` to the app directory and run `git pull`.

| Option | Explanation |
|:----------|:----------|
| `tvIpAddress` | *Address of the IP address of the Android TV running PiPup. Required.* |
| `displayTime` | *Time, in seconds, to display popup notifications.* |
| `R2ATV_IP_ADDRESS` | *Address of the IP address of the Android TV running PiPup. Required.* |
| `R2ATV_DISPLAY_TIME` | *Time, in seconds, to display popup notifications.* |
| `R2ATV_API_TOKEN` | *API Token used from Ring* |

## License & Contributions

Expand All @@ -82,8 +94,7 @@ This application is released under an MIT license.

### Contributions

Please submit contributions with a pull request, they are very welcome! A short list of needed enhancements are below:
- [x] ~~Ability to show notifications from multiple cameras and locations~~
Please submit contributions with a pull request, they are very welcome!

## Acknowledgements

Expand Down
13 changes: 7 additions & 6 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ const Ring = require('ring-client-api')
const fs = require('fs')
const request = require('request')
const { exit } = require('process')
require('dotenv').config()

// Configuration
const tvIpAddress = '192.168.1.11' // IP address of the Android TV you are running PiPup on
const displayTime = 12 // Display time for notifications, in seconds
const tvIpAddress = process.env.R2ATV_IP_ADDRESS // IP address of the Android TV you are running PiPup on
const displayTime = process.env.R2ATV_DISPLAY_TIME || 12 // Display time for notifications, in seconds

/**
* Returns the API token from `token.txt` or gracefully exits the script with error.
*/
function getApiToken() {
try {
return(fs.readFileSync(__dirname + '/token.txt').toString().trim()) // Grab plain-text token from token.txt
return(process.env.R2ATV_API_TOKEN.toString().trim()) // Grab plain-text token from .env file.
} catch(err) {
console.log('Unable to read API token from token.txt - ensure you have an API token before running the script.')
process.exit(-1)
console.log('Unable to read API token from .env file - ensure you have an API token before running the script.')
process.exit(1)
}
}

Expand Down Expand Up @@ -244,4 +245,4 @@ if(process.argv.includes('--test')) {
} else {
// Begin polling camera for events
startCameraPolling(true)
}
}
118 changes: 76 additions & 42 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Node application to send Ring API events/pictures to Android TV via PiPup",
"license": "MIT",
"dependencies": {
"ring-client-api": "^9.9.0",
"request": "^2.88.2"
"dotenv": "^8.2.0",
"request": "^2.88.2",
"ring-client-api": "^9.10.0"
}
}

0 comments on commit 0e34631

Please sign in to comment.