Webserver

Questions and comments specific to a particular plugin should go here.

Webserver

Postby ferris » Thu Jun 11, 2009 5:09 am

This is the official topic to support Webserver plugin.
The latest version of the plugin you can download here.

I have recently downloaded eventghost and am trying to learn how to use it. My aim is to use the html webserver eventually with usb-uirt. I have not done a lot of programming in html before so am learning my way through it. I downloaded the webserver demo and have been going over it to try and understand all the commands and steps. One thing I cannot work out is how to send an event and also change the page. Each time a <td> object is pressed it sends it to the TriggerEvent function that then onsends it to the Request function what I would like to do is essentially the following.

function TriggerEvent(eventname)
{
Request(eventname + "&withoutRelease");
href="https://www.google.com";
return false;
}

This is a simplification of what I am aiming to do but essentially I would like to have an opening screen that had options for 'Watch TV', 'Watch DVD' etc. If 'Watch DVD' is selected then a command will be send to Power on TV, Power on DVD, Set TV Input to DVD, I would also then like the remote to automatically navigate to the DVD Page that would then have 'Play', 'Stop', 'Pause', 'Menu' etc buttons on it.

I seem to be able to get the demo to either send the event to Eventghost or navigate to the new page, but cannot work out how to get it to do both.

I am sure I am overlooking something simple. Thanks for any help.
ferris
 
Posts: 2
Joined: Thu Jun 11, 2009 4:44 am

Re: Webserver

Postby ferris » Mon Jun 15, 2009 12:46 pm

anyone?
ferris
 
Posts: 2
Joined: Thu Jun 11, 2009 4:44 am

Re: Webserver

Postby jinxdone » Mon Jun 15, 2009 2:38 pm

What you are trying to do is commonly called AJAX. It stands for asynchronous javascript and xml (well, no xml in your case.) But anyhow from what I gather you want to send a page request on the background (trigger EG events) while you do something completely different with the page presented to the user. You will need javascript to accomplish this.

If you want to start learning javascript and modern web-building I recommend you first familiarize yourself with JQuery, one of the more popular javascript frameworks out there. (or any other javascript framework, but this is what I use :wink: ) It takes away a lot of the cross-browser issues you will have with plain javascript and also offers lots and lots of useful tools, shortcuts and all sorts of things that will make your life as a javascript coder so much easier. I recommend this book for learning JQuery, it's well written and newcomer friendly and will get you that mindset and insight how it is supposed to work very quickly. After you've read it the online docs become much more useful since you already have the basic knowledge.

What I'm trying to say is that with the right tools making requests to EG webserver, or any other webserver, is a breeze. And that it's not really EG specific in any way. Theres also lots and lots of information on the subject elsewhere on the internet.

I hope you find your answers, I think it is should be easy to learn and like I mentioned, not EG specific, so this is the wrong place for it.

-jinxdone
User avatar
jinxdone
Plugin Developer
 
Posts: 443
Joined: Tue Jan 02, 2007 4:08 pm

Re: Webserver

Postby Pako » Fri Aug 02, 2013 1:02 pm

As I already announced, I've added some new options for this plugin.
Here is a "alpha version".
It is not intended for distribution or for testing (I have to add an application example).
This is intended to do two things:
1) Sem;colon: please check, whether your adjustments are working
2) I beg you, check the new English strings

Thanks, Pako
Attachments
__init__.py
Alpha version 1.2
(45.45 KiB) Downloaded 310 times
User avatar
Pako
Plugin Developer
 
Posts: 2247
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Webserver

Postby Sem;colon » Sat Aug 03, 2013 5:50 pm

Hi Pako,

I just tested it, my modifications work almost - just some small things.

Code: Select all
import re


was missing and my part in the do_POST block wasn't working.
I fixed it, see the attached file.


I know it's alpha, but I would like to report a bug:
when I parse a remote web page with non ascii code into a variable and want to access this variable from another PC over HTTP, I get a UnicodeDecodeError:

Code: Select all
19:26:30   Exception happened during processing of request from ('::ffff:192.168.0.15', 41284, 0, 0)
19:26:30   Traceback (most recent call last):
19:26:30     File "SocketServer.pyc", line 558, in process_request_thread
19:26:30     File "SocketServer.pyc", line 320, in finish_request
19:26:30     File "SocketServer.pyc", line 615, in __init__
19:26:30     File "BaseHTTPServer.pyc", line 329, in handle
19:26:30     File "BaseHTTPServer.pyc", line 323, in handle_one_request
19:26:30     File "C:\Program Files (x86)\EventGhost\plugins\Webserver\__init__.py", line 470, in do_POST
19:26:30       self.SendContent(self.path)
19:26:30     File "C:\Program Files (x86)\EventGhost\plugins\Webserver\__init__.py", line 447, in SendContent
19:26:30       content = template.render()
19:26:30     File "jinja2\environment.pyc", line 891, in render
19:26:30     File "C:\auto\web\var.htm", line 1, in top-level template code
19:26:30       {{eg.globals.playlist}}
19:26:30   UnicodeDecodeError: 'ascii' codec can't decode byte 0xfc in position 5573: ordinal not in range(128)


the content of the variable in this example was:
Code: Select all
1;~!960054620;~!1;~!die ärzte - zeiDverschwÄndung;~!2:59!2ex71in3!5tr!nG 0:02:59


Edit: with the previous version of the webserver this works.

I hope this helps!
Attachments
__init__.py
(45.89 KiB) Downloaded 265 times
Sem;colon
Experienced User
 
Posts: 578
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Postby Pako » Sun Aug 04, 2013 2:49 pm

Sem;colon wrote:I know it's alpha, but I would like to report a bug:
when I parse a remote web page with non ascii code into a variable and want to access this variable from another PC over HTTP, I get a UnicodeDecodeError:
...

