Page 2 of 3
Re: Websocket Plugin
Posted: Sat Jul 09, 2011 7:46 pm
by cfull1
What kind of smartphone do you have?
I don't think Android supports websockets yet.
I don't know much about cgi.
What types of files are you wanting to send?
I don't think websockets can do much of that yet.
Pictures can be done with Base64 encoding but I don't think the plugin or I am ready for that yet.
Sorry
Re: Websocket Plugin
Posted: Sat Jul 09, 2011 8:24 pm
by Mannyman
I have HP webOS Pre2.
Currently I am using webserver plugin to send commands and OSD text from my Pre2 to PC running EG.
I'd like to send a picture from my phone and then use EG's Show Picture command to put it on my Monitor and things like that.
Also .wav files, .mp3, etc...
I am patient so no hurry, as it is fun learning all this stuff.
Thanks,
Manny
Re: Websocket Plugin
Posted: Sat Jul 09, 2011 9:52 pm
by cfull1
Unfortunately webOS doesn't support websockets.
Since websockets are a fairly new protocol they are not yet supported many browsers.
Does Pako's email plugin allow for attachments?
Maybe you could use that or find another script that downloads certain email's attachments and saves them in a folder.
The script could then trigger an eg event through the cmd functions, triggering a macro to display the picture.
Just a thought
Re: Websocket Plugin
Posted: Sat Jul 09, 2011 11:52 pm
by Mannyman
It looks like webSocket is supported in webOS 3.0 per the webOS development forum.
I've also been looking at
http://socket.io/ for previous versions of webOS...another guy is using that to connect to a .NET WebSocket server...
I'll look into your other suggestions as well.
Thanks,
Manny
Re: Websocket Plugin
Posted: Sun Jul 10, 2011 2:50 am
by cfull1
Socket.io looks like good stuff. I've heard about it alot too. I'll look into it
Re: Websocket Plugin
Posted: Sun Jul 10, 2011 6:33 am
by krambriw
Hi there,
This works fine. At least with Crome. This technic would allow to build very efficient flat panels around the house to control & always have actual state updated on those
It's a pitty if android doesn't support websocket since those small flat panels are getting cheaper every day. Is socket.io supported on android?
If socket.io works on those, it might be a smarter choice than websocket (just thinking loud)
Best regards, Walter
Re: Websocket Plugin
Posted: Sun Jul 10, 2011 2:07 pm
by cfull1
The problem with me is most of my stuff is controlled by IR which I'm getting really sick of lol. It's so limited.
But I've got a nice setup with iTunes through this.
I've been looking into socket.io.
I would mean i major code rewrite if not just starting from scratch.
I'm not sure how soon I would be able to do it. There are other projects I want to work on too.
But it does offer some advantages:
Heartbeats - To see whether the client is still connected, currently if the plugin runs into an error with the client it just removes it to prevent the whole thing from crapping out.
Multiple "onmessage" functions - You can setup custom functions so that everything doesn't have to go through one function.
Also it doesn't use just websockets it picks from the best choice. One of the methods is flash. This provides more compatibly with browsers, supporting IE, Chrome, Firefox, Safari, Opera, Mobile Safari, Android, and webOS. But some of these connects are not true websockets, and I'm not sure how responsive they will be, given that one of the methods of transport being ajax polling.
I will continue to research.
Re: Websocket Plugin
Posted: Tue Jul 12, 2011 12:35 pm
by krambriw
Hi,
This topic is for sure very interesting and really appreciates all work done by everybody.
I have played with it a bit and I have some ideas how I see that this can be extremely useful. I think best is maybe to describe with example what I would like to achieve.
I use EG to control many devices and EG always know the actual status of the devices (ON, OFF etc)
Now I plan to put a number of flat touch panels around in the house to enable a visual view and control functions using buttons & status indicators on an html page.
The devices can, besides using EG, also be controlled by various remotes. Those signals (coming from remotes and others) are captured by EG too, just to have the actual status correctly represented
The websocket server works fine to control the status indicators, they are changing accordingly to show the actual status. So far so good!
The remaing parts I have to think about is
- I need to make the current statuses persistent to make it possible to restart EG and to recover the correct display on all connected web clients
- I need to make it possible so that when a new web client connects, it shall be synchronized with the current statuses
- When I touch a button on the touch screen to control a device, I need to make sure that the page is not fully refreshed to its default state, it should only update the changed status of the specific device
To save the current statuses I think I have to solve this by creating (a script or a plugin)
- that saves the status for each device when it changes using eg.PersistentData
- that sends out the current statuses to a web client when it detects that it is newly connected
Currently I have a problem to make a simple html page that has just two buttons, one ÔÇ£ONÔÇØ and one ÔÇ£OFFÔÇØ that I can change the background & text color on
- Default button background are lets say red and green
- Click/Touch the ÔÇ£ONÔÇØ button, it shall trigger an event in EG
- The event is then captured (by a script) used to trigger the sending from the websocket
- The event from the websocket is captured in the web client and a java script function is changing the background and text color of the buttons to reflect the actual statuses
Examples below
Any help to make this simple html page to work is very much appreciated. How much I tried, I did not manage to make the page not refresh back to the default state (red & green background)
Best regards, Walter
Java script function that receives events from websocket server and changes the properties of elements in the html page
Code: Select all
function StartUp()
{
ws = new WebSocket("ws://127.0.0.1:1235");
ws.onmessage = function (event) {
if (event.data == "Heater ON")
{
document.getElementById("p07").style.backgroundColor="yellow";
document.getElementById("p07").style.color ="black";
document.getElementById("p08").style.backgroundColor="black";
document.getElementById("p08").style.color ="white";
}
if (event.data == "Heater OFF")
{
document.getElementById("p07").style.backgroundColor="black";
document.getElementById("p07").style.color ="white";
document.getElementById("p08").style.backgroundColor="black";
document.getElementById("p08").style.color ="white";
}
};
ws.onclose = function() {
ws = ''
alert('Connection Closed');
};
}
Sample html with two buttons
Code: Select all
<html lang="sv">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<title>My websocket test page</title>
</head>
<form name="example">
<body onLoad="StartUp()" bgcolor="#3A3C69" text=white link=white vlink=white alink=white />
<center>
<br>
<table border="1" width="25%">
<tr><!-- Row 4 -->
<td><button id="p07" onMouseDown="TriggerEvent('Heater ON')" style="background-color:green"><img src="lamp-on.png" ALIGN="right"> Towel dryer</button></td>
<td><button id="p08" onMouseDown="TriggerEvent('Heater OFF')" style="background-color:blue"><img src="lamp-off.png" ALIGN="right"> Towel dryer</button></td>
<td><!-- Col 3 -->
</tr>
</table>
</center>
</form>
</body>
</html>
Re: Websocket Plugin
Posted: Thu Jul 14, 2011 1:21 pm
by cfull1
I need to make the current statuses persistent to make it possible to restart EG and to recover the correct display on all connected web clients
I deal with this in eventghost. Whenever a states changes I write it to a file. When eventhgost starts it grab that file and saves the variable that way.
That may be easier than trying to use an html client.
I need to make it possible so that when a new web client connects, it shall be synchronized with the current statuses
Can you not use the
WebSocket.ClientConnected event to trigger a macro to send that data?
When I touch a button on the touch screen to control a device, I need to make sure that the page is not fully refreshed to its default state, it should only update the changed status of the specific device
Does your webpage reload everytime you send a command?
I have mine setup using ajax...I think. I copied part of the code from someone here.
Code: Select all
function Request(eventname){
var xmlHttp = null;
var dateObject = new Date();
try {
// Firefox, Opera 8.0+, Safari, IE7
xmlHttp = new XMLHttpRequest();
}
catch (e) {
try
{
// IE 6
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
// IE 5
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
xmlHttp.open('GET', "empty?" + eventname + "&" + dateObject.getHours() + ":" + dateObject.getMinutes() + "&" + deviceName, true);
xmlHttp.send(null);
return false;
}
Let me know how it goes,
Carson
Re: Websocket Plugin
Posted: Sat Jul 16, 2011 6:08 am
by krambriw
Thanks, I got everything working now

Re: Websocket Plugin
Posted: Tue Jul 19, 2011 9:58 am
by krambriw
Hi, I have seen that my web client is making a disconnect/reconnect to the websocket server everytime I click on something in the browser that sends an event to eg.
Is it possible to avoid the disconnection in any way?
Best regards, Walter
Re: Websocket Plugin
Posted: Tue Jul 19, 2011 4:39 pm
by Pako
Dear Walter!
As I already wrote, I'm just deal with the development of my WebSocket plugin.
It forced me to make a demonstration web client as well.
I met with javascript so far only very marginally.
Now I know about it much more.
Therefore, I can advise you:
Your problem is occurs because the BUTTON tag is enclosed in the FORM tag.
If you remove the FORM tag, it will work properly.
Best regards, Pako.
Re: Websocket Plugin
Posted: Tue Jul 19, 2011 6:03 pm
by krambriw
Dear Pako,
This is so exciting, I have a rapid update of my button text and background indicating actual status of devices in EG, I will try to find how to move the buttons as you suggested.
Thanks for the hint,
Very best regards, Walter
And yes, yes, it works super!!!!
Thanks a lot Pako!
Re: Websocket Plugin
Posted: Tue Jul 19, 2011 11:58 pm
by cfull1
Pako,
Thanks for your input, I appreciate your help!
Are you currently working on your websocket plugin?
Have you looked into socket.io?
They just updated to 0.7, unfortunately all the python code I can find is for the old version.
Maybe this is something you can address being a more experienced programmer than I?
I'm excited to see where all this goes!
Re: Websocket Plugin
Posted: Sun Sep 04, 2011 3:23 pm
by krambriw
So I finally have made a simple html page from where I can control lamps and other power consumers. I have also added some information coming from a number of temperature & humidity sensors.
Everything is instantly updated using the websocket server plugin, it really works nice.
I also made buttons as toggle button so they actually will work as pushbuttons once I get my tablets.
Most of the lights and other power consumers are controlled by EG using schedulers or suntracker plugins. They can be operated with
- standard rf remotes
- by EG using schedulers or suntrackers
- from touch screen using tablets
Whatever, the status will always be shown correctly and thats the key point.
For browsers, I have tried various onces but I believe Opera will be my choice because Opera supports websockets on all platforms including android and symbian. I even tried this wih my symbian Nokia mobile and it worked perfect even if the display of course is too small.
Now the fun part starts, it's time to extend with even more controls...
Text is in Swedish but I think you get the idea
Best regards, Walter