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 dataChangeCallback(ZWay aZWay, ZWDataChangeType aType, ZDataHolder aData, void * apArg) {
 bool level;
 ZWBOOL value;
 zway_data_get_boolean(aZWay, aData, &value);
 switch (value) {
 case 0:
  level = false;
  break;
 case 1:
  level = true;
  break;     
 default:
  cerr << "Invalid value for level: " << value << endl;
  return;
 }
[...]

Comments

  1. Hello, I've just compiled the z-way-test sample downloaded from z-wave.me and I'm still facing an issue with dataHolder whixh always return 0. Same with your examples.
    Are you able to share a whole main.c content file in order to give me the opportunity to test a well-running code ?

    Thanks
    Gilles

    ReplyDelete
  2. Hi,
    I will see what I can do... These days when I got time and motivation, I work more on the Ruby side than on the C++ side :-)
    And the C++ code is not in a state I can share, split between my library/application code is still ugly.

    ReplyDelete
  3. Hi,

    thanks for your reply. Eventually, I succeed to move on, thanks to one of your last update, the one explaining that "level" value is now obtained with "1.level".

    Have you got some more detailled documentation regarding the C API from z-wave.me ? ...I'm very frustrating by the lake of comments and Doc.

    My next step is to try moving to C# with mono.

    Good luke with Ruby :-)

    ReplyDelete
  4. The only documentation for the C API I am aware of is the set of header files.
    :-( Not much but well, enough to start with.

    ReplyDelete

Post a Comment

Popular posts from this blog

ZWay: getting the device list.

First steps with the ZWay library

Libcurl: perform a REST HTTP PUT