diff --git a/RaspberryPi/configreader.h b/RaspberryPi/configreader.h index 0c59e38..a75b66c 100644 --- a/RaspberryPi/configreader.h +++ b/RaspberryPi/configreader.h @@ -3,7 +3,7 @@ typedef struct sensornode { - char *ip; + char ip[50]; struct sensornode *next; } sensornode; diff --git a/RaspberryPi/main.c b/RaspberryPi/main.c index 9f8eaf4..be5e8f9 100644 --- a/RaspberryPi/main.c +++ b/RaspberryPi/main.c @@ -25,29 +25,35 @@ int main(void) { int i; for (i = 0; i < cfgreadpinamount(); i++) { data.pin = cfgreadpinnumber(i); - getData(&data); - printf("Pin: %i, %.2f, %.2f\n", data.pin, data.temperature, data.humidity); + //getData(&data); + //printf("Pin: %i, %.2f, %.2f\n", data.pin, data.temperature, data.humidity); //insertData(&data); } sensornode nodes; //Settings of ESP8266 sensor nodes int nodecount = 0; + printf("Reading Sensornodes\n"); cfgreadsensornodes(&nodes, nodecount); //read settings + printf("Reading Sensornodes done Nodecount: %i\n", nodecount); sensor nodedata; //Should be a linked list for further data usage sensornode *currentNode = &nodes; + printf("First IP: %s\n", nodes.ip); - for (i = 0; i < nodecount; i++) { + for (i = 0; i <= nodecount; i++) { //start rest requests strcpy(nodedata.ip, currentNode->ip); getRestSensor(&nodedata); + printf("Acquiring rest response\n"); - printf("Temperature: %f, Humidity: %f, NodeID: %i", nodedata.temperature, nodedata.humidity, nodedata.node_id); + printf("Temperature: %f, Humidity: %f, NodeID: %i\n", nodedata.temperature, nodedata.humidity, nodedata.node_id); + + //Insert data into database currentNode = currentNode->next; } - + cfgdestroy(); return 0; } diff --git a/RaspberryPi/makefile b/RaspberryPi/makefile index e9bf5ce..d6b766c 100644 --- a/RaspberryPi/makefile +++ b/RaspberryPi/makefile @@ -3,7 +3,7 @@ VERSION = 1.0 CC = cc -CFLAGS = -Wall -O3 -D_GNU_SOURCE -D_REENTRANT -DVERSION=\"$(VERSION)\" `mysql_config --cflags` +CFLAGS = -Wall -g -D_GNU_SOURCE -D_REENTRANT -DVERSION=\"$(VERSION)\" `mysql_config --cflags` #LDFLAGS = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread LDFLAGS = -lwiringPi -lconfig `mysql_config --libs` -lcurl diff --git a/RaspberryPi/restcurl.c b/RaspberryPi/restcurl.c index c18130a..d60ce1e 100644 --- a/RaspberryPi/restcurl.c +++ b/RaspberryPi/restcurl.c @@ -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);