event handling

Discussions about RaZberry - Z-Wave board for Raspberry computer
scarm
Posts: 3
Joined: 09 Apr 2013 13:34

event handling

Post by scarm »

A question regarding "catching state changes" in with the RazBerry:
I wonder how I could catch an event when e.g. the physical light switch is clicked.
Would I have to create a script a (e.g. python) that constantly monitors the state of the switch? Or is there some other way to get notified when the event is triggered (i.e. state is changed)? Which would be less resource consuming for the rpi
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

I was about to post the same

Post by pz1 »

I was about to post the same question. I don't see a change in the GUI either after using the manual switch. Sometimes, after a manual switch the on/off buttons in the screen also seem no longer functional. May have to do with the ambiguous state?

I also noted, that after a while the device seems dead for a prolonged time. I haven't been able to reproduce those "dead" switches consistently, so I did not report this yet.
Your post triggered me to share my experiences now.
Since 29-12-2016 I am no longer a moderator for this forum
krambriw
Posts: 46
Joined: 03 Apr 2013 18:14

Agree

Post by krambriw »


Agree, it would be very nice to have a built in callback mechanism that could be subscribed to.

Is there anyone who has made a sample in python that has callbacks function implemented?

I try to avoid creating a polling thread....

Best regards, Walter
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

There are callbacks in

Post by PoltoS »

There are callbacks in JavaScript engine embeded in Z-Way. Use .bind() function on dataholder leaf. Likedevices[N].SwitchBinary.data.level.bind(function() {
debugPrint(this.value);
})Please read manual for more info. Also check this article
krambriw
Posts: 46
Joined: 03 Apr 2013 18:14

Can't make it work...

Post by krambriw »

Hi, spent some hours trying with urls and java consol, see no callbacks yet.

Is there a simple way with a url of setting up a callback that gives ALL events. Like
http://ip_to_raspberry:8083/JS/Run/zway....

BestR Walter
krambriw
Posts: 46
Joined: 03 Apr 2013 18:14

I have tried a bit further to

Post by krambriw »

I have tried a bit further to create a python script in trying to get the callback with value but it does not work :-(I think it is because the callback function is incorrect. Any hints?Best regards, Walter 

import httplibclass ZWay: def __init__(self, address): self.address = address def performGetRequest(self, requestString): response = None try: self.conn = httplib.HTTPConnection(self.address) self.conn.request('GET', requestString) res = self.conn.getresponse() except: print 'ERROR: __performGetRequest' res = None if res: if res.status == 200: response = res.read() else: print 'ERROR:', res.status, res.reason return responsedef do_bind(value, callback): ret = z.performGetRequest(value) print ret callback(ret)def say_value(value): print 'Value from callback: ', valuez = ZWay('192.168.10.248:8083')z_bind = '/ZWaveAPI/Run/devices[2].instances[1].SwitchBinary.data.level.bind(function(){say_value(this.value);})'do_bind(z_bind, say_value)
 
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Do you really think you can

Post by PoltoS »

Do you really think you can mix server side JavaScript with client side Python?

It is not possible to instruct JavaScript on the server to call Python function on the client as a callback! JavaScript on the server side can execute server side JavaScript only!

For client-server interaction we have implemented /ZWaveAPI/Data/ mechanism. You can see the http://z-wave.me/content/z-way-api page to see how to do it (inthis example the client is also JavaScript in the browser, but this can be also done in Python).
krambriw
Posts: 46
Joined: 03 Apr 2013 18:14

OK, I see, not possible...

Post by krambriw »

OK, I see, not possible...Would it really not be very interesting to have such a server functionality built in? I have worked with websockets, xPL etc and I think it would be of great value if this would be included by default. It would be so much easier to integrate.My wish/proposal would be a websocket server..Best regards, Walter  
krambriw
Posts: 46
Joined: 03 Apr 2013 18:14

Another option

Post by krambriw »

I try right now is to make a python script (on the server side) with socket communication.

Best regards, Walter
krambriw
Posts: 46
Joined: 03 Apr 2013 18:14

Working!

Post by krambriw »

So I got it working...using a python script with socket communication over TCP and a similar receiver in my client (EventGhost). So far so good.Now my questions: 1) I am interested in EVERY device event in z-way, how shall I bind the function? Do you support wild cards like * or ?2) How can I add several arguments to the system( call? Like this.value arg2 arg3 etc)Best regards, thanksWalterCurrently my_main.js looks like this:zway.devices[2].instances[1].SwitchBinary.data.level.bind(function() {
try {system("python /home/pi/Desktop/network_send.py", this.value);} catch(err) {debugPrint("Failed to execute script system call: " + err);}});
Post Reply