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.

On Screen Menu over a LAN

If you have a question or need help, this is the place to be.
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

On Screen Menu over a LAN

Post by WharfRat »

This topic is an exploration of something which started as a question in another topic.

Motivation:
I need to be able to control other computers on the LAN with EventGhost.
I already use Network Event Sender/Receiver (NES/NER) to do that, so that is not a problem.
I use the On Screen Menu (OSM) to switch contexts, and to choose computers.
One problem is: I sometimes have to look at the screen of the other computer to see the menu.
Fortunately, OSM has the show menu, created from expression Action which can come to our rescue.
I understand how to use the expression to show the menu, so that is not a problem either.

Setup:
I use a simple LAN consisting of a crossover cable between two computers.
Let us represent the two computers as PC1 and PC2.
Let us use PC1 as the network name of PC1, and PC2 as PC2.
I use static IP addresses.
Let us use 192.168.0.1 as the IP address for PC1, and 192.168.0.2 for PC2.
(Of course, all of this will be different for each of us, but that should not be a problem).

Here are some problems I need to solve:
1. How to send the tuple representing the menu across the LAN.
2. How to obtain the IP address of the local computer.
3. How to detect the presence of a remote computer.
4. How to configure an instance of NES for each detected computer.
(There might be other unforseen problems also).

I have some ideas for some of the problems already.
For instance, for problem 3: use a UDP broadcast of the local IP address during Main.OnInit, and then TCP acknowledges with IP addresses from the remote computers.

For now, let us focus on each problem individually, before moving on to the others.
So, we will start with problem 1, and ignore the others.

Let me provide sample configurations for PC1 and PC2 that we can use as a common base.
PC1_and_PC2_v01.zip
(5.37 KiB) Downloaded 169 times
They use a generic desktop remote, and some simple contexts, but the contexts are slightly different from each other.
One of the contexts is used to switch to the other computer.
The OSM will always use {eg.globals.currentmenu} to show the menus.
Each computer has {eg.globals.localmenu} in which to store its own main menu.

Setting up:
Decide which of your computers will be PC1 and PC2, then load PC1.xml and PC2.xml into them respectively.
Reconfigure the NES plugin in each configuration to point to the other computer.
Then save the configurations (and make backups of them?) before proceeding.
Play around with the configurations to familiarize yourself with them.
The Fn button activates the OSM.

Of course, you need to be able to see both screens at the moment.
(I usually use the Remote Event Mapper to consolidate remote control events, but it has not been used here).
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

Problem 1: How to send the tuple representing the menu across the LAN

We need to get the {eg.globals.localmenu} from the remote computer into {eg.globals.currentmenu} on the local computer.

It would be possible to send strings across the LAN, but it seems very clumsy. There must be something simpler.

I wish we could pickle a tuple over the LAN, but as far as I know - we cannot.

Any suggestions?
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
jonib
Plugin Developer
Posts: 1328
Joined: Thu Mar 26, 2009 9:33 pm
Location: Sweden

Re: On Screen Menu over a LAN

Post by jonib »

WharfRat wrote:I wish we could pickle a tuple over the LAN, but as far as I know - we cannot.
Don't know if it's clumsy, but if you can send a string over the network you can base64 encode the tuple pickle to send it as a string.

jonib
XBMC2 plugin to control XBMC. If you want to flatter me Image
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: On Screen Menu over a LAN

Post by Pako »

Another way to convert a tuple to a string, is json.dumps.
Original data then you get back using json.loads.

Pako
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

The json technique is excellent.

I have managed to send the string across the LAN using NES/NER.

Now I will try to figure out how to send it as a payload.

Thanks...
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: On Screen Menu over a LAN

Post by krambriw »

Check out the Broadcaster plugin, it has this feature to separate the payload
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

Thanks...

I was looking at the source for NES, and it seems that the eg.plugins.NetworkSender.plugin.Send(self, eventString, payload=None) can accept a payload if you call it from Python.

A payload cannot be specified when using the NES Map action.

If payloads don't work with NES, then I will check out Broadcaster.
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

Just a quick update...

I have successfully sent the tuple representing the menus across the LAN using NES/NER.
And, I have succeeded in displaying the menu from the other computer on the local computer.

I am currently working on sending the menu choice back to the other computer.

