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.

Webserver

Questions and comments specific to a particular plugin should go here.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

zetat wrote:...I have tried to add a python command after a HTTP event that says "lrwinstate = true" but I get this error:...
Hello zetat,
The problem is, at the moment there is no documentation/example how to use the new functions, but Pako allready promised to create some example files.

Anyway, maybe I can help you a bit:
-The new functions like set or get variables ONLY work with POST requests, not with GET. (I don't know how you were trying to request it)
-The variables you can set are not variables from eg.globals, you have to read or write them by using the commands from the webserver Plugin.
Unbenadnnt.PNG
Unbenadnnt.PNG (5.21 KiB) Viewed 8984 times
-I don't know about the json request, but with a normal post request your first argument (arguments are separated by "&") needs to be one of those depending on what you want to do:
GetValue #gets the value of a temporary variable with the name defined by the second argument
GetPersistentValue #gets the value of a persistent variable with the name defined by the second argument
SetValue #sets the value of a temporary variable with the name defined by the second argument and the value defined by the third argument
SetPersistentValue #sets the value of a persistent variable with the name defined by the second argument and the value defined by the third argument
GetAllValues #gets a list with all names and values of all (webserver) variables
GetChangedValues
ExecuteScript #executes a function defined in the second argument, returns the return value of this function
TriggerEvent
TriggerEnduringEvent
RepeatEnduringEvent
EndLastEvent
-the type of the variables needs to be string (or unicode)

I hope that helps,
Sem;colon
If you like my work, Image me a drink :wink:
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

Hello all,

I made some minor changes to the webserver plugin again that I would like to share:
# 1.6 by Sem;colon 2013-09-07 22:00 UTC+1
# - edited the POST enhancement by Sem;colon:
# -changed the function "request=" to GetGlobalValue
# -added loop for GetValue requests to be able to request multible values at once
# -fixed bug: GetValue didn't return a value
@Pako: I had to replace "plugin.pubVars[data[1]] = data[2]" with "plugin.SetValue(data[1], data[2])" in order to get "GetValue" to work.
Anyway, I only changed that in "my" part of the POST block. I think you might have the same issue with JSON requests, can you please check it?
# - changed "author" line, so that it showes up correctly under "Special Thanks"
Attachments
__init__.py
(50.59 KiB) Downloaded 271 times
If you like my work, Image me a drink :wink:
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Webserver

Post by Pako »

Sem;colon wrote:@Pako: I had to replace "plugin.pubVars[data[1]] = data[2]" with "plugin.SetValue(data[1], data[2])" in order to get "GetValue" to work.
Anyway, I only changed that in "my" part of the POST block. I think you might have the same issue with JSON requests, can you please check it?
Yes, you're right, there was a bug.
I was just a bit confused expression in order to get "GetValue" to work instead of in order to get "SetValue" to work :) .
So I also did some changes:
- added Autosave option (when a persistent value changed)
- added do_POST (Ajax/JSON) method "GetGlobalValue"
- fixed do_POST (Ajax/JSON) methods "Set(Persistent)Value"

Pako
Attachments
__init__.py
Version 1.7
(51.26 KiB) Downloaded 261 times
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

Cool, thanks Pako!

I also did a minor change to the ExecuteScript function of "my" POST block to be able to handle list outputs.
Attachments
__init__.py
(51.43 KiB) Downloaded 272 times
If you like my work, Image me a drink :wink:
zetat
Posts: 8
Joined: Thu Aug 29, 2013 5:29 pm

Re: Webserver

Post by zetat »

Sem;colon wrote:
zetat wrote:...I have tried to add a python command after a HTTP event that says "lrwinstate = true" but I get this error:...
Hello zetat,
The problem is, at the moment there is no documentation/example how to use the new functions, but Pako allready promised to create some example files.

Anyway, maybe I can help you a bit:
-The new functions like set or get variables ONLY work with POST requests, not with GET. (I don't know how you were trying to request it)
-The variables you can set are not variables from eg.globals, you have to read or write them by using the commands from the webserver Plugin.
Unbenadnnt.PNG
-I don't know about the json request, but with a normal post request your first argument (arguments are separated by "&") needs to be one of those depending on what you want to do:
Hi,
Could you give me one example of how I can get a variable with POST?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Webserver

Post by Pako »

Suppose that your variable is named album.
Then the value of this variable you can get from Webserver as follows:

Code: Select all

        $.ajax({
           type: 'POST',
           url: "",
           dataType: 'JSON',
           contentType: "application/json;charset=utf-8",
           data: JSON.stringify({'args':["album"],'method' :'GetValue'}),
           cache: false,
           success: function (jsonData) {
                alert("album = "+jsonData);  
           },            
        });
Note: If this is a global variable, then use the GetGlobalValue method instead of the method GetValue.

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

Re: Webserver

Post by Pako »

I put a long-promised example of using new features of Webserver plugin.
You can find it in MusicBee topic.
In particular, pay attention the file script.js in the folder www-musicbee/js.

Pako
blaher
Experienced User
Posts: 487
Joined: Thu Nov 17, 2011 1:27 am

Re: Webserver

Post by blaher »

Thanks for this plugin. I don't use its full potential, but it's very handy for sending HTTP events from another device, (like a z-wave Vera), or even another EventGhost on a different PC.

A python command of: "import urllib; urllib.urlopen('http://192.168.0.1:8081/?EventName')", for example, works well in EventGhost

and on the Vera, LUUP code of: "local status, result = luup.inet.wget("http://192.168.0.4:8082/?Sleep", 5)". When my HTPC gets a "Sleep" event it knows to have a snooze. :)

Cheers.
zetat
Posts: 8
Joined: Thu Aug 29, 2013 5:29 pm

Re: Webserver

Post by zetat »

I have a problem when I try to send an event to another eventghost. I get a lot of error message see below:
15:05:18 Traceback (most recent call last) (1630):
15:05:18 File "C:\Program Files (x86)\EventGhost\eg\Classes\TaskletDialog.py", line 59, in ProcessingTask
15:05:18 self.Configure(*args, **kwargs)
15:05:18 File "C:\Program Files (x86)\EventGhost\eg\Classes\ConfigDialog.py", line 165, in Configure
15:05:18 treeItem.Configure(*args)
15:05:18 File "C:\Program Files (x86)\EventGhost\eg\Classes\ActionItem.py", line 101, in Configure
15:05:18 return self.executable.Configure(*args)
15:05:18 File "C:\Program Files (x86)\EventGhost\plugins\Webserver\__init__.py", line 863, in Configure
15:05:18 panel.StaticText(text.password),
15:05:18 AttributeError: class SendEvent has no attribute 'password'

What goes wrong?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Webserver

Post by Pako »

1)
First of all, I should point out that it would be right to act according to this: READ THIS before posting anything!
This means in particular use the latest version.

