Page 21 of 23
Re: Webserver
Posted: Sat Mar 30, 2019 7:48 am
by kgschlosser
that is why a slider control is a better way to go instead of using a volume up or down when using a web app.
the logic is really simple to achieve even if you do not have a direct entry of the volume available. so long as you have a reporting of the current volume level. you would have the websocket event get generated in EG with the new volume and then in a script you can do something like the following.
Code: Select all
import time
new_volume = eg.event.payload
while eg.plugins.SomePlugin.GetVolume() != new_volume:
eg.plugins.SomePlugin.VolumeUp()
time.sleep(0.05) # 50 milliseconds is about the average for what a remote api can do for speed
[code]
Re: Webserver
Posted: Sun Mar 31, 2019 3:51 pm
by yokel22
therealbiglou wrote: Fri Mar 29, 2019 2:17 pm
I think what I could do is contain each remote interface into its own DIV and show/hide each DIV through JS. So, if EG sends an event like webserver.remote.cable, it would hide all DIVs without the ID of #cable and only show #cable. Does this sound feasible?
You shouldn't use #id's for multiple items. Use "class" instead. Id's are unique, classes are meant to apply to multiple items.
Re: Webserver
Posted: Sun Mar 31, 2019 4:53 pm
by kgschlosser
here is a link to learn how to make a slider in javascript. it is very simple to do.
https://www.w3schools.com/howto/howto_j ... slider.asp
Re: Webserver
Posted: Mon Apr 01, 2019 8:49 pm
by therealbiglou
yokel22 wrote: Sun Mar 31, 2019 3:51 pm
You shouldn't use #id's for multiple items. Use "class" instead. Id's are unique, classes are meant to apply to multiple items.
I've got it set up so each interface is contained in their own unique div with a unique ID. So, I have IDs of:
#RemoteCable
#RemoteStreaming
#RemoteChromecast
etc.
It was trivial to then hide/show the appropriate div based on what was going on inside EG. This actually works exceptionally well!
Re: Webserver
Posted: Tue Apr 02, 2019 7:00 pm
by yokel22
That's how id's should work. The way you described it. It sounded like you were going to try & use the same id on multiple divs. This can cause a number a # of problems for the webserver plugin..
Alternatively, you can use a class selector to hide/show multiple items with the same class with one variable change if need be.
Re: Webserver
Posted: Sun Jul 28, 2019 4:23 am
by davlind
Hi I am new to EventGhost but I have a simple question about Webserver. I have used Webserver to receieve a message from IFTTT via webhooks with a variable. In my macro I can access the variable value with {eg.event.payload[0]} in MS command and in an email, but I cannot send the variable value back to IFTTT (webhook) via Webserver send to another webserver. The format is:
https://maker.ifttt.com/trigger/EGReply ... .payload[0]}
and I have tried different formats of {eg.event.payload[0]}, i.e. {{eg.event.payload[0]}}, eg.globals.item etc.
I create a eg.globals.item variable in a little python script, et persistent variables.
I am sure I am making a very obvious error but the links to Webserver seem to be broken. Can anyone assist me.
Re: Webserver
Posted: Fri Aug 09, 2019 4:25 am
by leejk
Hi,
Read thru most of this post but did not see my answer. I'm wanting to send a json object to the EG web server, but not sure what the steps are to make use of the json data inside EG. Basically I want to read the json data object, then in EG fire events based on evaluation of that data. Could someone explain the basic steps to accomplish this?
thx
Re: Webserver
Posted: Fri Aug 09, 2019 6:15 am
by kgschlosser
ok so the standard way of triggering an event using the webserver plugin would be to connect to the webserver using this syntax
Example:
Code: Select all
http://192.168.1.101:80?eventName&payloadValue
using that information here is what you want to do.
Code: Select all
http://192.168.1.101:80?JSON.Test.Event&JSON_DATA_HERE
ok so now on the EG end of things.
create a macro
add an event to the macro and the event is "JSON.Test.Event"
then add a python script action and paste in the code below
** the event may have a prefix in it so it can differ.
Code: Select all
import json
json_string = eg.event.payload
# this converts the json data into a python dictionary or a list of dictionaries
# depending on how the json is formatted
json_data = json.loads(json_string)
# to use a dictionary it is broken up into key: value pairs just like json is
# value = json_data['key']
# if you are not certain that a json element will be in the data then we
# want to check if it is in there first to avoid any errors.
# if 'key' in json_data:
# value = json_data['key']
print json.dumps(json_data, indent=4)
You will need to make sure you escape the json data that you add to the url. it has to be able to be sent as part of the url.
Re: Webserver
Posted: Fri Aug 09, 2019 6:46 am
by kgschlosser
If you have the ability to send the request via http POST then in the body of the POST
Code: Select all
TriggerEvent&prefix=SomeTest&suffix=Event&payload={'jsondata': 'json value'}}
This will spit out a python list as a payload and this is the code you would use to parse it.
Code: Select all
import json
json_string = eg.event.payload[0]
# this converts the json data into a python dictionary or a list of dictionaries
# depending on how the json is formatted
json_data = json.loads(json_string)
# to use a dictionary it is broken up into key: value pairs just like json is
# value = json_data['key']
# if you are not certain that a json element will be in the data then we
# want to check if it is in there first to avoid any errors.
# if 'key' in json_data:
# value = json_data['key']
print json.dumps(json_data, indent=4)
There are other commands you can use as well instead of TriggerEvent
you have
request&some_suffix&some_payload_data
GetGlobalValue&value_name&value_name&value_name...etc
ExecuteScript&python_extression&python_extression&python_extression... etc (not a python script really but a python expression. it does not use exec it uses eval)
GetValue&value_name&value_name&value_name...etc
GetPersistentValue&value_name&value_name&value_name...etc
SetValue&value_name&data
SetPersistentValue&value_name&data
GetAllValues
GetChangedValues
TriggerEnduringEvent&prefix=someprefix&suffix=some_suffix&payload=payload_data
RepeatEnduringEvent
EndLastEvent
TriggerEvent&prefix=someprefix&suffix=some_suffix&payload=payload_data
or you can also do this in the body of a POST
{'method': 'eg.globals.some_function', 'kwargs': YOUR JSON DATA HERE}
add this to a python script and place it at the verry top of your autostart group. it only needs to be run a single time on startup.
Code: Select all
def some_function(**kwargs):
# this is your json data
print kwargs
eg.globals.some_function = some_function
Re: Webserver
Posted: Sat Aug 10, 2019 11:38 pm
by leejk
@kgschlosser
Thank you for that pretty detailed explanation. I'm trying to utilize
Plex Webhooks to monitor when a video is playing. I've set them up to send the JSON payload to EG using this url:
http://192.168.0.105:80?PlexEvent
I can see the payload is being sent in the EG log window, however there is no event being listed. Where the event should be listed perhaps is an entry like: HTTP.--------------------------e694883f75b8dba0
The string is unique each time. Any thoughts on that?
I'm running 0.5 RC6
thx
Re: Webserver
Posted: Sun Aug 11, 2019 1:14 am
by kgschlosser
hmmm... we need to know exactly how the information is being sent...
a proper URL is going to be
192.168.1.1?event_name&payload_data so unless it is adding the data like that it's not going to work properly
Re: Webserver
Posted: Sun Aug 11, 2019 1:25 am
by leejk
yeah, tried most every variation I can think of... the data is being sent, but the event name is never shown, which is a problem. According to the Plex docs, "the payload is sent in JSON format inside a multipart HTTP POST request."
Now my knowledge of HTTP is limited, but could this be the issue?
Re: Webserver
Posted: Mon Aug 12, 2019 10:31 pm
by kgschlosser
OK as i stated above... if the data is being sent as a POST then you cannot make use of parameters in the URL. everything has to be sent in the body of the POST. and it MUST be formatted this way.
Code: Select all
TriggerEvent&prefix={EVENT_PREFIX}&suffix={EVENT_SUFFIX}&payload={YOUR_JSON_DATA}
you will replace the following
- {EVENT_PREFIX} - everything before the first "." in the event
- {EVENT_SUFFIX} - everything after the first "." in the event
- {YOUR_JSON_DATA} - The data you want to pass
So if i did the following.
Code: Select all
TriggerEvent&prefix=TestEventPrefix&suffix=TestEventSuffix&payload=Here is my payload data
You will get the following event in EG
Code: Select all
TestEventPrefix.TestEventSuffix "Here is my payload data"
again this is how the body of the post MUST be formatted in order to work.
the url you are going to use is going to need to be formatted like this
Re: Webserver
Posted: Tue Aug 13, 2019 1:01 am
by leejk
Thanks, I get it now. I was able to see it working in EG by using the POSTMAN extension in Chrome.
Unfortunately, Plex does not let me alter the payload data sent, so I can't add the TriggerEvent. What options are left do you think?
Re: Webserver
Posted: Wed Aug 14, 2019 6:42 am
by kgschlosser
there are always options.... let me hammer something together for ya.
are you able to specify the connection port in plex?