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 1 of 2
Topic:
Pronto Script for tcp socket
This thread has 21 replies. Displaying posts 1 through 15.
Post 1 made on Wednesday September 8, 2010 at 05:10
mon
Long Time Member
Joined:
Posts:
June 2010
11
var socket = new TCPSocket(true);
socket.connect("192.168.1.15",port num,3000);
socket.write("##########");
socket.close();

When I use this code to command and control the lighting device via network
lights on and off can be done.

But I want to get back the Lights Status from the device via the network.
( Which light is on )

Though I have the lighting command supposed to receive back from the device, I can't recall it inside the script.

Is there any idea?
can i use
socket.read()
or
socket.onData = function()
Post 2 made on Wednesday September 8, 2010 at 11:58
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Maybe, but no idea since you did not mention what lighting equipment you are using.

Respectfully... Are we supposed to be mind readers? I suspect that you might also ask for more information to be able to provide an answer to a customer.

And yes, you can use socket.read() inside an asynchronous callback of your OnData() function. The Dev Guide offers an example of asynchronous socket communication to read data from google or yahoo via http on port 80.

The RSS reader provided by Philips also has an example of this, albeit a bit more complicated where they process XML received via http protocol using asynchronous socket with callbacks.

Last edited by Lyndel McGee on September 8, 2010 12:41.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Wednesday September 8, 2010 at 20:21
Barry Gordon
Founding Member
Joined:
Posts:
August 2001
2,157
Every man has the wit to know and the will to learn, but the key to knowledge is the open book.

In this case the Developers Guide. You are asking very basic questions which are covered with examples in the developers quide.

Lyndel is being very nice to you.
Post 4 made on Wednesday September 8, 2010 at 20:40
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
But the reality is that without knowing the vendor nor the protocol, one cannot ascertain what a message might look like or how you might need to write the script.

For example, the example posted was to connect a socket and then do a write to the socket. If the socket is synchronous, as it is in the example, it might be so simple (but not likely or the best approach as there is likely a time lag waiting for data) to write the following:

// assumes previous connect completed.
socket.write(command to query device);
var data = socket.read();
socket.close();

However, asynchronous socket communication is the preferred way to do this and therefore, I pointed to several examples where this has indeed been done.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 5 made on Wednesday September 8, 2010 at 22:29
mon
Long Time Member
Joined:
Posts:
June 2010
11
Do let me say Sorry for incomplete info

var socket= new TCPSocket(false);
socket.connect("192.168.10.35",8005,3000);
socket.onConnect = function()
{
socket.write("192.168.10.25",8005,3000);
};
var result=" ";
socket.onData = function()
{
result+=socket. read();

};
if (result== "05380001013F")
{
socket.write("\\053801007901\r");
}
else
{
socket.write("\\053801000101\r");
}
socket.close();
socket.onIOError = function(e)
{
label1 = "socket error:"+e;
};


in the above code --- "05380001013F" is the status(i.e the light is being off) i need to get back from the CBus PCI interface

("\\053801007901\r") is the On Command for light
("\\053801000101\r" ) is the Off Command for light

By using this code I can talk to the CBus PCI .
But still can't do the On/Off operation after checking the status with if() {} else{}
I am a quite new to pronto script area ( the above codes refer to the prontoscript developer guide)
Is there anything I' m missing out ?

Thanks in advance
Post 6 made on Thursday September 9, 2010 at 00:06
Guy Palmer
Active Member
Joined:
Posts:
June 2008
648
mon,

You don't say whether you are using wired or wireless CBus but, in any event, the code "05380001013F' is not one that I recognise for feedback. In my CBus/pronto implementation, I only get feedback if I specifically request it. I do this by sending "\\05FF0073073800\r" (wired lights) or "\\03FD09FF73073800\r" (wireless lights). I then get back a string which I analyse using the published CBus message formats to understand which of my lights are on/off, which I then use in my Prontoscript if statements to do the appropriate toggle.

The other difference between what I do and what you seem to be doing is that I separate the receiving of feedback and the sending of commands. In other words, my logic is:

1. Enter the activity and initiate a loop which requests feedback every 30 seconds.

2. Whenever I press a toggle button, look at the current status of the corresponding light, toggle the light on/off and toggle the status accordingly.

This means that, when turning the light on/off (in step 2), I don't have to wait for any feedback on current status because that has already been obtained from my loop (in step 1).

Finally, your commands don't seem to include a checksum at the end and, given this, I'm a bit surprised that they work at all.
OP | Post 7 made on Thursday September 9, 2010 at 02:32
mon
Long Time Member
Joined:
Posts:
June 2010
11
@ Guy Palmer

How can i check the feedback get back from CBus PCI? Mine is wired connection
Post 8 made on Thursday September 9, 2010 at 04:31
Guy Palmer
Active Member
Joined:
Posts:
June 2008
648
I'm not quite sure what you are asking.

You send "\\05FF0073073800\r" via a Socket.write, for example:

Socket.onConnect = function ()
{
Socket.write(SendString);
};

Then you receive the feedback via a Socket.onData, for example:

Socket.onData = function ()
{
Response += Socket.read();
while(Response.indexOf("\r") != -1)
{
StringLen = Response.indexOf("\r");
ReceiveString = Response.substring(0,StringLen);
}
};

