Posts

Remote control, 24/24h, under all circumstances via Google pubsub

For my home alarm system, I defined the following important requirements: It should be possible to contact and control remotely (e.g. turn off/on the alarm while not at home) the system. The latency for reacting to remote control commands should be as fast as possible (e.g. not more than 1-2 seconds). And there I go, starting to implement the security of my home service HTTP endpoints... configuring the Ruby Sinatra framework to use SSL , to have basic HTTP authentication... setting up port forwarding on the home gateway... That sounds ok, works ok, until thinking about using a "backup network"; what I have always foreseen in my home alarm system, is to use an external WiFi external access-point as fallback when my home gateway network is down; nowadays it is indeed easy and common to use your ISP special WiFi access points, available everywhere in the country. A quick scan around shows already 3 of these access points in the neighbourhood (one of course being linked ...

Time for an upgrade, and an update too...

Image
I have been waiting for a long time to get myself one these Raspberry Pi cameras. From the beginning I wanted to experiment with a camera, movement detection, making some time-lapse videos... Unfortunately when I tried initially with my good old Logitech 4400 webcam, it did not work so well. Something was wrong with the USB driver? Not clear, but at the end I never managed to get it working well. Recently, well a few months ago already, the 2nd big version of the Raspberry Pi got out. The perfect opportunity to get an upgrade for my existing system. The camera is nice: simple setup, works out of the box. The  documentation  is great and better, the default distribution (Raspian) got all these nice shell command lines to control the camera. This opens a bunch of new ideas, things to try out in the future :-) The "old" Raspberry Pi is still running, my home "alarm/surveillance" system (still based on my  Ruby ZWay wrapper library , that I update and improve -...

rzwaveway: controlling a siren & strobe alarm

Finally "back to work" and trying to finalize a first fully working version of my home alarm system... I am now looking at how to use my alarm device, a " FortrezZ strobe and alarm " ZWave device. I added a small extension to the rzwaveway library for that matter. It is a simple interface for controlling the state of the alarm and enabling or disabling the strobe light and siren. zway = RZWaveWay::ZWay.instance zway.setup(hostname) zway.start device = RZWaveWay::Extensions::SSASirenStrobeAlarm.new(device_id) device.enable_strobe sleep 5 device.enable_siren sleep 5 device.disable Unfortunately it seems that the "SetWithDuration" function of the SwitchMultiLevel command class does not work (at least from the Z-Wave Me web UI). I guess it would have helped to implement a "pre-alarm warning" (e.g. some short bips to notify when the alarm is armed). The best solution I could find so far to ...

ZWave: window/door sensors

Image
The first ZWave devices I bought one year ago were window/door sensors. I started with 3x Everspring SM 103 sensors as I got a bulk price for them. Initially everything worked fine, until a few months: One sensor, attached to a window, suddenly stopped communicating with the controller; changed the batteries, re-included into the network, did a reset, but still the same. Even at 30 cm from the controller, sometimes it takes a few seconds (to a minute) to wake up and send an event. Weirdly after it wake up a first time, it seems to work fine for a few... but after some time, it "lags" again. Finally, I replaced it with the "test" spare sensor I had. Second sensor, the door sensor... Ok, that one was badly treated: since the base was too big to be installed next to the door, I installed the base on the door and the magnet on the side. Clearly a bad idea. This probably did not help. Recently this one also started to "miss" wake ups, but worse, it also mi...

rzwaveway: calling ZWave commands

Still working on the Ruby [ dark ] side (although I wish I had more time and motivation to go on with my C++ :-)),... I finally implemented something that makes it possible to "invoke" ZWave command class functions on devices. In Ruby life is easy and this was implemented quite easily: after all, calling a function in ZWay ends up being just a simple HTTP call. In my little rzwaveway  library gem I added the notion of "extensions" ("plug-ins" would have been a good name too) that define a clear API (meaning, not a low-level ZWay function call) for a known ZWave device interface. As a first test, I implemented support for the ZWave siren/strobe alarm device I bought earlier this year. The code for it looks like this: module RZWaveWay module Extensions class SSASirenStrobeAlarm include CommandClasses def initialize(device_id) @device_id = device_id end def disable set_value(0) end def enable ...

4 weeks with Ruby

The past month brought a bunch of changes in my developer carrier. Change of job team, office, city... and technologies. One of these was to start learning a new language for developing software: Ruby! It is quite a change from the programming languages I went through before (in short, Turbo Pascal, C, C++, Assemblers, Java, C#). I was advised a very good Ruby book,  Eloquent Ruby  and some fancy "training exercises", the " Ruby Koans " to start learning about Ruby. After a few days I realized that a better exercise for me would be to re-implement my "home zwave proxy" (developer in C++, using directly the ZWay C library); and well, it was a good idea. After 4 weeks (well, a few hours in the evenings), with some basic knowledge of Ruby, I almost managed to reach the same "level of functionality" as my native C++ application. "Almost", because there is definitively something I miss in this fancy Ruby world: real callbacks on event...

ZWay: new ZWave devices!

Image
Right, it was about time to invest into some new ZWave devices for my home. Christmas being over....... I finally made up my mind and ordered: A smoke sensor: Fibaro FGSS-001. A wireless siren & strobe alarm: FortrezZ SSA1 So far I managed to include the smoke sensor device; the ZWay configuration screen were initially not right and I had to update the ZDDX definitions in order to get it right: it was missing the XML file for this brand new device: " 500-010f-0c00-1000-03-03-34-02-01.xml " (note that there is a nice ZWave device database here ). For that matter, I discovered that there is a script meant for that purpose: "/opt/z-way-server/ZDDX/UpdateXMLs.sh" I did not install yet the alarm device; too risky :-) My C++ Razberry proxy software needs some rework and device abstractions first...

