Fixed segfault in configreader
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
typedef struct sensornode {
|
typedef struct sensornode {
|
||||||
char *ip;
|
char ip[50];
|
||||||
struct sensornode *next;
|
struct sensornode *next;
|
||||||
} sensornode;
|
} sensornode;
|
||||||
|
|
||||||
|
@@ -25,29 +25,35 @@ int main(void) {
|
|||||||
int i;
|
int i;
|
||||||
for (i = 0; i < cfgreadpinamount(); i++) {
|
for (i = 0; i < cfgreadpinamount(); i++) {
|
||||||
data.pin = cfgreadpinnumber(i);
|
data.pin = cfgreadpinnumber(i);
|
||||||
getData(&data);
|
//getData(&data);
|
||||||
printf("Pin: %i, %.2f, %.2f\n", data.pin, data.temperature, data.humidity);
|
//printf("Pin: %i, %.2f, %.2f\n", data.pin, data.temperature, data.humidity);
|
||||||
//insertData(&data);
|
//insertData(&data);
|
||||||
}
|
}
|
||||||
|
|
||||||
sensornode nodes; //Settings of ESP8266 sensor nodes
|
sensornode nodes; //Settings of ESP8266 sensor nodes
|
||||||
int nodecount = 0;
|
int nodecount = 0;
|
||||||
|
printf("Reading Sensornodes\n");
|
||||||
cfgreadsensornodes(&nodes, nodecount); //read settings
|
cfgreadsensornodes(&nodes, nodecount); //read settings
|
||||||
|
printf("Reading Sensornodes done Nodecount: %i\n", nodecount);
|
||||||
sensor nodedata; //Should be a linked list for further data usage
|
sensor nodedata; //Should be a linked list for further data usage
|
||||||
sensornode *currentNode = &nodes;
|
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
|
//start rest requests
|
||||||
strcpy(nodedata.ip, currentNode->ip);
|
strcpy(nodedata.ip, currentNode->ip);
|
||||||
getRestSensor(&nodedata);
|
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;
|
currentNode = currentNode->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
cfgdestroy();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
VERSION = 1.0
|
VERSION = 1.0
|
||||||
CC = cc
|
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 = -lm -lpthread `gtk-config --cflags` `gtk-config --libs` -lgthread
|
||||||
LDFLAGS = -lwiringPi -lconfig `mysql_config --libs` -lcurl
|
LDFLAGS = -lwiringPi -lconfig `mysql_config --libs` -lcurl
|
||||||
|
|
||||||
|
@@ -73,12 +73,18 @@ int getRestSensor(sensor *sensor) {
|
|||||||
char *data = handle_url(url);
|
char *data = handle_url(url);
|
||||||
if (data) {
|
if (data) {
|
||||||
cJSON *jsondata = cJSON_Parse(data);
|
cJSON *jsondata = cJSON_Parse(data);
|
||||||
cJSON *temperature = cJSON_GetObjectItemCaseSensitive(jsondata, "temperature");
|
cJSON *variables = cJSON_GetObjectItemCaseSensitive(jsondata, "variables");
|
||||||
cJSON *humidity = cJSON_GetObjectItemCaseSensitive(jsondata, "humidity");
|
|
||||||
|
//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");
|
cJSON *id = cJSON_GetObjectItemCaseSensitive(jsondata, "id");
|
||||||
|
|
||||||
sensor->temperature = (float)temperature->valuedouble;
|
sensor->temperature = (float)temperature->valuedouble;
|
||||||
sensor->humidity = (float)humidity->valuedouble;
|
sensor->humidity = (float)humidity->valuedouble;
|
||||||
sensor->node_id = id->valueint;
|
sensor->node_id = atoi(id->valuestring);
|
||||||
|
|
||||||
//free
|
//free
|
||||||
cJSON_Delete(jsondata);
|
cJSON_Delete(jsondata);
|
||||||
|
Reference in New Issue
Block a user