diff --git a/README.md b/README.md index a3c84ec..4adfdbe 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Show all entries in table: `select * from stats;` ## Dependencies ### Raspberry Pi -`apt install mariadb-server mariadb-client libmariadbclient-dev libmariadbclient-dev-compat libconfig-dev wiringpi (-s)` +`apt install mariadb-server mariadb-client libmariadbclient-dev libmariadbclient-dev-compat libconfig-dev wiringpi libcurl4-openssl-dev (-s)` ### ESP-8266 [aRest](https://github.com/marcoschwartz/aREST) diff --git a/RaspberryPi/calculate.c b/RaspberryPi/calculate.c index 75ad7c3..7c11f51 100644 --- a/RaspberryPi/calculate.c +++ b/RaspberryPi/calculate.c @@ -47,8 +47,10 @@ static float dd(float relativeHumidity, float temperature) { return relativeHumidity / 100 * sdd(temperature); } +/* CURRENTLY UNUSED + static float r(float temperature, float dewTemperature) { - /* This is optional. Necessary with dew point measurements. */ + // This is optional. Necessary with dew point measurements. return 100 * sdd(dewTemperature) / sdd(temperature); } @@ -65,7 +67,7 @@ static float td(float relativeHumidity, float temperature) { } return b * v(relativeHumidity, temperature) / (a - v(relativeHumidity, temperature)); } - +*/ static float af(float relativeHumidity, float temperature) { float tk = temperature + 273.15; return pow(10, 5) * mw/R * dd(relativeHumidity, temperature) / tk; diff --git a/RaspberryPi/configreader.c b/RaspberryPi/configreader.c index 7266925..365d60a 100644 --- a/RaspberryPi/configreader.c +++ b/RaspberryPi/configreader.c @@ -3,6 +3,7 @@ #include #include #include + config_t cfg; const config_setting_t *pins; @@ -60,7 +61,7 @@ int cfgreadsensornodes(sensornode *nodes, int nodecount) { if (!config_setting_lookup_string(sensornodesetting, "ip", &ip)) continue; - currentNode->ip = ip; + strcpy(currentNode->ip, ip); //if (i < count - 1) { //stop at last item currentNode->next = malloc(sizeof(sensornode)); currentNode = currentNode->next; @@ -70,5 +71,5 @@ int cfgreadsensornodes(sensornode *nodes, int nodecount) { return 1; } - + return 0; } diff --git a/RaspberryPi/configreader.h b/RaspberryPi/configreader.h index 9360ce3..0c59e38 100644 --- a/RaspberryPi/configreader.h +++ b/RaspberryPi/configreader.h @@ -1,10 +1,20 @@ +#ifndef cfgreader_H +#define cfgreader_H + + +typedef struct sensornode { + char *ip; + struct sensornode *next; +} sensornode; + + + void cfginit(void); void cfgdestroy(void); void cfgreinit(void); int cfgreadpinnumber(int element); int cfgreadpinamount(void); +int cfgreadsensornodes(sensornode *nodes, int nodecount); -typedef struct sensornode { - char *ip; - struct sensornode *next; -} + +#endif diff --git a/RaspberryPi/main.c b/RaspberryPi/main.c index 0afaeca..9f8eaf4 100644 --- a/RaspberryPi/main.c +++ b/RaspberryPi/main.c @@ -6,6 +6,7 @@ #include "sendmysql.h" #include "configreader.h" #include "restcurl.h" +#include int main(void) { if (wiringPiSetup () == -1) @@ -26,20 +27,20 @@ int main(void) { data.pin = cfgreadpinnumber(i); getData(&data); printf("Pin: %i, %.2f, %.2f\n", data.pin, data.temperature, data.humidity); - insertData(&data); + //insertData(&data); } sensornode nodes; //Settings of ESP8266 sensor nodes - int nodecount; + int nodecount = 0; cfgreadsensornodes(&nodes, nodecount); //read settings sensor nodedata; //Should be a linked list for further data usage - sensornode *currentNode = nodes; + sensornode *currentNode = &nodes; for (i = 0; i < nodecount; i++) { //start rest requests - nodedata.ip = currentNode->ip; - getRestSensor(&nodedate); + strcpy(nodedata.ip, currentNode->ip); + getRestSensor(&nodedata); printf("Temperature: %f, Humidity: %f, NodeID: %i", nodedata.temperature, nodedata.humidity, nodedata.node_id); diff --git a/RaspberryPi/restcurl.c b/RaspberryPi/restcurl.c index 42c5e03..c18130a 100644 --- a/RaspberryPi/restcurl.c +++ b/RaspberryPi/restcurl.c @@ -1,8 +1,10 @@ #include "restcurl.h" #include #include +#include +#include "cJSON.h" -static struct url_data { +struct url_data { size_t size; char* data; }; @@ -66,7 +68,7 @@ static char *handle_url(char *url) { int getRestSensor(sensor *sensor) { char url[25]; - url = "http://"; + strcpy(url, "http://"); strcat(url, sensor->ip); char *data = handle_url(url); if (data) {