Android: sending notifications

Image
Until now, my "Home server" Google application (running in the cloud :-)) was using basic XMPP for sending sensor notifications to my phone. With that, each time a sensor changed status, a small text message was sent to me, appearing in my Google Talk application, telling me what sensor changed, the time etc. Easy, simple, very basic: a few lines of code, done. Even an event history for free! However this basic solution started to be annoying: No easy way to integrate the notifications with my "Client" Android application. Impossible to use this if the Android Google Talk application got upgraded to "Hangouts": I tried and indeed, I never got a single message when using Hangouts. Apparently, this is a known limitation ? Luckily last month I finally discovered Google Cloud Messaging  and had a bit of time to "practice" during the holidays. In short, it makes it possible to easily received/send messages from/to an Android device; the send...

ZWay: version 1.4.1 changes

It seems that ZWay 1.4.1 got finally released ; well, at first sight it looks to be the same as the previous release candidate ("v1.4.1-rc1"). Therefore it was time to update my raspberry pi with this newer version. Hopefully this should now enable support for the ALARM command class. Nothing got broken in terms of recompiling my existing code. Good - but: It seems necessary to re-include/re-interview the ZWave devices. The data holder model for my binary sensor has changed! Previously, the "level" boolean value for my sensor was obtained using: zway_find_device_instance_cc_data(aZWay, 2, 0, COMMAND_CLASS_SENSOR_BINARY, "level"); Now there is no more data holder under this name. It is: zway_find_device_instance_cc_data(aZWay, 2, 0, COMMAND_CLASS_SENSOR_BINARY, " 1. level"); Not very clear why, but this works as before for me. But the good news is that no...

ZWay: support for the Alarm command class yeah!

According to the ZWay forums , the upcoming version of the ZWay RaZberry software (1.4.1?) will finally support the ZWave Alarm command class. Why is that interesting? Well, if you plan to use your RaZberry for a home security system, this command is kind of important: a ZWave device sensor sends this command when it gets tampered (e.g. when a door sensor gets detached from the door). And so far the Alarm command was not supported :-( As soon as it gets released in a final build, I will try that and give some feedback here!

Android: Give your smartphone a second chance

Looking at the constant evolution of the Android platform and how bad the phone manufacturers are supporting it on their older phone platforms, it is clear that a smartphone is not a "life companion". With about one or two major versions of the Android platform coming out each year, its lifetime is clearly short. At some point: It gets "stuck" in one particular Android platform release. There is no more main storage (flash) space. It is getting slow running some applications. It does not support anymore the newest market applications. It is not as "fancy" as recent phones :-) My old smartphone, an HTC Legend , reached that point; 3 years after I bought it, I am now part of one of the smallest Android platform group according to the  Android "platform version" distribution  : Froyo. My phone lacks storage space every day, each time an application update pops in for instance. It is impossible to update the good old Google Talk application...

Libcurl: perform a REST HTTP PUT

The libcurl library does not provide a clear example on how to issue HTTP PUT operations in a REST context; the examples are mainly about file transfers . For my proxy application this is not really what I need: I want to perform a REST HTTP PUT, keep it simple, meaning without using the "Expect" and "Transfer-Encoding" that libcurl adds by default. After some struggling I discovered that this behavior can be changed by using the following code: CURL * pCurl; struct curl_slist *headers = NULL; headers = curl_slist_append(headers, "Content-Type: application/json "); headers = curl_slist_append(headers, "Content-Length: 12345 "); headers = curl_slist_append(headers, "Expect:"); headers = curl_slist_append(headers, "Transfer-Encoding:"); pCurl = curl_easy_init(); curl_easy_setopt(pCurl, CURLOPT_VERBOSE, 1); curl_easy_setopt(pCurl, CURLOPT_PUT, 1); curl_easy_setopt(pCurl, CURLOPT_URL, " https://your-server.app...

ZWay: most interesting data for a binary sensor

In order to be able to refresh the persisted state of my binary sensors on my little web application, I extended my "Z-Wave proxy" to send some information when it initially starts. It retrieves data from a few "data holders": The current level (if the sensor is triggered or not). The configured wake-up interval. The last sleep time. The last wake-up time. The battery level. The following code can be used to do so. const ZWBYTE COMMAND_CLASS_ALARM = 113; const ZWBYTE COMMAND_CLASS_BATTERY = 128; const ZWBYTE COMMAND_CLASS_SENSOR_BINARY = 48; const ZWBYTE COMMAND_CLASS_WAKE_UP = 132; [...] bool level = findInstanceDataAsBoolean(aZWay, COMMAND_CLASS_SENSOR_BINARY, "level"); int wakeUpInterval = findInstanceDataAsInt(aZWay, COMMAND_CLASS_WAKE_UP, "interval"); int lastSleepTime = findInstanceDataAsInt(aZWay, COMMAND_CLASS_WAKE_UP, "lastSleep"); int lastWakeUpTime = findInstanceDataAsInt(aZWay, COMMAND_CLASS_WAKE_UP,...

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...