diff --git a/README.md b/README.md index c74452c..fdecacc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Create database: `create database dhtstats;` Use database: `use dhtstats` -Create new table: `CREATE TABLE stats (id MEDIUMINT NOT NULL AUTO_INCREMENT, node_id int not null, pin int not null, humidity FLOAT NOT NULL, temperature FLOAT NOT NULL, isoutside int not null, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );` +Create new table: `CREATE TABLE stats (id MEDIUMINT NOT NULL AUTO_INCREMENT, node_id int not null, pin int not null, humidity FLOAT NOT NULL, temperature FLOAT NOT NULL, isoutside int not null, gm3 float not null, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );` Show all entries in table: `select * from stats;` diff --git a/RaspberryPi/calculate.c b/RaspberryPi/calculate.c index 7c11f51..caec724 100644 --- a/RaspberryPi/calculate.c +++ b/RaspberryPi/calculate.c @@ -78,6 +78,7 @@ float absoluteHumidity(sensor *sensor) { } int compareSensors(sensor *inside, sensor *outside) { + //returns 1 if window should be opened if (absoluteHumidity(inside) <= absoluteHumidity(outside)) return 1; return 0; } diff --git a/RaspberryPi/main.c b/RaspberryPi/main.c index 7b295ad..da9acd2 100644 --- a/RaspberryPi/main.c +++ b/RaspberryPi/main.c @@ -8,6 +8,8 @@ #include "restcurl.h" #include +//Temporary include +#include "calculate.h" void freeNodeLinkedList(sensornode *node) { void *victim; @@ -61,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\n", nodedata.temperature, nodedata.humidity, nodedata.node_id, nodedata.isoutside ? "Yes" : "No"); + 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/sendmysql.c b/RaspberryPi/sendmysql.c index 900310d..f979d78 100644 --- a/RaspberryPi/sendmysql.c +++ b/RaspberryPi/sendmysql.c @@ -3,6 +3,7 @@ //#define _GNU_SOURCE #include #include +#include "calculate.h" #include "sendmysql.h" void insertData(sensor *s) { @@ -42,7 +43,7 @@ void insertData(sensor *s) { char *pquerystring = NULL; if (-1 == asprintf(&pquerystring, - "INSERT INTO stats (node_id, pin, humidity, temperature, isoutside) VALUES (%i, %i, %f, %f, %i)", s->node_id, s->pin, s->humidity, s->temperature, s->isoutside)) { + "INSERT INTO stats (node_id, pin, humidity, temperature, isoutside, gm3) VALUES (%i, %i, %f, %f, %i, %f)", s->node_id, s->pin, s->humidity, s->temperature, s->isoutside, absoluteHumidity(s))) { perror("asprintf() failed"); } else { if (mysql_query(conn, pquerystring)) {