United Kingdom
Asked — Edited

Telnet And Eventghost (Or Python)

It's been requested so here it is... a quick (and brief) look at TELNET.

First off, you can view DJ's video on TELNET for some info on how it works, here it is...

Which is great and covers the TELNET application but if you want to use something else, say EventGhost you'll need to know how.

The first steps are the same, enable the server for the board(s) you want to control, DJ covered this in the video so I wont repeat it.

Now, in EventGhost you will need to add a Python Script. This is a very basic Python script I have knocked up to show it working. You may need to change IP addresses and ports to suit your ARC but that should be easy enough to see how.

In EventGhost I have a Python Script written;

from socket import *
import time
HOST = '192.168.0.100'
PORT = 6666
ADDR = (HOST,PORT)
BUFSIZE = 4096
cli = socket( AF_INET,SOCK_STREAM)
cli.connect ((ADDR))
data = cli.recv(BUFSIZE)
cli.send('$incoming = "Hello, I am Event Ghost"')
cli.send('\n')
cli.close

HOST and PORT may need changing for you. This script simply sets a variable $incoming to be "Hello, I am Event Ghost". Run it and the command is sent to ARC, the variable is set.

I have added a simple EZ-Script to ARC, something that will use the variable that was set.

# Set up the variable so that it exists
$incoming = 0

# Set up a loop
:loop

# Wait until data received from EventGhost
WaitForChange($incoming)

# Speak the incoming text
SayWait($incoming)

# Loop back to the start
Goto(loop)

Now, the Python script will set the variable $incoming to the specified phrase, the script will see the change and will speak the phrase.

Also added is the Variable Watcher, which should show a change in the variable.

Also the debug window is added so you can see the connection happen.

Hopefully (it's currently uploading) here is a video of the example code above working and ARC being controlled by EventGhost... NOTE: TURN DOWN YOUR VOLUME! The sound went a bit wrong, I guess I forgot to set the audio device and it used the mic not the speakers so sound is messed up and very loud.

I also showed some other script commands, however the servo one didn't work but that was due to not being connected to an EZ-B at the time of testing. I'm too lazy to cut it out of the video.

Hopefully that should give an indication in to how to get EventGhost (or anything that uses Python) to talk to ARC. Writing the Python scripts is a more in depth process and there is a multitude of resources on the internet which should be able to help you work out how to write the code which sends other variables in to ARC (I am unable to show my code which creates the cli.send at this time due to a whole bunch of things that are going on with Jarvis right now - sorry it's vague, I wish I could say more).


ARC Pro

Upgrade to ARC Pro

Subscribe to ARC Pro, and your robot will become a canvas for your imagination, limited only by your creativity.

#9  

This is really cool. I am blown away by ARC more each day. Thanks Rich for posting this and Thanks DJ and team for adding such cool features to the platform.

United Kingdom
#10  

I remember why I can't find what I'm looking for in EventGhost and that's because I did ARC to EventGhost via HTTPGet() and a web page running on my home server which communicates with Event Ghost.

I think I have posted the PHP code before but I'll post it again later (tomorrow) when I get the chance.

New Zealand
#11  

Yes I've read that Rich.... I would have done something similar but I'm hoping for a different method.... perhaps something along th lines of a command like

exec telnet "variable=:=success"

I am sold on EZ-Robot but I want to pass off some of the mundane things to EG to manage. I need to have ARC intelligently feed back to Eventghost a change of status confirmation that it has completed an action.

Hence the need for two way communication....

New Zealand
#12  

Looking around the web and at a few of your earlier posts in the Artificial Intelligence thread I got to thinking about the exec command in ARC. ... and wondered if we could trigger an event in Evenghost from the command line.

I found a post on an Android phone forum for two Apps called Autoremote and Tasker. Their "tips and tricks" page gave an example of a phone triggering an action in EventGhost.

Eg. "C:\Program Files (x86)\EventGhost\EventGhost.exe" -event CoolEvent payload

So I got to fiddling around and .... Exec("Eventghost", "-event Media_Player_On" ) or Exec("Eventghost", "-event Media_Player_Off" ) works a treat!

Eventghost receives the request and looks for the event trigger... assuming you have placed that trigger in a macro you have created earlier you can execute anything you like!

Now...... You posted in the Artificial Intelligence thread that you had been doing some

Quote:

...integration via Telnet so that ARC (and it's scripts) are aware of everything they need to be aware of (i.e. if media playback starts, EventGhost sends ARC a script command $mediaplayback = 1, when it's finished it sends $mediaplayback = 0 (that's a very simple example, it also sends more info on the media).

Can you enlighten me how you passed the variables you store in EG via telnet to EZB?

Just the line syntax will do. Does it behave as if it were a direct console variable entry? Eg. $Apples=1
or do I have to do something extra?

How does EZB convert the Telnet line into a variable without some elaborate sequence of inputs being manually connected.... ie Send#54=$Apples, Send#55=pears ?

@Tameion

United Kingdom
#13  

I don't currently pass variables from EG to ARC, I set variables in ARC using EG.

My python script example shows how this is done, simply updating a variable with the script command $incoming = "Hello World"

I have had EG send it's variables data to ARC (i.e. current electrical load on th emains incoming electrics, room temperatures etc.) previously however I have since upgraded the PC and didn't carry those python scripts over as I prefer to use ARC to fetch that data directly from the MySQL server (which EG writes to).

I'll have to find my old notes on it which is more than just difficult with the way I file things... When I find them I will look but to be honest I wouldn't hold your breath, I have a million and one other things to do at the moment unfortunately.

New Zealand
#14  

@Rich

I won't Rich.... and please stop looking!

And thanks for your faithful support of the community.

I suspect our journeys have been very similar but you're a step or two ahead of me and if you've moved away from passing variables via telnet then using a SQL database to store and manage the variables is obviously the way to go....

I had planned for that ultimate eventuatility ...

I take it that you grab your data from media XBMC's database as well?

  • Wayne
United Kingdom
#15  

Yep, and XBMC is set up for MySQL too (I have a multi seat install so one database works best for me - upnp probably would work better but it was originally set up before upnp was introduced). I have heard that MySQL support is to be dropped from XBMC/KODI at some point though.

Everything in one easy to use database, simple PHP pages to pull the specific data when needed and HTTPGET() for ARC to get those details. i.e. HTTPGet("http://192.168.0.107/Jarvis/humidity.php";) will get the current humidity. HTTPGet("http://192.168.0.107/Jarvis/currentpower.php";) will get the current load on the power to the house.

All very simple PHP pages, based off of a simple template but the SQL query changes for each and then it just return the value in plain text on the page, no frills, no extra formatting, just the value so the variable is nice and easy to use.

I also have a more complex PHP page set up which displays everything with fancy graphics etc. but ARC doesn't like the returned results that much.