...
 
Commits (2)
......@@ -325,23 +325,21 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
}
}
// Test first element if there are new values
if (dev->announced && (dev->mod->values[0].last_reported >= dev->mod->values[0].last_query)) {
continue;
}
vdc_report(LOG_INFO, "Reporting new values from device %p: %s...\n", dev, dev->dsuidstring);
dsvdc_property_t* pushEnvelope;
dsvdc_property_t* propState;
dsvdc_property_t* prop;
time_t now = time (NULL);
dsvdc_property_new (&pushEnvelope);
dsvdc_property_new (&propState);
for (v = 0; v < dev->mod->values_num; v++) {
double val = dev->mod->values[v].value;
time_t now = time (NULL);
// Test each element if there are new values
if (dev->announced && (dev->mod->values[v].last_reported >= dev->mod->values[v].last_query)) {
continue;
}
if (dsvdc_property_new (&prop) != DSVDC_OK) {
continue;
......@@ -354,6 +352,12 @@ int main(int argc __attribute__((unused)), char **argv __attribute__((unused)))
snprintf (sensorIndex, 64, "%d", v);
dsvdc_property_add_property (propState, sensorIndex, &prop);
vdc_report(LOG_INFO, "Reporting value: device %s, index %d, type %s, value %.3f, age %d\n",
dev->dsuidstring, sensorIndex,
dev->mod->values[v].data_type,
dev->mod->values[v].value,
now - dev->mod->values[v].last_query);
dev->mod->values[v].last_reported = now;
}
......
......@@ -516,11 +516,14 @@ int netatmo_get_devices()
if (!strcmp(key, "devices")) {
if (type == json_type_array) {
//array_list* dev = json_object_get_array(val);
array_list* dev = json_object_get_array(val);
netatmo_module_t* nmodule = &netatmo.base.modules[0];
for (n = 0; n < 1 /*dev->length*/; n++) {
for (n = 0; n < dev->length; n++) {
json_object* jobj3 = json_object_array_get_idx(val, n);
if (jobj3 == NULL) {
break;
}
json_object_object_foreach(jobj3, key, val)
{
enum json_type type = val ? json_object_get_type(val) : -1;
......@@ -709,6 +712,9 @@ netatmo_get_values(netatmo_module_t* mod)
if (mod && mod != m) {
continue;
}
if (NULL == m->id) {
continue;
}
vdc_report(LOG_INFO, "network: getmeasure request for id %s/%s - last query %d \n",
m->id, m->name, m->values[0].last_query);
......
......@@ -500,7 +500,7 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
}
pthread_mutex_unlock(&g_network_mutex);
if (dev == NULL) {
if (dev == NULL || dev->mod == NULL) {
vdc_report(LOG_WARNING, "get property: unhandled dsuid %s\n", dsuid);
dsvdc_property_free(property);
return;
......@@ -544,6 +544,7 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
} else if (strcmp(name, "customActions") == 0) {
} else if (strcmp(name, "binaryInputDescriptions") == 0) {
if (NULL == dev->mod)
if ((strcmp(dev->mod->type, "NAModule1") == 0) ||
(strcmp(dev->mod->type, "NAModule2") == 0) ||
(strcmp(dev->mod->type, "NAModule3") == 0) ||
......@@ -570,10 +571,11 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
}
} else if (strcmp(name, "binaryInputSettings") == 0) {
if ((strcmp(dev->mod->type, "NAModule1") == 0) ||
if (dev->mod && dev->mod->type &&
((strcmp(dev->mod->type, "NAModule1") == 0) ||
(strcmp(dev->mod->type, "NAModule2") == 0) ||
(strcmp(dev->mod->type, "NAModule3") == 0) ||
(strcmp(dev->mod->type, "NAModule4") == 0)) {
(strcmp(dev->mod->type, "NAModule4") == 0))) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
......@@ -595,6 +597,7 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
}
} else if (strcmp(name, "sensorDescriptions") == 0) {
if (dev->mod && dev->mod->type) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
if (ret != DSVDC_OK) {
......@@ -607,23 +610,26 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
char sensorName[64];
char sensorIndex[64];
if ((strcmp(dev->mod->type, "NAModule1") == 0) ||
(strcmp(dev->mod->type, "NAModule2") == 0) ||
(strcmp(dev->mod->type, "NAModule3") == 0)) {
if ((strcmp(dev->mod->type, "NAModule1") == 0) || (strcmp(dev->mod->type, "NAModule2") == 0)
|| (strcmp(dev->mod->type, "NAModule3") == 0)) {
sensorUsage = 2; // Outdoor
} else {
sensorUsage = 1; // Indoor
}
if (strcmp(dev->mod->type, "NAModule2") == 0) {
struct windTypeList { char* typeName; int typeId; };
struct windTypeList wl[] = {
struct windTypeList
{
char* typeName;
int typeId;
};
struct windTypeList wl[] =
{
{ "WindAngle", 19 },
{ "WindStrength", 13 },
{ "GustAngle", 24 },
{ "GustStrength", 23 },
{ NULL, 0 }
};
{ NULL, 0 } };
for (n = 0; wl[n].typeName != NULL; n++) {
snprintf(sensorIndex, 64, "%d", n);
snprintf(sensorName, 64, "%s-%s", dev->mod->name, wl[n].typeName);
......@@ -698,6 +704,7 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
}
dsvdc_property_add_property(property, name, &reply);
}
} else if (strcmp(name, "sensorSettings") == 0) {
dsvdc_property_t *reply;
......@@ -773,6 +780,7 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
dsvdc_property_add_property(property, name, &reply);
} else if (strcmp(name, "binaryInputStates") == 0) {
if (dev->mod && dev->mod->type) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
if (ret != DSVDC_OK) {
......@@ -818,6 +826,7 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
dsvdc_property_add_property(reply, "0", &nProp);
}
dsvdc_property_add_property(property, name, &reply);
}
} else if (strcmp(name, "name") == 0) {
dsvdc_property_add_string(property, name, dev->mod->name);
......@@ -827,7 +836,9 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
} else if (strcmp(name, "model") == 0) {
char info[256];
if (strcmp(dev->mod->type, "NAModule1") == 0) {
if (NULL == dev->mod || NULL == dev->mod->type) {
strcpy(info, "Invalid");
} else if (strcmp(dev->mod->type, "NAModule1") == 0) {
strcpy(info, "Outdoor"); // raingauge and outdoor module
} else if (strcmp(dev->mod->type, "NAModule2") == 0) {
strcpy(info, "Wind Gauge"); // wind modules
......@@ -898,7 +909,9 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
dsvdc_property_add_string(property, name, info);
} else if (strcmp(name, "deviceIcon16") == 0) {
if (strcmp(dev->mod->type, "NAModule1") == 0) {
if (NULL == dev->mod || NULL == dev->mod->type) {
dsvdc_property_add_bytes(property, name, gIconStation16Data, gIconStation16Size);
} else if (strcmp(dev->mod->type, "NAModule1") == 0) {
dsvdc_property_add_bytes(property, name, gIconIndoor16Data, gIconIndoor16Size);
} else if (strcmp(dev->mod->type, "NAModule2") == 0) {
dsvdc_property_add_bytes(property, name, gIconWind16Data, gIconWind16Size);
......@@ -911,7 +924,9 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
}
} else if (strcmp(name, "deviceIcon48") == 0) {
if (strcmp(dev->mod->type, "NAModule1") == 0) {
if (NULL == dev->mod || NULL == dev->mod->type) {
dsvdc_property_add_bytes(property, name, gIconStation48Data, gIconStation48Size);
} else if (strcmp(dev->mod->type, "NAModule1") == 0) {
dsvdc_property_add_bytes(property, name, gIconIndoor48Data, gIconIndoor48Size);
} else if (strcmp(dev->mod->type, "NAModule2") == 0) {
dsvdc_property_add_bytes(property, name, gIconWind48Data, gIconWind48Size);
......@@ -925,7 +940,9 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
} else if (strcmp(name, "deviceIconName") == 0) {
char info[256];
if (strcmp(dev->mod->type, "NAModule1") == 0) {
if (NULL == dev->mod || NULL == dev->mod->type) {
strcpy(info, "netatmo-unknown.png");
} else if (strcmp(dev->mod->type, "NAModule1") == 0) {
strcpy(info, "netatmo-outdoor-16.png");
} else if (strcmp(dev->mod->type, "NAModule2") == 0) {
strcpy(info, "netatmo-wind-16.png");
......