I'm currently experimenting with the z-way C-API and somehow cannot manage to get any meaningful events. Since I'm a C-novice a little push into the right direction is very much appreciated Basically I'm trying to get callbacks for key-push events from my z-wave.me FOB (deviceID=3,instance=0). I picked command class 45 (SceneController) and configured all group actions on the FOB to "send scenes".
Code: Select all
#include <stdio.h>
#include <ZWayLib.h>
#include <errno.h>
#include <signal.h>
typedef int bool;
enum { false, true };
volatile sig_atomic_t stop;
void dataChangeCallback(ZWay aZWay, ZWDataChangeType aType, ZDataHolder aData, void * apArg) {
printf("Got callback\n");
}
void inthand(int signum) {
stop = 1;
}
int main(int argc, char ** argv) {
ZWay aZWay;
ZWError result;
int mDeviceId;
memset(&aZWay, 0, sizeof(aZWay));
result = zway_init(&aZWay, "/dev/ttyAMA0",
"/opt/z-way-server/config",
"/opt/z-way-server/translations",
"/opt/z-way-server/ZDDX", stdout, Warning);
if (result == NoError) {
result = zway_start(aZWay,NULL);
if (result == NoError) {
printf("Discovering...\n");
zway_data_acquire_lock(aZWay);
for (mDeviceId = 0; mDeviceId <= 4; mDeviceId++) {
printf("Trying device %i",mDeviceId);
ZDataHolder dataHolder = zway_find_device_instance_cc_data(aZWay, mDeviceId, 0, 45, "");
if (dataHolder != NULL) {
zway_data_add_callback_ex(aZWay, dataHolder, &dataChangeCallback, TRUE, "");
} else {
printf("No data holder for deviceId=%i\n",mDeviceId);
}
}
zway_data_release_lock(aZWay);
signal(SIGINT, inthand);
while (!stop) pause();
printf("Stopping ZWay...\n");
result = zway_stop(aZWay);
}
}
if (result != NoError) {
printf("Error: %d\n", result);
}
zway_terminate(&aZWay);
return 0;
}
Code: Select all
Discovering...
Trying device 0No data holder for deviceId=0
Trying device 1No data holder for deviceId=1
Trying device 2No data holder for deviceId=2
Trying device 3No data holder for deviceId=3
Trying device 4No data holder for deviceId=4
[2014-04-05 10:41:38.177] RECEIVED UNKNOWN PACKET TYPE: 0x00
[2014-04-05 10:41:38.188] RECEIVED UNKNOWN PACKET TYPE: 0x07
^CStopping ZWay...
[2014-04-05 10:41:42.908] SaveData will not save data since it wasn't loaded. This is to prevent data loss.
make: *** [run] Interrupt
Maroš