Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Webserver
Webserver
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.
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.
Re: Webserver
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
) 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
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
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
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Webserver
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
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 501 times
Re: Webserver
Hi Pako,
I just tested it, my modifications work almost - just some small things.
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:
the content of the variable in this example was:
Edit: with the previous version of the webserver this works.
I hope this helps!
I just tested it, my modifications work almost - just some small things.
Code: Select all
import reI 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)Code: Select all
1;~!960054620;~!1;~!die ärzte - zeiDverschwÄndung;~!2:59!2ex71in3!5tr!nG 0:02:59I hope this helps!
- Attachments
-
- __init__.py
- (45.89 KiB) Downloaded 415 times
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Webserver
I thank you for reporting.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:
...
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
Re: Webserver
well, it worked with my modification as the default doesn't allow to parse content of a foreign webpage.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).
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'))Code: Select all
thepage = handle.read()I admit that the line of code I wrote is ugly and could be done better (I really hate this encode-decode stuff)
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Webserver
@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
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
Re: Webserver
Code: Select all
content = json.dumps(result)Code: Select all
data = json.loads(content)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
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)
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Webserver
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
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 445 times
Re: Webserver
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?
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 (8.22 KiB) Viewed 24274 times
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Webserver
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
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
Re: Webserver
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
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
- Pako
- Plugin Developer
- Posts: 2294
- Joined: Sat Nov 11, 2006 1:31 pm
- Location: Czech Republic
- Contact:
Re: Webserver
I have no documentation and I do not think I'll create some documentation.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
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", "");
},
}); Pako
Re: Webserver
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!
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 455 times
