Fixed Segfault #9

This commit is contained in:
2017-08-29 19:10:08 +02:00
parent 6e12923557
commit 93dd54ab6d
2 changed files with 6 additions and 5 deletions

View File

@@ -63,7 +63,7 @@ int main(void) {
nodedata.isoutside = currentNode->isoutside; //copy the boolean value nodedata.isoutside = currentNode->isoutside; //copy the boolean value
printf("Acquiring rest response\n"); 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 //Insert data into database
printf("Insert data into stats table\n"); printf("Insert data into stats table\n");

View File

@@ -82,10 +82,11 @@ int getRestSensor(sensor *sensor) {
//The ID is stored in the JSON root //The ID is stored in the JSON root
cJSON *id = cJSON_GetObjectItemCaseSensitive(jsondata, "id"); cJSON *id = cJSON_GetObjectItemCaseSensitive(jsondata, "id");
sensor->temperature = (float)temperature->valuedouble; if (temperature != NULL && humidity != NULL && id != NULL) {
sensor->humidity = (float)humidity->valuedouble; sensor->temperature = (float)temperature->valuedouble;
sensor->node_id = atoi(id->valuestring); sensor->humidity = (float)humidity->valuedouble;
sensor->node_id = atoi(id->valuestring);
}
//free //free
cJSON_Delete(jsondata); cJSON_Delete(jsondata);
free(data); free(data);