2)
zetat wrote:What goes wrong?
I do not know. I can not achieve the same behavior. You did not indicate how you progressed. So I can not say what you did wrong.
Please describe the process by which the above error occurs (step by step).
Pako
zetat
Posts: 8
Joined: Thu Aug 29, 2013 5:29 pm

Re: Webserver

Post by zetat »

Pako wrote:1)
First of all, I should point out that it would be right to act according to this: READ THIS before posting anything!
This means in particular use the latest version.

2)
zetat wrote:What goes wrong?
I do not know. I can not achieve the same behavior. You did not indicate how you progressed. So I can not say what you did wrong.
Please describe the process by which the above error occurs (step by step).
Pako
1. Yes i Use the lates version.
2. I have configure the webserver to use port 8080. On this computer and I like to send event to another Pc in another room that runs XBMC, NetFlix and more.
I'm not sure which init.py file I'm using. (downloaded 29/8-2013)
How I progressed; Click create macro -> Webserver/Send event to another eventghost
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Webserver

Post by Pako »

1) Maybe now you are using the latest version. But before you use the version r1630. The latest version has number r1640.
2) So it's a typo. Change please the word "passsword" to "password" on line 888 (and also on line 992).

Pako
arturmaj
Posts: 23
Joined: Sun Apr 19, 2009 4:55 pm

Re: Webserver

Post by arturmaj »

Can anyone post a sample html with "request=" to GetGlobalValue or "Set(Persistent)Value"? Thanks.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

arturmaj wrote:Can anyone post a sample html with "request=" to GetGlobalValue or "Set(Persistent)Value"? Thanks.
with jQuery it could be:
GetGlobalValue:
$.post("", "GetGlobalValue&NameOfYourVariable", function(data){
//data=valueOfYourVariable
alert(data);
});

SetPersistentValue:
$.post("", "SetPersistentValue&NameOfYourVariable&NewValue", function(data){
//data="True" or "False"
alert(data);
});
If you like my work, Image me a drink :wink:
drhyoung
Posts: 4
Joined: Wed Nov 06, 2013 7:25 am

HTTP GET simple manipulation of variables

Post by drhyoung »

I have remotes that don't have a lot of capability so have had a good look at EG Webserver. I found a lot of other users, like myself, looking for some simple way to read and manipulate EG variables. POST and json are beyond the capabilities of my remotes (and me).

So I took to Python for the first time ever. The resulting code isn't pretty but it appears to do the job.
Hopefully, it can be incorporated into the next release of EventGhost. In the meantime it can be downloaded in used to replace the provided Webserver "__init__.py" file.

Rudimentary documentation follows....

EventGhost Webserver GET simple manipulation of variables

Displays and, if requested, updates EventGhost variables. Also will simply do a calculation. Returns the results in a simple XML page.
Designed for those with multiple remotes that need to transfer state information between remotes, and also to allow remotes to use PythonÔÇÖs arithmetic and string handling abilities.

Example URL:
http://10.1.1.3:81/eg?globals&TestGlobalVariable&MyNewVariable:=78&Another:=My String&[Equation]Lastly:=(1+2+3)&[Flag](3+4+5)

Syntax:
URL:= http://<domain>:<port>/<file>?globals[&<Command>]...

<Command> :=
(1) [<label>]<Variable>
Displays an EG global variable, for example eg.globals.Test
Will be in the resulting XML page as ÔÇÿ<egitem name=ÔÇØTestÔÇØ>MyResult</egitem>ÔÇÖ
(2) [<label>]<Variable>[:=<Operation>]
Assigns a value (string or numeric) to the EG global variable, and the result is displayed in the XML page. If the Operation is surrounded by ( and ), then the Operation will be evaluated and the result assigned to the EG global variable, prior to it being displayed.
(3) [<label>]<Operation>
Simply displays the Operation. For the Operation to be evaluated, it needs to be surrounded by ( and ).

<label> := a simple string surrounded by [ and ]
If present, it will replace the ÔÇ£nameÔÇØ value in the <egitem> tag on the displayed XML page.

Good luck with it.

6 November 2013
Attachments
__init__.py
(53.27 KiB) Downloaded 228 times
Post Reply