Your Universal Remote Control Center
RemoteCentral.com
Philips Pronto Professional Forum - View Post
Up level
Up level
The following page was printed from RemoteCentral.com:

Login:
Pass:
 
 

Original thread:
Post 4 made on Saturday September 28, 2013 at 05:15
bibi-12
Long Time Member
Joined:
Posts:
February 2008
16
Hi

Here is my code that turn on the light:


var socket = new TCPSocket(false);
var result="";

socket.connect('192.168.0.158', 80, 3000);
var JSON_on='{"on": true,"bri":144,"hue":13122,"sat":211,"ct":467,"xy": [0.5119,0.4147]}';

function getInfos(commands)
{
socket.write('PUT /api/newdeveloper/groups/all/action HTTP/1.1\r\nContent-Length: '+commands.length+'\r\n\r\n'+commands);

}

socket.onConnect = function()
{
getInfos(JSON_on);
};

socket.onData = function()
{

};

socket.onClose = function()
{
socket = null
}

socket.onIOerror = function() {
System.print("error");
try {
socket.close()
socket = null
} catch(e) {}
}


You have to create a new user before :


var socket = new TCPSocket(false);

socket.connect('192.168.0.158', 80, 3000);

function setUser()
{
socket.write('POST /api HTTP/1.1\r\nContent-Length: 64\r\n\r\n{"devicetype":"test user","username":"newdeveloper"}');
}

socket.onConnect = function()
{
setUser();
};

socket.onData = function()
{
result += socket.read();
};

socket.onClose = function()
{
var resultStartIndex =result.indexOf("\r\n\r\n");
var jsonData = result.substring(resultStartIndex+4);
}


Hosting Services by ipHouse