...
 
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,38 +597,62 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
}
} else if (strcmp(name, "sensorDescriptions") == 0) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
if (ret != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s\n", name);
free(name);
continue;
}
if (dev->mod && dev->mod->type) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
if (ret != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s\n", name);
free(name);
continue;
}
int n, sensorUsage, sensorType;
char sensorName[64];
char sensorIndex[64];
int n, sensorUsage, sensorType;
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)) {
sensorUsage = 2; // Outdoor
} else {
sensorUsage = 1; // Indoor
}
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[] =
{
{ "WindAngle", 19 },
{ "WindStrength", 13 },
{ "GustAngle", 24 },
{ "GustStrength", 23 },
{ 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);
dsvdc_property_t *nProp;
if (dsvdc_property_new(&nProp) != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s/%s\n", name, sensorName);
break;
}
dsvdc_property_add_string(nProp, "name", sensorName);
dsvdc_property_add_uint(nProp, "sensorType", wl[n].typeId);
dsvdc_property_add_uint(nProp, "sensorUsage", sensorUsage);
dsvdc_property_add_double(nProp, "aliveSignInterval", 300);
dsvdc_property_add_property(reply, sensorIndex, &nProp);
vdc_report(LOG_INFO, "sensorDescription: dsuid %s sensor %d: %s type %d usage %d\n", dsuid, n, sensorName,
sensorType, sensorUsage);
}
if (strcmp(dev->mod->type, "NAModule2") == 0) {
struct windTypeList { char* typeName; int typeId; };
struct windTypeList wl[] = {
{ "WindAngle", 19 },
{ "WindStrength", 13 },
{ "GustAngle", 24 },
{ "GustStrength", 23 },
{ NULL, 0 }
};
for (n = 0; wl[n].typeName != NULL; n++) {
} else if (strcmp(dev->mod->type, "NAModule3") == 0) {
n = 0;
snprintf(sensorIndex, 64, "%d", n);
snprintf(sensorName, 64, "%s-%s", dev->mod->name, wl[n].typeName);
snprintf(sensorName, 64, "%s-%s", dev->mod->name, dev->mod->values[n].data_type);
dsvdc_property_t *nProp;
if (dsvdc_property_new(&nProp) != DSVDC_OK) {
......@@ -634,70 +660,51 @@ void vdc_getprop_cb(dsvdc_t *handle, const char *dsuid, dsvdc_property_t *proper
break;
}
dsvdc_property_add_string(nProp, "name", sensorName);
dsvdc_property_add_uint(nProp, "sensorType", wl[n].typeId);
dsvdc_property_add_uint(nProp, "sensorType", 21);
dsvdc_property_add_uint(nProp, "sensorUsage", sensorUsage);
dsvdc_property_add_double(nProp, "aliveSignInterval", 300);
dsvdc_property_add_property(reply, sensorIndex, &nProp);
vdc_report(LOG_INFO, "sensorDescription: dsuid %s sensor %d: %s type %d usage %d\n", dsuid, n, sensorName,
sensorType, sensorUsage);
}
} else if (strcmp(dev->mod->type, "NAModule3") == 0) {
n = 0;
snprintf(sensorIndex, 64, "%d", n);
snprintf(sensorName, 64, "%s-%s", dev->mod->name, dev->mod->values[n].data_type);
dsvdc_property_t *nProp;
if (dsvdc_property_new(&nProp) != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s/%s\n", name, sensorName);
break;
}
dsvdc_property_add_string(nProp, "name", sensorName);
dsvdc_property_add_uint(nProp, "sensorType", 21);
dsvdc_property_add_uint(nProp, "sensorUsage", sensorUsage);
dsvdc_property_add_double(nProp, "aliveSignInterval", 300);
dsvdc_property_add_property(reply, sensorIndex, &nProp);
vdc_report(LOG_INFO, "sensorDescription: dsuid %s sensor %d: %s type %d usage %d\n", dsuid, n, sensorName,
sensorType, sensorUsage);
} else {
for (n = 0; n < dev->mod->values_num; n++) {
if (strcmp(dev->mod->values[n].data_type, "Temperature") == 0) {
sensorType = 1;
} else if (strcmp(dev->mod->values[n].data_type, "Humidity") == 0) {
sensorType = 2;
} else if (strcmp(dev->mod->values[n].data_type, "CO2") == 0) {
sensorType = 22;
} else if (strcmp(dev->mod->values[n].data_type, "Pressure") == 0) {
sensorType = 18;
} else if (strcmp(dev->mod->values[n].data_type, "Noise") == 0) {
sensorType = 20;
} else {
sensorType = 253;
}
snprintf(sensorName, 64, "%s-%s", dev->mod->name, dev->mod->values[n].data_type);
dsvdc_property_t *nProp;
if (dsvdc_property_new(&nProp) != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s/%s\n", name, sensorName);
break;
} else {
for (n = 0; n < dev->mod->values_num; n++) {
if (strcmp(dev->mod->values[n].data_type, "Temperature") == 0) {
sensorType = 1;
} else if (strcmp(dev->mod->values[n].data_type, "Humidity") == 0) {
sensorType = 2;
} else if (strcmp(dev->mod->values[n].data_type, "CO2") == 0) {
sensorType = 22;
} else if (strcmp(dev->mod->values[n].data_type, "Pressure") == 0) {
sensorType = 18;
} else if (strcmp(dev->mod->values[n].data_type, "Noise") == 0) {
sensorType = 20;
} else {
sensorType = 253;
}
snprintf(sensorName, 64, "%s-%s", dev->mod->name, dev->mod->values[n].data_type);
dsvdc_property_t *nProp;
if (dsvdc_property_new(&nProp) != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s/%s\n", name, sensorName);
break;
}
dsvdc_property_add_string(nProp, "name", sensorName);
dsvdc_property_add_uint(nProp, "sensorType", sensorType);
dsvdc_property_add_uint(nProp, "sensorUsage", sensorUsage);
dsvdc_property_add_double(nProp, "aliveSignInterval", 300);
snprintf(sensorIndex, 64, "%d", n);
dsvdc_property_add_property(reply, sensorIndex, &nProp);
vdc_report(LOG_INFO, "sensorDescription: dsuid %s sensor %d: %s type %d usage %d\n", dsuid, n, sensorName,
sensorType, sensorUsage);
}
dsvdc_property_add_string(nProp, "name", sensorName);
dsvdc_property_add_uint(nProp, "sensorType", sensorType);
dsvdc_property_add_uint(nProp, "sensorUsage", sensorUsage);
dsvdc_property_add_double(nProp, "aliveSignInterval", 300);
snprintf(sensorIndex, 64, "%d", n);
dsvdc_property_add_property(reply, sensorIndex, &nProp);
vdc_report(LOG_INFO, "sensorDescription: dsuid %s sensor %d: %s type %d usage %d\n", dsuid, n, sensorName,
sensorType, sensorUsage);
}
}
dsvdc_property_add_property(property, name, &reply);
dsvdc_property_add_property(property, name, &reply);
}
} else if (strcmp(name, "sensorSettings") == 0) {
dsvdc_property_t *reply;
......@@ -773,51 +780,53 @@ 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) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
if (ret != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s\n", name);
free(name);
continue;
}
int idx, n;
char* sensorIndex;
dsvdc_property_t *sensorRequest;
dsvdc_property_get_property_by_index(query, 0, &sensorRequest);
if (dsvdc_property_get_name(sensorRequest, 0, &sensorIndex) != DSVDC_OK) {
vdc_report(LOG_DEBUG, "binaryInputStates: no index in request\n");
idx = -1;
} else {
idx = strtol(sensorIndex, NULL, 10);
}
dsvdc_property_free(sensorRequest);
if (dev->mod && dev->mod->type) {
dsvdc_property_t *reply;
ret = dsvdc_property_new(&reply);
if (ret != DSVDC_OK) {
vdc_report(LOG_ERR, "failed to allocate reply property for %s\n", name);
free(name);
continue;
}
dsvdc_property_t *nProp;
if (((idx < 0) || (idx == 0)) && (dsvdc_property_new(&nProp) == DSVDC_OK)) {
bool val;
if (dev->mod->battery_percent > 0) {
val = dev->mod->battery_percent <= 25;
} else if (strcmp(dev->mod->type, "NAModule1") == 0) {
val = dev->mod->battery_vp <= 4000; // OUTDOOR
} else if (strcmp(dev->mod->type, "NAModule2") == 0) {
val = dev->mod->battery_vp <= 4360; // WIND
} else if (strcmp(dev->mod->type, "NAModule3") == 0) {
val = dev->mod->battery_vp <= 4000; // RAIN
} else if (strcmp(dev->mod->type, "NAModule4") == 0) {
val = dev->mod->battery_vp <= 4560; // INDOOR
int idx, n;
char* sensorIndex;
dsvdc_property_t *sensorRequest;
dsvdc_property_get_property_by_index(query, 0, &sensorRequest);
if (dsvdc_property_get_name(sensorRequest, 0, &sensorIndex) != DSVDC_OK) {
vdc_report(LOG_DEBUG, "binaryInputStates: no index in request\n");
idx = -1;
} else {
val = 0;
idx = strtol(sensorIndex, NULL, 10);
}
dsvdc_property_free(sensorRequest);
dsvdc_property_add_bool(nProp, "value", val);
dsvdc_property_add_int(nProp, "age", 0);
dsvdc_property_add_int(nProp, "error", 0);
dsvdc_property_t *nProp;
if (((idx < 0) || (idx == 0)) && (dsvdc_property_new(&nProp) == DSVDC_OK)) {
bool val;
if (dev->mod->battery_percent > 0) {
val = dev->mod->battery_percent <= 25;
} else if (strcmp(dev->mod->type, "NAModule1") == 0) {
val = dev->mod->battery_vp <= 4000; // OUTDOOR
} else if (strcmp(dev->mod->type, "NAModule2") == 0) {
val = dev->mod->battery_vp <= 4360; // WIND
} else if (strcmp(dev->mod->type, "NAModule3") == 0) {
val = dev->mod->battery_vp <= 4000; // RAIN
} else if (strcmp(dev->mod->type, "NAModule4") == 0) {
val = dev->mod->battery_vp <= 4560; // INDOOR
} else {
val = 0;
}
dsvdc_property_add_property(reply, "0", &nProp);
dsvdc_property_add_bool(nProp, "value", val);
dsvdc_property_add_int(nProp, "age", 0);
dsvdc_property_add_int(nProp, "error", 0);
dsvdc_property_add_property(reply, "0", &nProp);
}
dsvdc_property_add_property(property, name, &reply);
}
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");
......