NetHome with EventGhost

Functionality and usage of the OpenNethome Server
heggholmen
Posts: 12
Joined: Thu Jan 08, 2015 7:04 pm

Re: NetHome with EventGhost

Post by heggholmen »

@krambriw: I get an syntaxError when running the script MQTTevents.py - any idea?

py C:\MQTTevents.py
File "C:\MQTTevents.py", line 32
except socket.error, e:
^
SyntaxError: invalid syntax
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: NetHome with EventGhost

Post by krambriw »

Have you had the script opened in an editor? Maybe you have made some modification that has messed up indentation? Python is very sensitive to formatting, you can not use tabs, you need to use 4 spaces instead. I recommend Notepad++.
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: NetHome with EventGhost

Post by krambriw »

I just tested to run the script inside EventGhost as a python script and it worked fine!

You have to change the ip to NetHome and the MQTT broker if they are not running in the same computer. I also changed the long delay at start up (this delay is only needed if you autorun the script at reboot to give NetHome enough time to start and
maybe the delay can be set shorter).

In my case I did the following changes

# Main starts here -----------------------------------------------------------
time.sleep(2)

#MQTT settings
mqtt_host = '192.168.10.253'

#NetHomeServer settings
hostName = '192.168.10.253'


Once you have started the python script you can stop it in two ways:
- restart EventGhost
- send a message 'nethome_disconnect' to the MQTT broker at topic '/nethomeserver/in'
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: NetHome with EventGhost

Post by krambriw »

With the above in mind, if you are running the script in EventGhost, you could actually skip the MQTT broker completely and directly from the script generate necessary events in EG. But for now, I think it is easier to keep the MQTT broker than starting to re-write the script.
heggholmen
Posts: 12
Joined: Thu Jan 08, 2015 7:04 pm

Re: NetHome with EventGhost

Post by heggholmen »

did not save changes to the files. Looked at them with Notepad++, but no save. The other scipts are working.
I'll guss i give my Raspberry a try - do you have any reconmandaition for distribution to use? (I'm only gonna use it for this:) ) (I'm really a Windows guy, that's why I moved to a Windows Server instead)

update: seems like the script was not compatible with Python 3.x - have installed 2.x and now I got a new error message, but not any syntax error:)

Traceback (most recent call last):
File "MQTTevents.py", line 4, in <module>
import mosquitto
ImportError: No module named mosquitto

Investigation continues:)

update 2: Having the two scripts in the same folder, solved the trouble:) So now I can continue with the "step by step" guide

update 3: @ krambriw
I have got the script running (MQTTevents.py) (Subscribed: 1 (0,))
I have installed the EventGhost plugin (MQTT-client) and it seem to be running (MQTT Client NetHomeServer: Succesfully connected with MQTT broker...)

Only thing missing - nothing shows in EventGhost when "cliking" around in NetHome.

Ideas?
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: NetHome with EventGhost

Post by krambriw »

0) I assume you have configured your receiver for correct protocols and that you have the tcp/udp port 8005 configured

1) Do you see events from NetHomeServer being printed in the window from where you are running MQTTevents.py ?

2) I have noticed I have a little problem with the MQTT Client plugin (I will sort that out) but double check that you are subscribed to the correct topic. You can actually set /# as topic and you should see everything

3) A good MQTT client tool is Paho. You can try that. We need to verify that events are correctly published to the broker
heggholmen
Posts: 12
Joined: Thu Jan 08, 2015 7:04 pm

Re: NetHome with EventGhost

Post by heggholmen »

Thanks krambriw

I've done some investigation, and think i can conclude with that I have some issue with MQTTevents.py. The script doesn't catch anything.
I've installed PAHO, and sent messages that is shown in the EG-log. And I've sendt message fra EG thats shown in PAHO.

But nothing is shown in the MQTTevents-script :/ Tried diffrent things, but have not got the wanted result...

From my MQTTevents-py file:

time.sleep(2)
th_abort = False
debug = True

#MQTT settings
mqtt_host = '127.0.0.1'
port = 1883
topic_in = '/nethomeserver/in'
topic_out = '/nethomeserver'

#NetHomeServer settings
hostName = '127.0.0.1'
portNbr = 8020 (have also tried default in file - 8005)
socketTout = 600
connectionError = True
event_Old = []

I've looked into the MQTTevents-py - but I'm really newbie at this. How does this script "get" the actions from the service of NetHome? Where in the code is this happening?
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: NetHome with EventGhost

Post by krambriw »

How does this script "get" the actions from the service of NetHome? Where in the code is this happening?
It is handled by a separate thread in the function "def outgoing(outThreadEvent):". They way it is written, the thread is connecting to NetHome port 8005 and subscribing to events and you should see them all being printed in the command window if it is working correctly.

Why you use port 8020, that's the web server port, you must use the TCP/UP port 8005 (unless you have changed it). How does your NetHome configuration look like? Do you have the Port objects 'TCP Command Port' and 'UDP Port' defined?

You can also try to connect to that port with a Telnet session to verify that it is up. You should then see events in the Telnet session. If not, that is where you have a problem.

In the Telnet session, type

o 127.0.0.1 8005 and press Enter

press Enter again

and you should se 'ok' as response

Type subscribe and press Enter

Create or wait for events....


PS I have updated the MQTT Client for EventGhost, you find it here
http://sto.hopto.org/index.html
krambriw
Posts: 86
Joined: Sun Jan 04, 2015 8:48 am

Re: NetHome with EventGhost

Post by krambriw »

I have additional questions to you how you are running the various sw's and in what order you are starting them

1) How and when do you start the python script? (If you start it at the same time as BetHome it might be the problem. Be sure that NetHome is started before you subscribe to events. That is why I have 120 seconds before I try. SO instead of
time.sleep(2)
I have
time.sleep(120)
since my script is starting at boot time

2) Do you run EventGhost, NetHome and the python script in the same PC?

3) Are you running Windows 7 64Bit? If so, have you tried to run all sw as admin?
heggholmen
Posts: 12
Joined: Thu Jan 08, 2015 7:04 pm

Re: NetHome with EventGhost

Post by heggholmen »

1) time.sleep(2) or time.sleep(120) don't give any difference (but wating 2 miniutes instead of 2 sec when I'm starting everything manual to get it working).

2) yes - everything is hosted on the same computer

3) running windows 8.1 PRO 64bit. Have tried to run everything as "admin" but "NetHome". When trying to run NetHome as admin, i get error message "---------------------------
Java Virtual Machine Launcher
---------------------------
Error: Unable to access jarfile home.jar


Edit: And now i saw your previous post - I have not added the TCP / UDP ports in NetHome - so this is properbly understandable. I'll try this later this evening - think we are closing in now... :oops:
Post Reply