I will eventually abandon the NES/NER, because that combination will only handle 2 computers on the LAN.
Broadcaster, or TCPEvents, seem like better options.
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
eatmeimadanish
Experienced User
Posts: 118
Joined: Thu Oct 01, 2009 5:11 pm

Re: On Screen Menu over a LAN

Post by eatmeimadanish »

Wouldn't the web service be a much easier way to do this? The requests plugin is perfect for this.

Or running a small database (postgres for instance) and having the clients access that database could be all you need to transfer large amounts of data too and from quickly.
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

eatmeimadanish wrote:Wouldn't the web service be a much easier way to do this? The requests plugin is perfect for this.
I agree that the web service is probably much easier (although I have not heard of the requests plugin, I will look for it).
However, the question that I posted earlier, was to find interesting applications for the OSM show menu, created from expression Action.
I just thought that this might serve as such an example.
Or running a small database (postgres for instance) and having the clients access that database could be all you need to transfer large amounts of data too and from quickly.
That would be overkill for the small amount of data that needs to be transferred in this case.

Thanks for the input, it reminds us that there are other ways of approaching something.
(In US English: "There is more than one way to skin a cat...")
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

Just a quick update...

Here are modifications to the sample configurations that display the menus of the remote computers.
PC1_and_PC2_v02.zip
(5.57 KiB) Downloaded 153 times
The logic of the configuration trees is not perfect.
Once you have displayed the menu of the remote computer on the local computer, it remains visible on the remote computer.
I understand what I have done wrong.
The mistake is keeping the logic of the original sample configurations while trying to add the remote menus.
This means that we have to deal with synchronizing the menu display and navigation on both computers simultaneously.
Clearly that is too much work.
It is easier if we deal with the menu of the remote computer on the local computer only.
Why should the remote computer really care?

I just wanted to show you that the transfer of the menu tuple works.
The configurations to implement just one instance of the remote menus will be here soon.
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

OK...

The menu over the LAN is working now.
PC1_and_PC2_v03.zip
(5.62 KiB) Downloaded 176 times
The logic of the configuration tree is simpler now, although it still needs some work.
It definitely is not ready for sub-menus yet.

I will clean it up a little more before we move on to the other problems.
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

I have reorganized the configuration tree substantially.
PC1_and_PC2_v04.zip
(5.63 KiB) Downloaded 174 times
The items have been grouped more logically.

It still does not handle submenus, but that is usually up to how you like to implement them.

Now we can move on to the rest of the problems.
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

Problem 2: How to obtain the IP address of the local computer

I suppose I should look at the Ping plugin to get the IP address, although I have never used it before.
I will take a look.

In addition, I would like to get the network name of the local computer also.
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
User avatar
WharfRat
Experienced User
Posts: 159
Joined: Wed Dec 25, 2013 11:56 am

Re: On Screen Menu over a LAN

Post by WharfRat »

OK, I figured out problem 2.

Code: Select all

import socket
eg.globals.local_computer_name = socket.gethostname()
eg.globals.local_computer_address = socket.gethostbyname(socket.gethostname())
But, it took me a while to figure that out correctly.

Let me explain.
As I said earlier, my network is quite simple, just two computers and a crossover cable.
This means that the two computers are often not connected together.
While I was testing the socket interface, they were not connected.
So all the Google search results for the IP address kept giving me the "wrong" answers.
i.e. socket.gethostbyname(socket.gethostname()) gave me '127.0.0.1'.
After an eternity, the light in my head switched on again.
When both computers are connected and powered up I got '192.168.0.1' and '192.168.0.2'.

This brings two important facts to the forefront.
1. there is a way to detect if the computer is connected to the network or not
2. my bookshelf of Python books is still not complete

Fact 1 is immediately useful.
Fact 2 led me to The Standard Python Library by Fredrik Lundh, although it only covers Python v1.5.
A better book is The Python Standard Library by Example by Doug Hellman, good but expensive.

I will incorporate the problem 2 solution into the ongoing configuration trees and post it here soon.

If anyone here with a more elaborate LAN, i.e. hubs or switches etc., can give me info about the LAN connection status, I would be interested about that.

Our quest for fully automatic and self-configuring on screen menus over the LAN is progressing nicely...
EventGhost 0.4.1.r1640
PHX01RN plugin v3.0.1
Windows XP 32bit (v5.1 Build 2600 Service Pack 2)
Windows7 64bit (v6.1 Build 7601 Service Pack 1)
Post Reply