I have only three devices that has ZWave chips: RaZberry, Door/Window sensor and Power switch. I intended to turn on something with the power switch when somebody open the door. In my setting, device ID is as following:
- RaZberry got id 1
- Door/Window sensor got id 2
- Power switch got id 3
- Signal extender got id 4
The intention of the program above is to print out the device description that is stored on each device. Also it checks if the power switch status is currently "on" or "off". This checking may not work for now if there is a big network delay or something. As I mentioned earlier, there are two types of ZWave devices. One is devices that are turned on all the time and another is devices that are in sleep mode most of time but wake up occasionally or by some events. Power switch I have is the first type, which means it is turned on all the time. If I try to get the device status from Door/Window sensor, ZWay will give me whatever it stores currently but the value is probably updated last time the device woke up. It may be still fine to use it but if ZWay was not running when the device woke up last time, ZWay might miss the value and it goes out of sync. A proper way to get the device status is to follow steps:
- Send value update request to ZWay server.
- Wait for ZWay server to process the communiation because there might be other things ZWay may be doing at the moment.
- Wait for the device to wake up, which is set to 5minute in my case.
- Wait for ZWay to execute a call back function that I gave.
This characteristics of sleeping devices is very important to understand. Otherwise you may make mistake on your program due to the nature of asynchronous communication.
*PS: stdafx.h, Makefile and config.hpp remain same as the previous post.
The main role of the class, MyZWayData, is to make sure the lock is acquired before ZDataHolder object is accessed and to make sure that the lock is release once it is done. This is implemented in the constructor and destructor.
The function "Get" takes "Overload < type >" as the first argument. It is because C++ doesn't allow full explicit specialization inside of class. In other words, I wanted to have method like "template< ReturnType > ReturnType Get( ZDataHolder d );" and specialize for each return type but I couldn't do it. Instead, with "Overload" trick, I can implement different methods for different return types.
I have refactored this class more than ten times already so there are so many different versions of the class remaining in my head still. lol. It is one of the source of my headache when I think about this class.