Fixed segfault in configreader

This commit is contained in:
2017-08-27 18:28:26 +02:00
parent eda866b36d
commit 27ed59b52f
4 changed files with 22 additions and 10 deletions

View File

@@ -73,12 +73,18 @@ int getRestSensor(sensor *sensor) {
char *data = handle_url(url);
if (data) {
cJSON *jsondata = cJSON_Parse(data);
cJSON *temperature = cJSON_GetObjectItemCaseSensitive(jsondata, "temperature");
cJSON *humidity = cJSON_GetObjectItemCaseSensitive(jsondata, "humidity");
cJSON *variables = cJSON_GetObjectItemCaseSensitive(jsondata, "variables");
//These two are in the catergory variables
cJSON *temperature = cJSON_GetObjectItemCaseSensitive(variables, "temperature");
cJSON *humidity = cJSON_GetObjectItemCaseSensitive(variables, "humidity");
//The ID is stored in the JSON root
cJSON *id = cJSON_GetObjectItemCaseSensitive(jsondata, "id");
sensor->temperature = (float)temperature->valuedouble;
sensor->humidity = (float)humidity->valuedouble;
sensor->node_id = id->valueint;
sensor->node_id = atoi(id->valuestring);
//free
cJSON_Delete(jsondata);