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:
prontoscript for downloading internet images
This thread has 16 replies. Displaying posts 1 through 15.
Post 1 made on Sunday June 22, 2008 at 21:39
vanderwielen
Founding Member
Joined:
Posts:
December 2001
40
grandma is happy now that i've integrated the weather module on her TSU9400. has anyone created a prontoscript to download a jpeg of a weather radar image?
Post 2 made on Monday June 23, 2008 at 06:18
Krazz
Long Time Member
Joined:
Posts:
May 2008
65
I haven't done exactly that, but downloading an image is pretty simple. You have the sample code in the developers giude. It's just a matter of fine tuning to get it to work.

I'm not sure if I'm allowed to link directly to the document, but you can find it if you have an account and log into the following site: [Link: pronto.philips.com]
OP | Post 3 made on Monday June 23, 2008 at 08:47
vanderwielen
Founding Member
Joined:
Posts:
December 2001
40
Thanks for the reply, though registered i'm not certified and therefore cannot access that area. Would someone please paste the sample code?
Post 4 made on Monday June 23, 2008 at 09:28
nimnul
Long Time Member
Joined:
Posts:
August 2007
245
The developers guid is featured in this sites file area, try there.
Post 5 made on Monday June 23, 2008 at 12:36
Tom Light
Long Time Member
Joined:
Posts:
December 2006
229
In this thread is an example:
[Link: remotecentral.com]
OP | Post 6 made on Monday June 23, 2008 at 14:20
vanderwielen
Founding Member
Joined:
Posts:
December 2001
40
here's my script to retrieve a radar image. the location of the file is:

could someone take a look to see if there's anything i'm doing wrong:

var socket = new TCPSocket();
var receivedData = "";
socket.onConnect = function() {
write("GET /data/nids/IND19_thumb_t.jpg” + " HTTP/1.0\r\n\r\n");
};
socket.onData = function() {
receivedData += read();
};
socket.onIOError = function (e) {
widget(“output”).label = "IOError " + e;
};
socket.onClose = function () {
// remove the HTTP information from the received data
var imageStartIndex = receivedData.indexOf("\r\n\r\n");
var bitmapData = receivedData.substring(imageStartIndex+4);
// make and display the image
var MyImage = new Image(bitmapData);
widget(“output”).setImage(MyImage);
};
socket.connect('icons.wunderground.com',80,3000);
Post 7 made on Monday June 23, 2008 at 18:56
Krazz
Long Time Member
Joined:
Posts:
May 2008
65
Start of by replacing/re-entering all the cuotation marks. In some places you are using ' in some others " and yet also in some places ”. You should use either " or '.

Then I don't know if you have a widget called output (if I remember correctly this is the default widget name in the developers guide). If you don't, then just create it, or rename the output widget in the code to whatever your widget is called in your setup.

That shold be all you need to do... I think! ;)

Btw, I just came up with a related question on my own that maybe some of the more advanced developers at this site might know the answer to.
When you open a socket as in the example mentioned above. Will the socket close by itself if there is an IOError or do I have to close it manually?
Post 8 made on Tuesday June 24, 2008 at 07:02
Sogliphy
Long Time Member
Joined:
Posts:
July 2007
186
Krazz,

An HTTP server will close the connection after it has transmitted all the content in response to an HTTP request, unless the request contains "Connection: Keep-Alive" header or is an HTTP/1.1 request without a "Connection: close" header.

However, not all TCP socket communication is with HTTP servers. If the server doesn't close connections automatically (as with HTTP), the client should close them.
Post 9 made on Tuesday June 24, 2008 at 21:08
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,007
You may find that you also need to add a "Host" request header and specify:

icons.wunderground.com

as the value.


Krazz, on an IO Error, the socket is typically closed for you but as good programming practice, you really should examine the "connected" flag and issue a close() in try/catch block if not closed upon receipt of IO Error. This way, should the underlying functionality ever change, your code still behaves correctly.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 10 made on Wednesday June 25, 2008 at 06:52
Krazz
Long Time Member
Joined:
Posts:
May 2008
65
Lyndel McGee: That makes sense to me. Thank you.
OP | Post 11 made on Thursday June 26, 2008 at 08:02
vanderwielen
Founding Member
Joined:
Posts:
December 2001
40
Lyndel is 99% correct and I should clarify the solution. An internet image's address, i.e., ww3.weather.com/images/.....jpg is not the true location of the file. On the HTTP server, the www, or any other folders location can be set to be anywhere within that computer. The script does work. Thanks to everyone for the help. Now, if i could get get the stretch function to work.
Post 12 made on Thursday June 26, 2008 at 20:55
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,007
How in the heck am I 99% correct? I only suggested he add the Host request parameter. I said nothing about the actual file location?

I'm totally confused here. Help me out.

Stretch works fine. Before assigning the image to a panel/button, simply specify w.stretchImage = true;
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 13 made on Tuesday December 28, 2010 at 09:05
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
Trying to load images from remote web server, noticed delays between closing the socket, and low frame data size per query.My image is for about 30kbytes size but it uses 6 frames for image loading, what is going wrong?

var socket = new TCPSocket();
var receivedData = "";
var MyImage;
socket.connect("192.168.0.2",80,100);
socket.onConnect = function()
{
System.print("connected");
socket.write("GET /poo.jpg HTTP/1.1\r\n");
socket.write("HOST: 192.168.0.2\r\n\r\n");
System.print("write");
};
socket.onData = function()
{
receivedData += socket.read();
System.print ("TCP DATA RECEIVED:"+ receivedData);
var imageStartIndex = receivedData.indexOf("\r\n\r\n");
var bitmapData = receivedData.substring(imageStartIndex+4);
// make and display the image
MyImage = new Image(bitmapData);
};
socket.onIOError = function (e)
{
GUI.widget("panl").label = "IOError " + e;
};
socket.onClose = function () {
System.print("closed");
};
GUI.widget("panl").stretchImage=true;
GUI.widget("panl").setImage(MyImage);

I've tried to close manually(adding socket.close(); at the end of onData function), but in that case it didn't reach the onData block at all.

It closes sockets manualy after 3 min delays
Post 14 made on Tuesday December 28, 2010 at 20:27
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
13,007
Likely nothing you can do on webserver end. Some webservers send 'chunked' data. If you have access to Philips RSS reader, there's a function there to 'unchunk' the data but I doubt that is your real issue (until you can fix your code and prove me wrong).

Things you must do:

If you did not know this, please take it in stride...
Script is executed from top to bottom in the order the statements are defined.


Note that you are calling socket.connect() on the socket before defining an onConnect callback function or any other functions for that matter. You must move the socket.connect() call to the end of your script and things will likely work more like what you expect as you will have "hooked" all the callbacks on the socket at that time.

Things I strongly recommend:

To ensure that you can handle multiple packets of data you should:
1) Use HTTP 1.0 instead of 1.1 in your request.
2) And move your image loading from onData() function into to onClose().
3) Investigate the 'chunking' but I doubt that is really the issue here.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 15 made on Wednesday December 29, 2010 at 01:54
Elephant
Long Time Member
Joined:
Posts:
December 2010
47
Thanks for help! After changing to HTTP 1.0 and pasting the image creation snippet into onClose block all works fine, chunking dissapeared(may be Solaris webserver configuration changed))). It seems like 1 pic loaded for about 1 second(30-70kbytes), but how i can get 12 or more pics per second if i would work with IP camera?Or there's another factors make sense?
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