diff --git a/README.md b/README.md index c972916..49af87f 100644 --- a/README.md +++ b/README.md @@ -3,24 +3,33 @@ 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 -* 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 & 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 ``` -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/demo.js b/demo.js deleted file mode 100644 index 8e77fd9..0000000 --- a/demo.js +++ /dev/null @@ -1,15 +0,0 @@ - -var bravia = require('./lib'); - -bravia('192.168.1.100', function(client) { - - // List available commands - client.getCommandNames(function(list) { - console.log(list); - }); - - // Call a command - client.exec('Netflix'); - -}); - 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 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); };