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 »

Hi drhyoung,

next time you should maybe ask for a solution to your problem before starting to change the plugin.
I mean, I'm sure you spent some time with the code if it's your first Python experience.
That maybe could have been avoided.

The only thing that is not possible with the plugin as it was using GET is:
Will be in the resulting XML page as ÔÇÿ<egitem name=ÔÇØTestÔÇØ>MyResult</egitem>ÔÇÖ
To be honest I don't see a reason for this using GET, but hey, I guess you see one.

setting a variable with GET could have been done previously with a simple Python script like this:
1.PNG
1.PNG (3.52 KiB) Viewed 9251 times
that's inside the script:
2.PNG
2.PNG (6.39 KiB) Viewed 9251 times
(just one line!!)

how to use:
http://<ip or hostname>?setVar&<name>&<value>

and you will get:
3.PNG
3.PNG (5.33 KiB) Viewed 9251 times
TADAA!! ^^
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 everyone,

I made some changes on the plugin again!

What's new?
- added menue entries (plugin configuration) to customize the join strings in the do_POST Enhancement by Sem;colon
1.PNG
1.PNG (9.93 KiB) Viewed 9240 times
- improved handling of some returned datatypes in the do_POST Enhancement by Sem;colon
- fixed bug in end_request (length was not always calculated correctly)

@drhyoung: Sorry, I didn't worked your improvements in for several reasons:
#1: GET requests can be cached by a Browser - so retrieving variables with GET is not very reliable.
#2: It's not allowed for plugins to write in eg.globals... see notes for plugin developers.
#3: I can't think of a use case - can you maybe describe one?
Attachments
__init__.py
v1.8
(53.1 KiB) Downloaded 250 times
If you like my work, Image me a drink :wink:
drhyoung
Posts: 4
Joined: Wed Nov 06, 2013 7:25 am

Re: Webserver

Post by drhyoung »

Hi Sem;colon,

thanks for the feedback.
yes, I am very much the newbie.

I did actually start out researching events and payloads, almost exactly as you have described.
But I couldn't see an easy way to retrieve the values that I had used events and payloads to set.

I have 4 iRule iOS remote apps and have some variables and values that all the remotes need to know about, for example the current TV channel and whether a stereo device is on or off.
The apps are quite dumb when it comes to GET and POST calls.
On searching the web for how to use Webserver to easily do what I wanted, I did find a number of other postings from people who appeared to be looking for something simple also.
When I thought about my requirements, I was thinking, speed (sending and retrieving the states quickly) hence a number of calls in one GET.
I was also looking to record, increment, decrement and capture the setting of channel numbers.
I do see that I would need to add the HTTP header "Cache-Control: no-store" - thanks.

Happy to update the code I've added, or not, as you wish.
Let me know.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

Hi drhyoung,

I See, I never used iRule (and maybe never will be)
I have one question: Does it realy need to be that flexible that the Plugin creates the page?
Wouldn't it be OK to write templates with: <egitem name=ÔÇØTestÔÇØ>{{eg.globals.yourVarName}}</egitem> inside ?
If you like my work, Image me a drink :wink:
drhyoung
Posts: 4
Joined: Wed Nov 06, 2013 7:25 am

Re: Webserver

Post by drhyoung »

Hi Sem;colon

I tried creating a page that included {{eg.globals.Testing}} , then setting the variable eg.globals.Testing in EG, then did an http GET on the page I'd created.
It simply displayed " {{eg.globals.Testing}}" to me, ie the variable in the web page wasn't interpreted.
I tried a few other things, because I figured that I must have done something wrong because the {{ }} worked in the original version of the Plugin.
It was then that I thought I needed to have a look at the python. And before I knew it, rather than fixing the {{ }} problem, I thought I might be able to do something more useful for users/configurers of programmable remotes.

But not to worry. It works for me. And it wouldn't even be there for me to use if it wasn't for you, Pako and Bitmonster.
So, thanks.
drhyoung
Posts: 4
Joined: Wed Nov 06, 2013 7:25 am

