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

Login:
Pass:
 
 

Page 2 of 2
Topic:
Prontoscript TCP HTTP command help please?
This thread has 25 replies. Displaying posts 16 through 26.
Post 16 made on Thursday May 15, 2014 at 15:37
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Try this.

var myCommand = "GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
host: 192.168.0.151\r\n
connection: close\r\n\r\n\r\n";

// todo - send myCommand
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 17 made on Saturday May 17, 2014 at 04:12
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
On May 15, 2014 at 15:37, Lyndel McGee said...
Try this.

var myCommand = "GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
host: 192.168.0.151\r\n
connection: close\r\n\r\n\r\n";

// todo - send myCommand

Hi Lyndel,

I'm struggling with this. I have added the port number after the IP address and pasted the following to a button, but its not turning the light on.

function send lightCommand {
var myCommand2 = "GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
host: 192.168.0.151:3480\r\n
connection: close\r\n\r\n\r\n";}

send lightCommand

I have also tried posting the code in the Actions Properties then calling it from a button press with

send lightCommand

Is the issue with how I am calling the function or could it be the http request isn't quit right?

Thanks

Steve
Post 18 made on Saturday May 17, 2014 at 12:23
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Sorry you are struggling. There are HTTP examples in the ProntoScript Dev Guide that illustrate alot of the above. Also, there are posts here in this forum that discuss usage of the Host HTTP Request Header as well as the Connection HTTP Request Header. Try a search here for HTTP 1.0 and you will likely find some other examples. ProntoScript is fairly easy. It is getting the strings right that you exchange with other equipment that can be difficult.

You don't put the port on the host line. You put that in your call to socket.connect.


Put a try/catch block around code in your functions and if an error is caught, log it using System.print.

This will tell you whether you have a syntax error or the request is not right.

Several years back I did a writeup on use of try/catch for debugging. Might want to try a search for that thread as well.

Last edited by Lyndel McGee on May 17, 2014 12:35.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 19 made on Saturday May 17, 2014 at 12:49
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
On May 17, 2014 at 12:23, Lyndel McGee said...
Sorry you are struggling. There are HTTP examples in the ProntoScript Dev Guide that illustrate alot of the above. Also, there are posts here in this forum that discuss usage of the Host HTTP Request Header as well as the Connection HTTP Request Header. Try a search here for HTTP 1.0 and you will likely find some other examples. ProntoScript is fairly easy. It is getting the strings right that you exchange with other equipment that can be difficult.

You don't put the port on the host line. You put that in your call to socket.connect.

Put a try/catch block around code in your functions and if an error is caught, log it using System.print.

This will tell you whether you have a syntax error or the request is not right.

Several years back I did a writeup on use of try/catch for debugging. Might want to try a search for that thread as well.

Ok will do. Thanks again.

Steve
Post 20 made on Saturday May 17, 2014 at 14:23
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
In your string, change the occurrences of ':' in the URL parameters to %3A

function send lightCommand {
var myCommand2 = "GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn%3Aupnp-org%3AserviceId%3ASwitchPower1&action=SetTarget&newTargetValue=1 HTTP 1.0\r\n
Host: 192.168.0.151\r\n
Connection: close\r\n\r\n\r\n";}

This is what is meant by URL encoding. Also note that I removed the : from the Host and also changed the casing on Host and Connection.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 21 made on Sunday May 18, 2014 at 03:58
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
Lyndel,

I tried your updated code but still no luck with it. However I took your advise and searched for HTTP 1.0. I experimented by tweaking some examples and success this code seems to work -

////////////////////////////////////////////
//
var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:SwitchPower1&action=SetTarget&newTargetValue=1 HTTP/1.1\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.0.151',3480);
//
//
/////////////////////////////////////////////

Moving on to my next part, are button sliders supported? It would be great if I could have a button slider that could dim a light. I have done a search but can't seem to find anything here. I gues I maybe out of luck?

Thanks for all your help.

Steve
Post 22 made on Sunday May 18, 2014 at 18:40
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
You can have an example of a slider from going to www.the-gordons.net as Barry published one a few years back that has 20 buttons and does a 5% increment.

This technique was done before onMove was added to ProntoScript. Also, there was a color picker example that someone posted here a while back. Might want to have a look at that script.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 23 made on Wednesday October 29, 2014 at 03:28
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
I gave up sometime ago trying to get a slider working with http commands to control my lighting, however I decided to try and give it another go. I downloaded 'Rick's Slider Control'

[Link: files.remotecentral.com]

Looking at Rick’s code there is an option to change the slider from a vertical slider to horizontal slider by changing dimmer orientation variable to a ‘0’ from the default ‘1’. I also rotated the images to horizontal and the slider demo seems to work ok apart from it not remembering its position when I exit the page and re-enter. If I change it back to vertical it remembers just fine. I must be missing something in the code to enable this position memory but I'm not sure what I am looking for.

For information, I want to use a dimmer scale of 0-100. In my copy of the code I changed all the ‘15’s in the code below to ‘100’

Any help would be much appreciated.

Many thanks

Steve

Rick’s Code-
-----------------------------------------------------------------------------------------------------
@author Rick
*/
// skeleton coded for speed no error checking
// add Dimmer.js to activity properties (PS libraries)
//call dslider from knob page properties(advanced) to initialise.
//call dslider from button properties(actions)
// check prontoscript tag names are consistant

var dir,// dimmer orientation 0 = horizontal 1 = verticle
gmin,gmax,// dimmer graphic extents
scale,// dimmer scale, this case is 0 - 15
res, lres,// knob scale position, last knob position
pos, irpage,// ir button tag, ir dim code page tag
lab;// dimmer label tag

function dslider(wk, wg, wl, wpd, hv){
var xp, yp, xk, yk;// knob position
// get dimmer graphic extents
lab = wl; dir = hv; irpage = wpd;
if(dir == 0){
gmin = wg.left;
gmax = wg.left + wg.width - wk.width;}
else{
gmax = wg.top + wg.height - wk.height;
gmin = wg.top;}
scale = (gmax - gmin) / 15;

// note setGlobal used here only on first use to initialise
// getGlobal thereafter to remember and set knob position on re-entry
if (System.getGlobal(wk.tag) == null) System.setGlobal(wk.tag , 8);
res = System.getGlobal(wk.tag);
if(dir == 0) wk.left = gmin + (scale * res);
else wk.top = gmin + (scale * (15 - res)); // scaled from bottom to top. remove 15 to reverse.
lab.label = res;
////
//get knob position
wk.onPress = function(x, y) {
xp = x; yp = y;
xk = this.left; yk = this.top;}
/////
//see which way knob moves and increment or decrement position
//and keep within bounds of dimmer graphic
//save knob scale position in res
//display integer res in our label
wk.onMove = function(x, y) {
if(dir == 0 ){ // horizontal
if((x - 3) > xp) xk +=3; else if((x+3) < xp) xk -=3;
if(xk > gmax) {xk = gmax; return ;}
if(xk < gmin) {xk = gmin; return ;}
this.left = xk ;
res = (xk - gmin) / scale; }
else{
if((y - 3) > yp) yk +=3; else if((y +3) < yp) yk -=3;
if(yk > gmax) {yk = gmax; return ;}
if(yk < gmin) {yk = gmin; return ;}
this.top = yk ;
res = 15 - ((yk - gmin) / scale) ; }

res = Math.round(res);
if(res == lres) return ;
lab.label = res;
lres = res;}
//////
//save knob position res for page re-entry

-------------------------------------------------------------------------------------

Last edited by Stealth on October 29, 2014 03:45.
Post 24 made on Thursday October 30, 2014 at 10:05
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
You mention orientation but I am not seeing such a variable in the code above.

See the comments in the code about the use of System.setGlobal and System.getGlobal. Maybe you forgot to code an onExit handler for your page to set the value into the global?

I think you are only showing us 1/3 of the code. ;-) Especially since the code you posted has comments at the top that talk about page scripts, etc...
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 25 made on Friday October 31, 2014 at 08:57
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
Hi Lyndel,

As always you are correct. my issue was in the page properties. I had the code detailed below in the properties of the page but I hadn't changed the ),1); to the necessary horizontal requirement of ),0);

dslider(widget("KNOB1"),widget("SG1"),widget("SL1"),page("DCP6"),1);
dslider(widget("KNOB2"),widget("SG2"),widget("SL2"),page("DCP8"),1);
dslider(widget("KNOB3"),widget("SG3"),widget("SL3"),page("DCP4"),1);
dslider(widget("KNOB4"),widget("SG4"),widget("SL4"),page("DCP5"),1);

I can confirm this is now remembering the state on re-entry. Thank you for pointing me in the right direction.

My last problem is to work out how I would parse the slider light level into the code below on release. In the code sample snipet newLoadlevelTarget=25

25 is the light level. With DeviceNum=3 being as it looks i.e. light ID number 3.

Any help would be much appreciated.

Many thanks

Steve


var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=25 HTTP/1.1\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.0.151',3480);
Post 26 made on Tuesday November 11, 2014 at 06:04
Stealth
Long Time Member
Joined:
Posts:
December 2003
72
Can anyone help me with my question below?

Thanks in advance

Steve

On October 31, 2014 at 08:57, Stealth said...
Hi Lyndel,

As always you are correct. my issue was in the page properties. I had the code detailed below in the properties of the page but I hadn't changed the ),1); to the necessary horizontal requirement of ),0);

dslider(widget("KNOB1"),widget("SG1"),widget("SL1"),page("DCP6"),1);
dslider(widget("KNOB2"),widget("SG2"),widget("SL2"),page("DCP8"),1);
dslider(widget("KNOB3"),widget("SG3"),widget("SL3"),page("DCP4"),1);
dslider(widget("KNOB4"),widget("SG4"),widget("SL4"),page("DCP5"),1);

I can confirm this is now remembering the state on re-entry. Thank you for pointing me in the right direction.

My last problem is to work out how I would parse the slider light level into the code below on release. In the code sample snipet newLoadlevelTarget=25

25 is the light level. With DeviceNum=3 being as it looks i.e. light ID number 3.

Any help would be much appreciated.

Many thanks

Steve

var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /data_request?id=lu_action&output_format=xml&DeviceNum=3&serviceId=urn:upnp-org:serviceId:Dimming1&action=SetLoadLevelTarget&newLoadlevelTarget=25 HTTP/1.1\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.0.151',3480);
Page 2 of 2


Jump to


Protected Feature Before you can reply to a message...
You must first register for a Remote Central user account - it's fast and free! Or, if you already have an account, please login now.

Please read the following: Unsolicited commercial advertisements are absolutely not permitted on this forum. Other private buy & sell messages should be posted to our Marketplace. For information on how to advertise your service or product click here. Remote Central reserves the right to remove or modify any post that is deemed inappropriate.

Hosting Services by ipHouse