From 93dd54ab6df7c267142729716b84d33952e5d7fb Mon Sep 17 00:00:00 2001 From: structix Date: Tue, 29 Aug 2017 19:10:08 +0200 Subject: [PATCH] Fixed Segfault #9 --- RaspberryPi/main.c | 2 +- RaspberryPi/restcurl.c | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/RaspberryPi/main.c b/RaspberryPi/main.c index da9acd2..e0a2eb3 100644 --- a/RaspberryPi/main.c +++ b/RaspberryPi/main.c @@ -63,7 +63,7 @@ int main(void) { nodedata.isoutside = currentNode->isoutside; //copy the boolean value printf("Acquiring rest response\n"); - printf("Temperature: %f, Humidity: %f, NodeID: %i, Outside: %s, AbsoluteHumidity: %f\n", nodedata.temperature, nodedata.humidity, nodedata.node_id, nodedata.isoutside ? "Yes" : "No", absoluteHumidity(nodedata)); + printf("Temperature: %f, Humidity: %f, NodeID: %i, Outside: %s, AbsoluteHumidity: %f\n", nodedata.temperature, nodedata.humidity, nodedata.node_id, nodedata.isoutside ? "Yes" : "No", absoluteHumidity(&nodedata)); //Insert data into database printf("Insert data into stats table\n"); diff --git a/RaspberryPi/restcurl.c b/RaspberryPi/restcurl.c index 60d8452..2149c5a 100644 --- a/RaspberryPi/restcurl.c +++ b/RaspberryPi/restcurl.c @@ -82,10 +82,11 @@ int getRestSensor(sensor *sensor) { //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 = atoi(id->valuestring); - + if (temperature != NULL && humidity != NULL && id != NULL) { + sensor->temperature = (float)temperature->valuedouble; + sensor->humidity = (float)humidity->valuedouble; + sensor->node_id = atoi(id->valuestring); + } //free cJSON_Delete(jsondata); free(data);