Re: Webserver

Post by drhyoung »

You got me wondering...
If the web page has a filetype of ".htm" then {{ }} does work.
Apologies for the slack testing.
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

Hello Everyone,

I get an error when trying to save a specific string with "SetValue" or "SetPersistentValue":
Unbenannt.png
Unbenannt.png (3.41 KiB) Viewed 9145 times
As you can see the string has "{" and "}" in it, so this is the reason for the error.
Is there a possibility to avoid the error (other then replacing the "{" with something else, I would like to keep the string as it is)?

Sem;colon
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 »

I think it is (within EventGhost) quite a common problem.
It occurs in all places where the function eg.ParseString() is used.
There are several solutions. For example:
1) We can create an alternate function as the function eg.ParseString(), but more tolerant.
The importance of the brackets {} should be maintained.
2) Or we can create an alternative function, such as the function eg.ParseString(), but with a different algorithm.
For example, triple braces {{{some expression}}} would serve as the beginning and end of the expression, intended for parsing.
3) We can only handle errors - for example, like this:

Code: Select all

    def __call__(self, varname = "", value = "{eg.event.payload}"):
        try:
            key = eg.ParseString(varname)
        except:
            eg.PrintError(self.text.err % (str(varname), str(value)))
            return
        try:
            value = eg.ParseString(value)
        except (NameError, SyntaxError):
            value = value
        except:
            eg.PrintError(self.text.err % (str(varname), str(value)))
            return
        self.plugin.SetValue(key, value)
4) ...


In any case, the problem is backwards compatibility.
Which solution will cause the least amount of problems?
I do not know.

Pako
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

hmm, what about an extra switch?
e.g. a checkbox in Set...Value for "disable variable recognition" which, if true, bypasses eg.ParseString?
That shouldnÔÇÖt cause any problems with backwards compatibility.
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:hmm, what about an extra switch?
Yes, it is a good idea.
I assumed that there are many other solutions (that's why I wrote 4) ...).
In attached file it is already done.
Note: untested

Pako
Attachments
__init__.py
Version 1.9 - updated 2013-12-04 14:36 UTC+1
(54.15 KiB) Downloaded 232 times
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

Hi Pako,

there was a little bug in line 862 and 863 which caused EG to hang; I fixed it.

EDIT:
I also removed decoding of the return value for the SendEventExt action (could cause problems sometimes)
the code must now be decoded in a script manually (if decoding is needed)
Attachments
__init__.py
Version 2.0 - Bugfix 2014-01-04 22:15 UTC+1
(54.45 KiB) Downloaded 221 times
Last edited by Sem;colon on Sat Jan 04, 2014 9:28 pm, edited 1 time in total.
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 »

Hi Sem;colon,
I thank you. I do not see how I could screw up like this. :oops:
I tried it and it worked. And then I apparently changed it... :)

Pako
radenblazed
Posts: 9
Joined: Fri Jan 10, 2014 4:50 pm

Re: Webserver

Post by radenblazed »

ok so i made a webserver and would like to publish it via my apachi server im currently running... the problem is that the page only works when im using
http://localhost/index.html instead of the no-ip.com dns i have set up... how can i fix this? thank you
radenblazed
Posts: 9
Joined: Fri Jan 10, 2014 4:50 pm

Re: Webserver

Post by radenblazed »

I made a webserver using eventghost and would like to publish the page via apachi... the problem is that it only works when i use http://localhost/index.html instead of the no-ip dns im currently using... is there a way to fix this? thank your
Sem;colon
Plugin Developer
Posts: 625
Joined: Sat Feb 18, 2012 10:51 am
Location: Germany

Re: Webserver

Post by Sem;colon »

can you please give us a bit more details what you are trying to do.
Or what you did and what of that works and what doesn't?
If you like my work, Image me a drink :wink:
Post Reply