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

Added in PSK authentication #8

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 + '!');
});
14 changes: 9 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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"'
}
});
Expand Down Expand Up @@ -171,7 +175,7 @@ Bravia.prototype.auth = function(callback) {

var that = this;

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

this.makeAuthRequest();

Expand Down Expand Up @@ -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);
};