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:
[Newbie] Problems with the Philips Http Library
This thread has 12 replies. Displaying all posts.
Post 1 made on Tuesday October 13, 2015 at 06:35
MikeMelga
Long Time Member
Joined:
Posts:
November 2009
25
Hi.

I am using Philips http library to display images.
The first problem I have is that I can't seem to load images from other than port 80.
If I use an image address like 192.168.0.10:8080/... it doesn't show anything.

The second problem is that I am using it also to fetch some covers from Kodi and while the cover loads... the remote just hangs. Only after the cover is shown I can use the remote again.

I guess that's because some Kodi fanart covers are huge.

Is there any other way I can display images without freezing the remote?

I've testes most of the tcp scripts here on the forum, but none worked :(

Can some point me to a script that works or tell a workaround for the philips library? :P

Thanks.

Regards,
Mike
Post 2 made on Wednesday October 14, 2015 at 00:00
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
With regard to the Kodi fanart sizes, the only way to speed up the remote will be to resize the images on the site.

This can be a common problem and for this reason, systems such as Logitech Media Server will accept requests with size information in the URL and they will resize prior to sending the response.

I suspect your issue with regard to 192.168.0.10:8080 is because your server is expecting a 'HOST' HTTP Request Header which the showHTTPImage() function of the library does not support.

So, instead, try a modfied version of the function.

function showHTTPImageEx(hostIP, aUrl, aWidget, aIndex)
{
var w,
index = 0,
req,
data,
newImage;
if (typeof aWidget === 'string') {
w = CF.widget(aWidget);
} else {
w = aWidget;
}
if (aIndex) {
index = parseInt(aIndex, 10);
}
req = new com.philips.HttpLibrary.HttpRequest();
req.open('GET', aUrl, true);
req.setRequestHeader("Accept",
"image/*; q=0.2, image/jpeg; q=0.8, image/png");
req.setRequestHeader("Host",
hostIp);

req.onreadystatechange = function (aEvt) {
if (req.readyState === 4/*READYSTATE.COMPLETED*/) {
if (req.status === 200) {
data = req.responseBinary;
newImage = new Image(data);
w.setImage(newImage, index);
} else {
System.print("HTTP status: " + req.status);
}
}
};
req.send(null);
}

Last edited by Lyndel McGee on October 14, 2015 00:10.
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 3 made on Wednesday October 14, 2015 at 00:09
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
/* function from above goes here or in your page or activity script with the assumption that you've already included the Philips code*/


var panel = GUI.widget('MYPANEL');

showHTTPImageEx('192.168.0.10', 'http' +
'://' + '192.168.0.10:8080/myImage.jpg', panel, 0);


Note that I have broken the URL into 3 pieces here so that this site does not show the URL as an HTML Link.

The URL that you put in here should be the exact URL that you'd plug into Firefox, Chrome, or IE to download the image.

I am also assuming that you have tested fetch of image from your web browser and that the web browser does not ask you to authenticate or something like that (an IP Camera, perhaps).
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 4 made on Wednesday October 14, 2015 at 05:21
MikeMelga
Long Time Member
Joined:
Posts:
November 2009
25
Lyndel McGee,

Thanks.
I will try that later today :)

And yes, although it's a surveillance camera image... it has no authentication. I can see the image in any browser.

Thanks again!
OP | Post 5 made on Wednesday October 14, 2015 at 08:17
MikeMelga
Long Time Member
Joined:
Posts:
November 2009
25
Lyndel,

One last question:

The image I am pulling is a from a surveillance camera so... I would like to update it every x seconds. What is the best way to do this? Reload the page every x seconds or add a loop in the code?

Thanks.
Post 6 made on Wednesday October 14, 2015 at 22:48
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
If you put a loop in the code, that is not a good idea as your UI may never refresh except for the picutre at hand.

Either put script into Page Script and set the Page Interval to every 2 or so seconds. Also, a better approach is to have look at the DEV Guide around CF.activity().scheduleAfter();

Here's the way to do this.

At the end of the code you currently have in the page script, put in the following assuming that you have a single page.

var intervalMs = 2000;
var panel = GUI.widget('MYPANEL');
// Display the first time.
showHTTPImageEx('192.168.0.10', 'http' +
'://' + '192.168.0.10:8080/myImage.jpg', panel, 0);

// Repeat/reload every 2 seconds.
CF.activity().scheduleAfter(intervalMs, function(p) {


showHTTPImageEx('192.168.0.10', 'http' +
'://' + '192.168.0.10:8080/myImage.jpg', panel, 0);
if (CF.page() == p) {
// still on same page, request update again in 2 seconds. If page has
// changed, then reschedule will not occur effectively cancelling until
// you return to the page.
CF.activity.scheduleAfter(intervalMs, arguments.callee, p);
}
}, CF.page());
Lyndel McGee
Philips Pronto Addict/Beta Tester
Post 7 made on Wednesday October 14, 2015 at 22:51
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
If this works in a web browser, you might want to try a tool that allows you to inspect the HTTP Request/Response headers. You can setup your browser to use an HTTP Proxy which can capture all this data. Wireshark/Ethereal will also capture it but in a much finer grain (raw bytes). Once you know what header values you need to add to the request, use the example above to move forward.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 8 made on Thursday October 15, 2015 at 11:38
MikeMelga
Long Time Member
Joined:
Posts:
November 2009
25
On October 14, 2015 at 22:51, Lyndel McGee said...
If this works in a web browser, you might want to try a tool that allows you to inspect the HTTP Request/Response headers. You can setup your browser to use an HTTP Proxy which can capture all this data. Wireshark/Ethereal will also capture it but in a much finer grain (raw bytes). Once you know what header values you need to add to the request, use the example above to move forward.

