Fixed segfault in configreader
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user