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

Login:
Pass:
 
 

Topic:
Prontoscript assistance. Repeated commands
This thread has 11 replies. Displaying all posts.
Post 1 made on Monday November 29, 2010 at 09:34
lscolman2
Long Time Member
Joined:
Posts:
July 2003
216
Hi,

I've nabbed this piece of code to use with my Vu+ (dreambox satellite receiver).

var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.0.3',80,3000);


The command to send the command to the box is below:-

socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")

What I need to be able to do is send multiple numbers to allow me to select channel numbers, ie. channel 112, needs to send 1, 1 and then 2.

Can anyone help me to modify the piece of code aove so that it sends the command three times?

I have tried repeating the command in the script, so

socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")
socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")
socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")

I have also tried running the whole script three times. Each time, I only get 1 command sent.

Sending the command from a web browser works fine.

This would really help me out.

Cheers, Lee
Post 2 made on Monday November 29, 2010 at 11:42
BluPhenix
Long Time Member
Joined:
Posts:
December 2008
371
To send something 3 times you just loop it:

for (i=0; i<3; i++) {
do whatever you want
}

So:
socket.onConnect = function()
{
var i;
for(i = 0 ;i < 3; i++) {
socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")
// System.delay(100); // maybe not needed
}
socket.close();
};

Try sending everything you mean before you close the connection because the HW may work in a way that when it sees the closing of the socket, it thinks the data it recieved is final.
OP | Post 3 made on Monday November 29, 2010 at 13:34
lscolman2
Long Time Member
Joined:
Posts:
July 2003
216
Hi Blu,

Sorry, I didn't mean that I wanted to repeat the same command each time. I need to send three commands, so for example channel 612 would be:-

var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /web/remotecontrol?command=6 HTTP/1.0\r\n\r\n")
System.delay(100)
socket.write("GET /web/remotecontrol?command=1 HTTP/1.0\r\n\r\n")
System.delay(100)
socket.write("GET /web/remotecontrol?command=2 HTTP/1.0\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.0.3',80,3000);

The above does not work, but that's where I am at.

I don't know enough about prontoscript to know where I'm going wrong. I wondered if the port was closing after it did the first command?

Any help would be most appreciated.

Cheers, Lee
Post 4 made on Monday November 29, 2010 at 15:21
BluPhenix
Long Time Member
Joined:
Posts:
December 2008
371
Whops, my bad.

Do you have any documentation of the device (particularly the control part?).

You could try adding the http command connection: close to see if it needs it:

"GET /web/remotecontrol?command=6 HTTP/1.0 Connection: close \r\n\r\n"

Will try to look more into it tomorrow.


Whoops, I just realised: Why do you need two threads for the same issue?
OP | Post 5 made on Monday November 29, 2010 at 16:11
lscolman2
Long Time Member
Joined:
Posts:
July 2003
216
Hi Blu,

I've opened this one to open it to a wider audience. I think the other thread may have just been read by people with a similar satellite receiver.

I'll give that close command a go, and let you know...

Cheers, Lee
Post 6 made on Monday November 29, 2010 at 18:26
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
if the device is using http 1.0 ( as you seem to indicate in the commands being sent) as opposed to http 1.1 then the connection is not persistant. That is, as soon as the server acknowedges the command received it closes the connection.

Ergo you have to re-connect for each number you wish to send. Just repeating the write will not work as the connection will have been closed.

You should wait for the reply to each command prior to sending the next command, that is Connect, send command, wait for reply, repeat the sequence
Post 7 made on Tuesday November 30, 2010 at 01:57
BluPhenix
Long Time Member
Joined:
Posts:
December 2008
371
Huh, nice spotting Barry, haven't noticed the HTTP 1.0.

The guides in the other thread don't mention which HTTP protocol should be used. But if the commands sent from a browser work, then it must work with 1.1 as Barry said, because browsers usually use the HTTP 1.1 protocol.

Also I don't remember what happens if you don't read the response, I have a little voice in my mind that is telling me that you first have to read the incoming data if you want to be able to send more data, but I'm not sure if you have to do this with the pronto or with some other device.

Iscolman, do what Barry said, might be the right tip.
OP | Post 8 made on Tuesday November 30, 2010 at 04:05
lscolman2
Long Time Member
Joined:
Posts:
July 2003
216
Do you gentlemen think this should do the job?

var socket = new TCPSocket(false);
socket.onConnect = function()
{
socket.write("GET /web/remotecontrol?command=6 HTTP/1.1\r\n\r\n")
socket.write("GET /web/remotecontrol?command=2 HTTP/1.1\r\n\r\n")
socket.write("GET /web/remotecontrol?command=2 HTTP/1.1\r\n\r\n")
socket.close();
};
socket.onClose = function()
{
};
socket.onIOError = function(e)
{
label = "Error: " + e;
};
socket.connect('192.168.0.3',80,3000);

I'll give it a go when I get home tonight.

Cheers, Lee
Post 9 made on Tuesday November 30, 2010 at 06:46
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
I would set up a socket.onData event handler, and issue the second and subsequent write commands from there. In that way you get the response from the unit first and then reissue. Just keep a state variable that starts at 0 and is incremented each time a write is issued. The first write is from the on connect and set the state to 1. At on data issue a command based on the value of the state variable and increment the state variable.

Or as a general case:

Have an array lets call it macroArray. Enter the strings for the write commands (data only, not the socket. Put them into array as strings using push, e.g. macroArray.push("GET /web/remotecontrol?command=6 HTTP/1.1\r\n\r\n"). Pull the command strings out using pop. That should make the array a LIFO Structure, so the first command to be executed should be the last command pushed in. Execute the command using socket.write(macroArray.pop). Execute the first command in the onConnect and all others in onData event handlers. When the array has a length of zero on entry to the onData handler do not issue the write but rather close the socket.

In this way you push your macro into the array and issue the connect. It then handles itself and this works for any macro of any length.
Post 10 made on Tuesday November 30, 2010 at 10:08
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,999
FWIW...

[Link: remotecentral.com]
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 11 made on Tuesday November 30, 2010 at 13:18
lscolman2
Long Time Member
Joined:
Posts:
July 2003
216
Hi,
The script above, using HTTP 1.1 works a treat. Just the job. Thanks folks!

Cheers, Lee
Post 12 made on Tuesday November 30, 2010 at 14:32
BluPhenix
Long Time Member
Joined:
Posts:
December 2008
371
Thank Barry, he is like The Dark Knight, he always saves the day. :)


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