I thank you for reporting.
However, I have two questions:
1) This is a new bug, or it occurred in the previous version too?
2) Can you please give me instructions on how I can cause the same error? Maybe you can put an attachment here (with examples).

Thanks, Pako
User avatar
Pako
Plugin Developer
 
Posts: 2247
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Webserver

Postby Sem;colon » Sun Aug 04, 2013 10:35 pm

However, I have two questions:
1) This is a new bug, or it occurred in the previous version too?
2) Can you please give me instructions on how I can cause the same error? Maybe you can put an attachment here (with examples).


well, it worked with my modification as the default doesn't allow to parse content of a foreign webpage.

I now found the issue; I just took a quick look over the code in the first place and didn't notice any difference in the class SendEventExt from my modification.
But there is one, and that's the problem
Code: Select all
thepage = unicode(urllib2.unquote(handle.read()).decode(eg.systemEncoding,'replace'))

was replaced with
Code: Select all
thepage = handle.read()

which causes problems if the content is non-ascii.

I admit that the line of code I wrote is ugly and could be done better (I really hate this encode-decode stuff)
Sem;colon
Experienced User
 
Posts: 578
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Postby Pako » Mon Aug 05, 2013 3:53 pm

@Sem;colon:
I downloaded the modified file.
I do not understand your changes in the text (lines 475-481 and 539-545).
What is the reason you are returning the contents of the original request?
Why you do not like the original version content = json.dumps(None) ?

Pako
User avatar
Pako
Plugin Developer
 
Posts: 2247
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Webserver

Postby Sem;colon » Mon Aug 05, 2013 4:53 pm

Code: Select all
content = json.dumps(result)


is one of the things that didn't work for me, just as

Code: Select all
data = json.loads(content)


it leads to an exception.

lines 475-481: correct me if I'm wrong, but I think these lines should fulfill the post request if no file is sent to the requester :roll: (I'm not sure, that's how I interpreted it, I also just copied it from the original, but it works fine!)

lines 539-545: well, I already explained why I "don't like" json.dumps but also two responses were sent in case of the request stated with "request" (one from line 539-545 and one from line 470)
Sem;colon
Experienced User
 
Posts: 578
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Postby Pako » Mon Aug 05, 2013 6:32 pm

I'm still a little confused.
I understand that data = json.loads(content) causing the error
(this is obvious if your request does not it formatted as json).
But the rest of it is not entirely clear to me. I do not know, how I can to try it.
However, I have another suggestion. Can you please try a modified version?
If it will work, I've no interest in dealing with it.

Pako
Attachments
__init__.py
Alpha version 1.3
(46.08 KiB) Downloaded 259 times
User avatar
Pako
Plugin Developer
 
Posts: 2247
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Webserver

Postby Sem;colon » Sun Aug 11, 2013 9:50 am

Hi Pako,

why did you add "eg.PrintTraceback()" in line 472??
This results in very ugly error messages (see attachment).
Would you please leave it out?
Attachments
Unbenannt.png
Unbenannt.png (8.22 KiB) Viewed 15809 times
Sem;colon
Experienced User
 
Posts: 578
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Postby Pako » Sun Aug 11, 2013 2:04 pm

Oh, I'm sorry.
I tried something and then I forgot to return it.
I always use json, so I do not have this problem.
I promise you that very soon I will do a new build with the fix.

Pako
User avatar
Pako
Plugin Developer
 
Posts: 2247
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Webserver

Postby Sem;colon » Sun Aug 11, 2013 6:00 pm

No problem, I already thought something like that :)
Well, I guess with all the improvements blackwind did, the next release won't be far anyway.
(also I did two more plugin fixes that could be included in the next release, I will post it in the release topic as soon as the test period is over)


I have a question Pako,

you mentioned that it would be possible with your modification to execute scripts from the website directly without using TriggerEvent, is there any documentation or can you explain how to do that?

Sem;colon
Sem;colon
Experienced User
 
Posts: 578
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Postby Pako » Mon Aug 12, 2013 4:58 am

Sem;colon wrote:you mentioned that it would be possible with your modification to execute scripts from the website directly without using TriggerEvent, is there any documentation or can you explain how to do that?
Sem;colon

I have no documentation and I do not think I'll create some documentation.
This could be done by someone who speaks English.
However, I already have done a fairly comprehensive example of the use of the new possibilities of this plugin.
It is a collaboration with the MusicBee plugin and therefore control MusicBee using the Web UI.
I intend to publish it very soon.

Here is a small piece of script:
Code: Select all
        $.ajax({
            type: 'POST',
            cache: false,
            url: "",
            data: JSON.stringify({"args": ["eg.plugins.MusicBee.PlaylistCommand(63, None, None, None)"], "method" :"ExecuteScript"}),
            dataType: 'JSON',
            contentType: "application/json;charset=utf-8",
            success: function (jsonData, textStatus) {
                UpdateSelect(jsonData, "playlists", ""); 
            },
       });
Note: The string between square brackets can be best obtained from the EventGhost configuration tree using "Copy as Python."

Pako
User avatar
Pako
Plugin Developer
 
Posts: 2247
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: Webserver

Postby Sem;colon » Thu Aug 15, 2013 7:52 pm

Cool!

But unfortunately this only works with AJAX JSON POST-
I just extended the POST enhancement by me to match the functionality of the AJAX JSON POST, so that it also works with jquery Post ;-) !

EDIT: I found a small bug at line 493, I corrected it and updated the attachment!
Attachments
__init__.py
(48.89 KiB) Downloaded 276 times
Sem;colon
Experienced User
 
Posts: 578
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Next

Return to Plugin Support

Who is online

Users browsing this forum: No registered users and 5 guests

cron