Posts

ZWay: notification on wake-up events

Z-Wave battery powered devices implement a periodic "wake-up" where it contacts the controller; for the door sensors I am using, I configured the wake-up to happen every 5 minutes. Now, how to capture this in the ZWay library? It is again the same as for other events: register a callback on a certain "data holder". Here this data holder is found on: device instance level; command class: 132 (wake up); path: "lastWakeup" (there is also another one "lastSleep", so far it is not clear to me which one is the best to use). Here is a sample code registering a call-back for this event: zway_data_acquire_lock(aZWay); ZDataHolder dataHolder = zway_find_device_instance_cc_data(aZWay, mDeviceId, 0, COMMAND_CLASS_WAKE_UP, "lastWakeup"); if (dataHolder != NULL) { zway_data_add_callback_ex(aZWay, dataHolder, &aliveCallback, TRUE, this); } else { cerr << "No data holder for deviceId=" << (int) mDeviceId...

From Z-Wave to my phone!

Now that I know a bit better how to use the ZWay library, and that I refreshed a bit my C/C++ knowledge, I can finally complete the first use-case of my home security system: getting notified of an event on my phone (my good "old" HTC Legend running Android 2.2). For a long time I have been wondering and hesitating about the "server" part of my system. The Raspberry Pi could of course play this role, but it would not be "safe" since cutting the home power or un-plugging it would void the "security system". Yes of course I could put the Raspberry Pi on battery, hide it somewhere in the house and use WiFi to connect to others networks in case my home Internet connection would drop, but then again, cutting the power of the whole neighborhood would still kill my system. So it had to be something external. Looking at prices for getting my own Linux private server, that would be something like 5-15 Euros a month. That sounds rather stupid since for...

ZWay: notification on event (continued)

After getting your hand on a Z-Wave data holder in the ZWay library, the next step is to register a listener for getting notified when a change occurs on this data. The ZWay library provides the following methods for managing data holder listeners: zway_data_add_callback() zway_data_remove_callback() zway_data_add_callback_ex() zway_data_remove_callback_ex() zway_data_acquire_lock(aZWay); ZDataHolder dataHolder = zway_find_device_instance_cc_data(aZWay, 2, 0, COMMAND_CLASS_SENSOR_BINARY, "level"); if (dataHolder != NULL) { zway_data_add_callback_ex(aZWay, dataHolder, &dataChangeCallback, TRUE, this); } else { cerr << "No data holder for deviceId=" << (int) mDeviceId << endl; } zway_data_release_lock(aZWay); The following code will register the following "dataChangeCallback" function in the ZWay stack and make sure it is invoked when the Z-Wave binary sensor with node ID 2 gets triggered. void dataChangeCallba...

ZWay: notification on event

Having now my sensors now installed "properly" (well, the sensors are hell to mount on PVC) on the door and windows at home, it is time to set-up my little ZWay application to get notified when these sensors are generating some events. More precisely, when a window or door gets open... The ZWay API provides the possibility to install some callbacks when "data holder" are changed. Therefore the first thing to investigate is the data holder. There are a few functions to get a hand on a data holder: zway_find_data(...) That one requires a data holder as argument, so that's not the one we need. zway_find_controller_data zway_find_device_data zway_find_device_instance_data zway_find_device_instance_cc_data These are the functions to use; to get the "root" of the data holder, you can simply provide an empty string as parameter e.g. ZDataHolder dataHolder = zway_find_device_instance_cc_data(theZWay, 2, 0, 48, ""); Given a bit o...

ZWay: getting the device list.

Back after a while... and a son! Here is a piece of code that can be used with the latest version of the ZWay library. It makes it possible to retrieve the Z-Wave device list and display the device names and associated XML file (each recognized device can be associated to an XML that contains a bunch of meta-data: name, description etc.). int main(int argc, char ** argv) { ZWay theZWay; ZWError result; memset(&theZWay, 0, sizeof(theZWay)); result = zway_init(&theZWay, "/dev/ttyAMA0", "/home/pi/src/razberry-proxy/config", "/home/pi/src/razberry-proxy/translations", "/home/pi/src/razberry-proxy/ZDDX", stdout, Warning); if (result == NoError) { result = zway_start(theZWay, &terminationCb); if (result == NoError) { printf("Discovering...\n"); result = zway_discover(theZW...

First steps with the ZWay library

The Z-Wave "RaZberry" installation comes with everything needed to be able to do some custom development in C; everything is installed in the /opt/z-way-server  directory. There, one can find: A set of (documented, nice!) C header files found in /opt/z-way-server/libzway-dev : CommandClassesPublic.h FunctionClassesPublic.h ZDataPublic.h ZDefsPublic.h ZErrors.h ZPlatform.h ZWayLib.h A set of libraries found in /opt/z-way-server/libs : libmicrohttpd.so libv8.so libzwayhttp.so libzwayjs.so libzway.so For the ZWay stack to run properly, it is needed to provide the necessary configuration files. Instead of using these directly from the installation folder, I made a copy in order not to mess up too much with my working/configured setup. The following directories from the ZWay installation folder are needed: config translations ZDDX For experimenting I made a small Makefile in order to build and run. main.out: main.c gcc -I/opt/z-way-server/li...

More toys: Razberry & sensors!

Image
Having a "Raspberry Pi" as a DHCP server is of course not my end goal. There are plenty of ideas I have about what it could do... Home automation is one of them. So finally, after a long time hesitating between various extensions, devices and technologies, I finally ordered some new fancy toys: First of all, a Z-Wave extension board for the Pi: the "Razberry" from Z-Wave.me . Unfortunately expensive (but well, a USB dongle is also too), but quite a nice little extension board. A set of Z-Wave sensors; as security was my wife first concern and my budget limited, I bought three door/window contact detectors ( SM103 from Everpring ). Z-Wave  seems to be definitively an expensive choice compared to ZigBee , but well, at least I found easily some devices, and guess what, so far it works out-of the box!  So now, time to look at APIs and see how to get further... As a start, I would like to be able to control things from my phone and be able to get notified w...