Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

Commit

Permalink
Merged alisalama-master
Browse files Browse the repository at this point in the history
  • Loading branch information
alanreid committed Jan 3, 2017
1 parent f59dd28 commit 0cb91e4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 28 deletions.
23 changes: 16 additions & 7 deletions README.md
Expand Up @@ -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) {
Expand All @@ -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

Expand Down
15 changes: 0 additions & 15 deletions demo.js

This file was deleted.

35 changes: 35 additions & 0 deletions 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 + '!');
});
16 changes: 10 additions & 6 deletions lib/index.js
Expand Up @@ -7,13 +7,16 @@ var request = require('request'),
fs = require('fs'),
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 = {};
Expand Down Expand Up @@ -129,6 +132,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"'
}
});
Expand Down Expand Up @@ -172,8 +176,8 @@ Bravia.prototype.auth = function(callback) {

var that = this;

if(!this.hasCookie()) {

if(!this.hasCookie() && this.pskKey == "") {
this.makeAuthRequest();

var rl = readline.createInterface({
Expand Down Expand Up @@ -243,6 +247,6 @@ Bravia.prototype.updateCookieJar = function(callback) {
callback();
}

module.exports = function(ip, callback) {
return new Bravia(ip, callback);
module.exports = function(ip, pskkey, callback) {
return new Bravia(ip, pskkey, callback);
};

0 comments on commit 0cb91e4

Please sign in to comment.