Then you look at the data that you have received and decode it using the published CBus message formats.
OP | Post 9 made on Thursday September 9, 2010 at 07:39
mon
Long Time Member
Joined:
Posts:
June 2010
11
My Question is How and where i can check the return data that I have received

I am really lost ...

thanks for your reply
Post 10 made on Thursday September 9, 2010 at 09:04
Guy Palmer
Active Member
Joined:
Posts:
June 2008
648
On September 9, 2010 at 07:39, mon said...
My Question is How and where i can check the return data that I have received

Yes, that is the question that my answer above was trying to address. In that answer, the return data is held in the variable ReceiveString. OTTOMH I can't remember the CBus wired message format but let's assume that characters 18-21 give light number 1's status, with "5555" meaning it is on and AAAA meaning it is off. Then you could do something like:

Status = ReceiveString.substring(17,17+4) ;
switch (Status)
{
case "5555": SendString="\\053801000101\r"; break;
case "AAAA": SendString="\\053801007901\r"; break;
}
Socket.write(SendString);
Post 11 made on Thursday September 9, 2010 at 11:53
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
You must read from the socket and analyze the data inside the OnData function. Please see the Dev Guide for additional examples.

You posted this:

var socket= new TCPSocket(false);
socket.connect("192.168.10.35",8005,3000);
socket.onConnect = function()
{
socket.write("192.168.10.25",8005,3000);
};
var result=" ";
socket.onData = function()
{
result+=socket. read();

};
if (result== "05380001013F")
{
socket.write("\\053801007901\r");
}
else
{
socket.write("\\053801000101\r");
}
socket.close();
socket.onIOError = function(e)
{
label1 = "socket error:"+e;
};


Which should look like this instead - Processing code moved inside the OnData and obvious bugfix in connect - I have also taken liberties of pointing out what I believe may be potential problems you will encounter:


var result=""; // note change to empty string.
var socket= new TCPSocket(false);
socket.connect("192.168.10.35",8005,3000);
socket.onConnect = function()
{
result = ""; // reset buffer.
socket.write("stringtosend");
};
socket.onData = function()
{
result+=socket. read();
// Note that this if clause moved inside of the function.
// Note that result may have trailing Carriage Return and if so, this clause will never report true.
if (result== "05380001013F")
{
socket.write("\\053801007901\r");
}
else
{
// you may have to account for incomplete data here and not do this write.
socket.write("\\053801000101\r");
}
socket.close();

};

socket.onIOError = function(e)
{
// Is this a bug? Presume label1 is a widget so may need to be label1.label
label1 = "socket error:"+e;
};
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 12 made on Thursday September 9, 2010 at 19:52
Guy Palmer
Active Member
Joined:
Posts:
June 2008
648
mon,

Several comments.

First, whilst your code logic, as amended by Lyndel, might well work, it will make your toggle button extremely sluggish. This is because, on pressing the button, it has to first request status feedback and then receive/analyse the reply before sending the approprate on/off command. Because of this, as per my first response in this thread, I strongly recommended that you separate these two things. As I know from my own CBus implementation, this makes the toggle buttons execute almost instantaneously.

Second, the format of the CBus feedback messages is not exactly simple, and there are differing formats depending on what mode you are in (e.g. smart or not, MMI or not) and, perhaps, on your CBus configuration. In this context, your first step is to find out what format is being used in the feedback messages in your circumstances, rather than writing the code to react to this feedback. Once you have done this, I could probably decode it for you if you posted some example responses.

For example, when I send "\\05FF0073073800\r", I get back something like:

F907380000000000000000000000000000000000000000000000C8
F907380B0000000000000000000000000000000000000000AAAA69
F70738160000000000000000000000000000000000000000B4

The first eight characters of each line give what application is being reported on etc. Each subsequent block of four characters gives the status of a particular light, starting with the first light, and with "AAAA" meaning full off and "5555" meaning full on. The last two characters of each line are checksums.

Third, what you are trying to do is, I think, rather ambitious given you are seemingly not very familar with how TCPIP Pronto/CBus communications work. Two, much simpler, alternatives (neither of which involve using feedback) would be:

1. Simply to have two discrete buttons for on/off rather than a toggle.

2. To maintain expected status within your Prontoscript logic itself rather than via feedback.
Post 13 made on Thursday September 9, 2010 at 21:22
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Based on the fact that you say you are really lost, I'm hoping the above does not send you running.

If you can find a website such as w3schools or mozilla that you can use as documentation for javascript, you will find yourself needing to have a look at String.substring to really parse through the data. I highly recommend the first 11 chapters of the Flanagan book that is referenced in the Dev Guide. Past chapter 11 is pretty much useless in Pronto-Land but the first 11 give you a good background on core javascript and lay the foundation for the programming model that Philips uses with the libraries in PEPv2.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 14 made on Friday September 10, 2010 at 02:15
MCFH
Long Time Member
Joined:
Posts:
December 2009
35
I have written a module for CBUS that abstracts the PCI protocol into a series of functions that can be called or passed as callbacks.

That might make your life a whole load easier

PM me for more information
OP | Post 15 made on Saturday September 11, 2010 at 03:52
mon
Long Time Member
Joined:
Posts:
June 2010
11
The response that i received is as followed
73073800D807000000000000000000000000000000000000000000
D80758000000000000000000000000
Page 1 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