On February 27, 2021 at 20:04, Lyndel McGee said...
Several questions:
The socket code you have here is basically an Image reader which is also supported by the Philips HTTP Library. Do you have that library and have you tried using it?
Is the code above in a button or in a page script?
It makes a difference due to the variable scoping of 'socket'.
Have you attempted any of the examples from the Dev Guide thus far and did you encounter any specific errors?
Hi Lyndel,
here is the specific script I'm using and it runs OK :
var socket, receivedData;
socket = new TCPSocket();
receivedData = "";
socket.onConnect = function() {
socket.write("GET /images/hspi_ultranetcam3/snapshots/NetCam001/last_snapshot.jpg HTTP/1.0\r\n\r\n");
};
socket.onData = function() {
receivedData += socket.read();
};
socket.onIOError = function (e) {
widget("output").label = "press MENU button to update !";
};
socket.onClose = function () {
var imageStartIndex,
bitmapData,
myImage;
// remove the HTTP header from the received data
imageStartIndex = receivedData.indexOf("\r\n\r\n");
bitmapData = receivedData.substring(imageStartIndex+4);
// make and display the image
myImage = new Image(bitmapData);
widget("output").setImage(myImage);
};
socket.connect("192.168.178.31", 81, 3000);
This code is in a page script and I use it as it is, not with Http Library.
I don't have attempted any of the examples from the Dev Guide until now.
Clicking on the MENU button causes a 4 seconds wait and then calling again this page with the code and a refresh in that way.
It would be nice to do this automatically onWake.
Kind regards,
Fischi