Thanks.

I can't get any image on the Pronto so... I will start playing with the headers this weekend :(
Post 9 made on Thursday October 15, 2015 at 23:41
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Just curious. When you use a web browser, is it http or https:// that is returned on the link?
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 10 made on Friday October 16, 2015 at 06:25
MikeMelga
Long Time Member
Joined:
Posts:
November 2009
25
Lyndel,

It's http.

This is the headers information I got using Chrome's internal network tools:

General:
Remote Address:192.168.0.10:8080
Request URL:[Link: 192.168.0.10]
Request Method:GET
Status Code:200 OK

Response Headers:
Access-Control-Allow-Origin:*
Cache-Control:no-cache
Connection:Keep-Alive
Content-Length:88677
Content-Type:image/jpeg
Date:Fri, 16 Oct 2015 10:18:06 GMT
Last-Modified:Fri, 16 Oct 2015 10:18:06 GMT
P3P:CP="CAO COR CURa ADMa DEVa OUR IND ONL COM DEM PRE"
Pragma:no-cache
Server:BlueIris-HTTP/1.1
Set-Cookie:session=16c230212ea249030127559c02cc0599; path=/;

Request Headers:
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:max-age=0
Connection:keep-alive
Cookie:session=769b7b76399571ff696f2fda0dc12e08
Host:192.168.0.10:8080
If-Modified-Since:Fri, 16 Oct 2015 10:12:48 GMT
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36


Just one information about the survaillence system: it only asks for authentication OUTSIDE of the local network. I am using my Pronto inside my local lan of course.

Thanks again for your help.
Post 11 made on Sunday October 18, 2015 at 14:52
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
Interesting. Looks like it is establishing a web session but don't think that is your issue.

Try setting these 3 header values in your request.

Cache-Control:max-age=0
Connection:close
Host:192.168.0.10:8080

Note that this will require you to update parameters to first function to supply hostIP + ':8080'.


I presume the IP addy of your pronto is 192.168.0.XXX.
Lyndel McGee
Philips Pronto Addict/Beta Tester
OP | Post 12 made on Monday October 19, 2015 at 05:06
MikeMelga
Long Time Member
Joined:
Posts:
November 2009
25
Lyndel,

Those 3 headers did the trick!!!!! Thanks a lot! :D
I tried all headers before but I never would have guessed the "Connection:close"


Here is your fulll code in case someone needs a working script (I've just altered the refresh time for 0.5 seconds):


function showHTTPImageEx(hostIP, aUrl, aWidget, aIndex)
{
var w,
index = 0,
req,
data,
newImage;
if (typeof aWidget === 'string') {
w = CF.widget(aWidget);
} else {
w = aWidget;
}
if (aIndex) {
index = parseInt(aIndex, 10);
}
req = new com.philips.HttpLibrary.HttpRequest();
req.open('GET', aUrl, true);
req.setRequestHeader("Host", hostIP + ":8080");
req.setRequestHeader("Cache-Control", "max-age=0");
req.setRequestHeader("Connection", "close");
req.onreadystatechange = function (aEvt) {
if (req.readyState === 4/*READYSTATE.COMPLETED*/) {
if (req.status === 200) {
data = req.responseBinary;
newImage = new Image(data);
w.setImage(newImage, index);
} else {
System.print("HTTP status: " + req.status);
}
}
};
req.send(null);
}

var intervalMs = 500;
var panel = CF.widget('painel');
// Display the first time.
showHTTPImageEx('192.168.0.10', '[Link: 192.168.0.10], panel, 0);
CF.widget("painel").stretchImage=true;

// Repeat/reload every 0.5 seconds.
CF.activity().scheduleAfter(intervalMs, function(p) {


showHTTPImageEx('192.168.0.10', '[Link: 192.168.0.10], panel, 0);
if (CF.page() == p) {
// still on same page, request update again in 0.5 seconds. If page has
// changed, then reschedule will not occur effectively cancelling until
// you return to the page.
CF.activity().scheduleAfter(intervalMs, arguments.callee, p);
}
}, CF.page());
Post 13 made on Tuesday October 20, 2015 at 20:19
Lyndel McGee
RC Moderator
Joined:
Posts:
August 2001
12,994
'Connection: close' is required because the philips library by default uses HTTP 1.1 instead of 1.0. As a result, if you don't have that header, the server is keeping the connection alive and evidently the socket code in the philips library does not like long-lived connections for images.
Lyndel McGee
Philips Pronto Addict/Beta Tester


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