event handling

Discussions about RaZberry - Z-Wave board for Raspberry computer

event handling

Postby scarm » 09 Apr 2013 13:43

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
scarm
 
Posts: 1
Joined: 09 Apr 2013 13:34

I was about to post the same

Postby pz1 » 09 Apr 2013 13:43

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
pz1
 
Posts: 2053
Joined: 08 Apr 2012 13:44

Agree

Postby krambriw » 09 Apr 2013 13:43


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
krambriw
 
Posts: 46
Joined: 03 Apr 2013 18:14

There are callbacks in

Postby PoltoS » 09 Apr 2013 13:43

There are callbacks in JavaScript engine embeded in Z-Way. Use .bind() function on dataholder leaf. Like

devices[N].SwitchBinary.data.level.bind(function() {

debugPrint(this.value);
})

Please read manual for more info. Also check this article

User avatar
PoltoS
 
Posts: 3314
Joined: 26 Jan 2011 19:36

Can't make it work...

Postby krambriw » 09 Apr 2013 13:43

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

Postby krambriw » 09 Apr 2013 13:43

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 httplib

class 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 response


def do_bind(value, callback):
ret = z.performGetRequest(value)
print ret
callback(ret)


def say_value(value):
print 'Value from callback: ', value


z = 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)


 

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

Do you really think you can

Postby PoltoS » 09 Apr 2013 13:43

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).
User avatar
PoltoS
 
Posts: 3314
Joined: 26 Jan 2011 19:36

OK, I see, not possible...

Postby krambriw » 09 Apr 2013 13:43

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

Postby krambriw » 09 Apr 2013 13:43

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!

Postby krambriw » 09 Apr 2013 13:43

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, thanks

Walter

Currently 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);
}
});
krambriw
 
Posts: 46
Joined: 03 Apr 2013 18:14

Next

Return to RaZberry

Who is online

Users browsing this forum: No registered users and 2 guests