From 20f232a6102bfc9c11c5427a9aa0a0172a143a9e Mon Sep 17 00:00:00 2001 From: Ali Salama Date: Sat, 9 Apr 2016 17:32:03 +0100 Subject: [PATCH 1/6] No longer requires authentication cookies, so allows for a permanent connection to the TV. Cookie method left in for completeness. --- README.md | 17 +++++++++++++---- cookies.json | 1 + demo.js | 9 +++++---- lib/index.js | 14 +++++++++----- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index c972916..c8404dc 100644 --- a/README.md +++ b/README.md @@ -6,10 +6,18 @@ Control your Sony Bravia TV using nodejs. #####Warning: I moved and I no longer own a Bravia TV. Unfortunately that means I can't maintain this project anymore :( I will do my best to help out with any issues you may encounter, but I won't be able to reproduce them. ### One time setup -* Turn on your TV + +#### TV Setup +* Turn on your TV +* On the TV go to Settings > Network > Home network setup > Remote device/Renderer > On +* On the TV go to Settings > Network > Home network setup > IP Control > Authentication > Normal and Pre-Shared Key +* On the TV go to Settings > Network > Home network setup > Remote device/Renderer > Enter Pre-Shared Key > 0000 (or whatever you want your PSK Key to be) +* On the TV go to Settings > Network > Home network setup > Remote device/Renderer > Simple IP Control > On + +#### Node Setup * Find your TV's IP address * Run `npm install` -* Edit the `demo.js` file with your TV's IP +* Edit the `demo.js` file with your TV's IP * Run `node demo.js` * If you're running this script for the first time, you will be asked to enter a 4-digit code shown on your TV @@ -20,7 +28,8 @@ This library handles the authentication process with the TV, saving the generate ### Usage ``` -bravia('192.168.1.100', function(client) { +// Accepts two parameters, IP and PSKKey +bravia('192.168.1.100', '0000', function(client) { // List available commands client.getCommandNames(function(list) { @@ -44,7 +53,7 @@ The available commands may vary from model to model. I'm getting the following o I've also added a `PowerOn` command to that list, that implements WakeOnLAN to turn your TV on. ### TODO -* Clean up the code a bit +* Clean up the code a bit * TV auto-detection (via UPnP or similar) * Shortcut commands diff --git a/cookies.json b/cookies.json index e69de29..c4e7319 100644 --- a/cookies.json +++ b/cookies.json @@ -0,0 +1 @@ +{"192.168.1.100":{"/sony/":{"auth":{"key":"auth","value":"8D90B77C88E2A80B4D83373B96F60B53732EF887","expires":"2016-04-23T15:54:22.000Z","maxAge":1209600,"domain":"192.168.1.100","path":"/sony/","hostOnly":true,"creation":"2016-04-09T15:48:47.272Z","lastAccessed":"2016-04-09T16:04:04.095Z"}}}} \ No newline at end of file diff --git a/demo.js b/demo.js index 8e77fd9..9e968df 100644 --- a/demo.js +++ b/demo.js @@ -1,12 +1,13 @@ var bravia = require('./lib'); -bravia('192.168.1.100', function(client) { + +bravia('192.168.1.100', '0000', function(client) { // List available commands - client.getCommandNames(function(list) { - console.log(list); - }); + // client.getCommandNames(function(list) { + // console.log(list); + // }); // Call a command client.exec('Netflix'); diff --git a/lib/index.js b/lib/index.js index 4432888..be2ff63 100644 --- a/lib/index.js +++ b/lib/index.js @@ -6,13 +6,16 @@ var request = require('request'), wol = require('wake_on_lan'), arpTable = require('./arp_table.js'); -var Bravia = function(ip, callback) { +// Now accepts a PSKKey. No longer requires authentication cookies, so allows for a permanent connection. +// Cookie method left in for completeness +var Bravia = function(ip, pskkey, callback) { var that = this; this.ip = ip; this.device = ip; - this.nickname = 'bravia-control'; + this.nickname = 'Pi'; + this.pskKey = pskkey; this.uuid = uuid.v1(); this.cookieJar = request.jar(new FileCookieStore('cookies.json')); this.commands = {}; @@ -128,6 +131,7 @@ Bravia.prototype.makeCommandRequest = function(code, callback) { body: body, headers: { 'Content-Type': 'text/xml; charset=UTF-8', + 'X-Auth-PSK' : this.pskKey, 'SOAPACTION': '"urn:schemas-sony-com:service:IRCC:1#X_SendIRCC"' } }); @@ -171,7 +175,7 @@ Bravia.prototype.auth = function(callback) { var that = this; - if(!this.hasCookie()) { + if(!this.hasCookie() && this.pskKey == "") { this.makeAuthRequest(); @@ -223,6 +227,6 @@ Bravia.prototype.request = function(options, callback) { }; -module.exports = function(ip, callback) { - return new Bravia(ip, callback); +module.exports = function(ip, pskkey, callback) { + return new Bravia(ip, pskkey, callback); }; From 087a298647f83ac1f27fbf923c3f30f6654d5a61 Mon Sep 17 00:00:00 2001 From: Ali Salama Date: Mon, 11 Apr 2016 18:38:11 +0100 Subject: [PATCH 2/6] Updated Markdown --- README.md | 11 +++++------ demo.js | 6 ++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index c8404dc..9cced95 100644 --- a/README.md +++ b/README.md @@ -3,27 +3,26 @@ Bravia Remote Control Control your Sony Bravia TV using nodejs. -#####Warning: I moved and I no longer own a Bravia TV. Unfortunately that means I can't maintain this project anymore :( I will do my best to help out with any issues you may encounter, but I won't be able to reproduce them. - ### One time setup -#### TV Setup +##### TV Setup * Turn on your TV * On the TV go to Settings > Network > Home network setup > Remote device/Renderer > On * On the TV go to Settings > Network > Home network setup > IP Control > Authentication > Normal and Pre-Shared Key * On the TV go to Settings > Network > Home network setup > Remote device/Renderer > Enter Pre-Shared Key > 0000 (or whatever you want your PSK Key to be) * On the TV go to Settings > Network > Home network setup > Remote device/Renderer > Simple IP Control > On -#### Node Setup +##### Node Setup * Find your TV's IP address * Run `npm install` -* Edit the `demo.js` file with your TV's IP +* Edit the `demo.js` file with your TV's IP & PSK Key * Run `node demo.js` * If you're running this script for the first time, you will be asked to enter a 4-digit code shown on your TV ### Authentication -This library handles the authentication process with the TV, saving the generated cookie as a file that can be accessed in later executions. If you need to refresh the credentials for some reason, just remove any content from the `cookies.json` file. +New Method - If you provide a PSK key to the function it will use that to authenticate rather than going through the old method. +Old Method - This library handles the authentication process with the TV, saving the generated cookie as a file that can be accessed in later executions. If you need to refresh the credentials for some reason, just remove any content from the `cookies.json` file. ### Usage diff --git a/demo.js b/demo.js index 9e968df..c5658c5 100644 --- a/demo.js +++ b/demo.js @@ -1,16 +1,14 @@ var bravia = require('./lib'); - +// IP & PSK Key bravia('192.168.1.100', '0000', function(client) { // List available commands // client.getCommandNames(function(list) { // console.log(list); // }); - // Call a command client.exec('Netflix'); -}); - +}); \ No newline at end of file From 8e73e33723bc552374efd96c6a14fb4252d301ae Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 11 Apr 2016 18:38:51 +0100 Subject: [PATCH 3/6] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9cced95..49af87f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Control your Sony Bravia TV using nodejs. ### Authentication -New Method - If you provide a PSK key to the function it will use that to authenticate rather than going through the old method. +New Method - If you provide a PSK key to the function it will use that to authenticate rather than going through the old method. + Old Method - This library handles the authentication process with the TV, saving the generated cookie as a file that can be accessed in later executions. If you need to refresh the credentials for some reason, just remove any content from the `cookies.json` file. From 0fc58bb6f14b63f472c3b56da930de94ae9ba552 Mon Sep 17 00:00:00 2001 From: Ali Salama Date: Mon, 11 Apr 2016 18:40:11 +0100 Subject: [PATCH 4/6] Removed Cookies File --- README.md | 3 ++- cookies.json | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9cced95..49af87f 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,8 @@ Control your Sony Bravia TV using nodejs. ### Authentication -New Method - If you provide a PSK key to the function it will use that to authenticate rather than going through the old method. +New Method - If you provide a PSK key to the function it will use that to authenticate rather than going through the old method. + Old Method - This library handles the authentication process with the TV, saving the generated cookie as a file that can be accessed in later executions. If you need to refresh the credentials for some reason, just remove any content from the `cookies.json` file. diff --git a/cookies.json b/cookies.json index c4e7319..e69de29 100644 --- a/cookies.json +++ b/cookies.json @@ -1 +0,0 @@ -{"192.168.1.100":{"/sony/":{"auth":{"key":"auth","value":"8D90B77C88E2A80B4D83373B96F60B53732EF887","expires":"2016-04-23T15:54:22.000Z","maxAge":1209600,"domain":"192.168.1.100","path":"/sony/","hostOnly":true,"creation":"2016-04-09T15:48:47.272Z","lastAccessed":"2016-04-09T16:04:04.095Z"}}}} \ No newline at end of file From 67969330854034567730818e5f008edfff3fb11a Mon Sep 17 00:00:00 2001 From: Ali Date: Mon, 11 Apr 2016 18:41:00 +0100 Subject: [PATCH 5/6] Update cookies.json --- cookies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookies.json b/cookies.json index c4e7319..8b13789 100644 --- a/cookies.json +++ b/cookies.json @@ -1 +1 @@ -{"192.168.1.100":{"/sony/":{"auth":{"key":"auth","value":"8D90B77C88E2A80B4D83373B96F60B53732EF887","expires":"2016-04-23T15:54:22.000Z","maxAge":1209600,"domain":"192.168.1.100","path":"/sony/","hostOnly":true,"creation":"2016-04-09T15:48:47.272Z","lastAccessed":"2016-04-09T16:04:04.095Z"}}}} \ No newline at end of file + From 385c610bfadf6c1296df68ba8cd77ee000b80f6a Mon Sep 17 00:00:00 2001 From: Ali Salama Date: Tue, 16 Aug 2016 17:20:00 +0100 Subject: [PATCH 6/6] Express server rejig --- http-bravia-echo.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 http-bravia-echo.js diff --git a/http-bravia-echo.js b/http-bravia-echo.js new file mode 100644 index 0000000..3148ce5 --- /dev/null +++ b/http-bravia-echo.js @@ -0,0 +1,35 @@ +const http = require('http') +var express = require('express'); +var bravia = require('./lib'); + +var app = express(); + +const port = 5006 +const tvIP = '192.1.168.100' +const pskKey = '0000' + +// Set up the server +app.get('/:intent', function (req, res) { + + // Get the intent + var intent = req.params.intent; + + // Confirm the intent + console.log('Running ' + intent); + + // Call the Bravia function. + bravia(tvIP, pskKey, function(client) { + + // Call a command + client.exec(intent); + + // Send back the ok status. + res.sendStatus(200); + + }); +}); + +// Set up the port listener +app.listen(port, function () { + console.log('Example app listening on port ' + port + '!'); +}); \ No newline at end of file