Check for finite numbers before inserting the data into the database; Link against math library; Updated Readme
This commit is contained in:
41
README.md
41
README.md
@@ -1,7 +1,12 @@
|
|||||||
# dht22 Temperature Stats
|
# dht22 Temperature Stats
|
||||||
|
|
||||||
|
## Raspberry Pi
|
||||||
|
|
||||||
## mySQL
|
### Dependencies
|
||||||
|
|
||||||
|
`apt install mariadb-server mariadb-client libmariadbclient-dev libmariadbclient-dev-compat libconfig-dev wiringpi libcurl4-openssl-dev (-s)`
|
||||||
|
|
||||||
|
### mySQL
|
||||||
|
|
||||||
Login: `mysql --user=root --password=password`
|
Login: `mysql --user=root --password=password`
|
||||||
|
|
||||||
@@ -13,14 +18,40 @@ Create database: `create database dhtstats;`
|
|||||||
|
|
||||||
Use database: `use 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, gm3 float 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) );
|
||||||
|
```
|
||||||
|
and
|
||||||
|
```
|
||||||
|
CREATE TABLE average_stats (id MEDIUMINT NOT NULL AUTO_INCREMENT, humidity FLOAT NOT NULL, temperature FLOAT NOT NULL, gm3 float not null, isoutside int not null, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Show all entries in table: `select * from stats;`
|
Show all entries in table: `select * from stats;`
|
||||||
|
|
||||||
## Dependencies
|
### Compile & Install
|
||||||
|
|
||||||
|
To compile and install humidityPi use this oneliner: `make && make install`
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
#### Settings
|
||||||
|
|
||||||
|
The settings file ist located under `/etc/humiditypi/settings.cfg`
|
||||||
|
|
||||||
|
#### Cronjob
|
||||||
|
|
||||||
|
If you like to run humidityPi in a desired time intervall you can enable a cronjob by entering `crontab -e` and paste the following to the bottom of the text file:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
#Cronjob that will repeat every minute
|
||||||
|
#Pipe the output to /dev/null to suppress mails from cron
|
||||||
|
* * * * * humiditypi > /dev/null
|
||||||
|
```
|
||||||
|
|
||||||
### Raspberry Pi
|
|
||||||
`apt install mariadb-server mariadb-client libmariadbclient-dev libmariadbclient-dev-compat libconfig-dev wiringpi libcurl4-openssl-dev (-s)`
|
|
||||||
|
|
||||||
### ESP-8266
|
### ESP-8266
|
||||||
[aRest](https://github.com/marcoschwartz/aREST)
|
[aRest](https://github.com/marcoschwartz/aREST)
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include "restcurl.h"
|
#include "restcurl.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "calculate.h" //for comparing the nodes
|
#include "calculate.h" //for comparing the nodes
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
//Temporary include
|
//Temporary include
|
||||||
#include "calculate.h"
|
#include "calculate.h"
|
||||||
@@ -115,8 +116,13 @@ int main(void) {
|
|||||||
float avgOutsideHumidity = avhum_in / outCount;
|
float avgOutsideHumidity = avhum_in / outCount;
|
||||||
|
|
||||||
//Insert the results into the database
|
//Insert the results into the database
|
||||||
//insertDataAverages(avgInsideTemperature, avgInsideHumidity, absoluteHumidityFloat(avgInsideTemperature, avgInsideHumidity));
|
if (isfinite(avgInsideHumidity) && isfinite(avgInsideTemperature)) {
|
||||||
//insertDataAverages(avgOutsideTemperature, avgOutsideHumidity, absoluteHumidityFloat(avgOutsideTemperature, avgOutsideHumidity));
|
insertDataAverages(avgInsideTemperature, avgInsideHumidity, absoluteHumidityFloat(avgInsideTemperature, avgInsideHumidity), 0);
|
||||||
|
}
|
||||||
|
if (isfinite(avgOutsideHumidity) && isfinite(avgOutsideTemperature)) {
|
||||||
|
insertDataAverages(avgOutsideTemperature, avgOutsideHumidity, absoluteHumidityFloat(avgOutsideTemperature, avgOutsideHumidity), 1);
|
||||||
|
}
|
||||||
|
|
||||||
printf("Averages:\n| Inside temperature: %f\n| Inside humidity: %f\n| Outside temperature: %f\n| Outside humidity: %f\n", avgInsideTemperature, avgInsideHumidity, avgOutsideTemperature, avgOutsideHumidity);
|
printf("Averages:\n| Inside temperature: %f\n| Inside humidity: %f\n| Outside temperature: %f\n| Outside humidity: %f\n", avgInsideTemperature, avgInsideHumidity, avgOutsideTemperature, avgOutsideHumidity);
|
||||||
|
|
||||||
//free
|
//free
|
||||||
|
@@ -5,7 +5,7 @@ VERSION = 1.0
|
|||||||
CC = cc
|
CC = cc
|
||||||
CFLAGS = -Wall -g -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 -lm
|
||||||
|
|
||||||
OBJ = main.o dht22.o sendmysql.o configreader.o cJSON.o restcurl.o calculate.o
|
OBJ = main.o dht22.o sendmysql.o configreader.o cJSON.o restcurl.o calculate.o
|
||||||
|
|
||||||
@@ -20,6 +20,10 @@ clean:
|
|||||||
rm -r *.o
|
rm -r *.o
|
||||||
|
|
||||||
install:
|
install:
|
||||||
sudo cp humiditypi /usr/local/bin
|
sudo cp humiditypi /usr/bin
|
||||||
if [ ! -d /etc/humiditypi ]; then sudo mkdir /etc/humiditypi; fi
|
if [ ! -d /etc/humiditypi ]; then sudo mkdir /etc/humiditypi; fi
|
||||||
sudo cp settings.cfg /etc/humiditypi
|
sudo cp settings.cfg /etc/humiditypi
|
||||||
|
|
||||||
|
uninstall:
|
||||||
|
sudo rm /usr/bin/humiditypi
|
||||||
|
rm -r /etc/humiditypi
|
||||||
|
@@ -102,7 +102,7 @@ void insertDataAverages(float temperature, float humidity, float gm3, int isouts
|
|||||||
|
|
||||||
char *pquerystring = NULL;
|
char *pquerystring = NULL;
|
||||||
if (-1 == asprintf(&pquerystring,
|
if (-1 == asprintf(&pquerystring,
|
||||||
"INSERT INTO stats (humidity, temperature, gm3, isoutside) VALUES (%f, %f, %f, %i)", humidity, temperature, absoluteHumidityFloat(temperature, humidity), isoutside)) {
|
"INSERT INTO average_stats (humidity, temperature, gm3, isoutside) VALUES (%f, %f, %f, %i)", humidity, temperature, absoluteHumidityFloat(temperature, humidity), isoutside)) {
|
||||||
perror("asprintf() failed");
|
perror("asprintf() failed");
|
||||||
} else {
|
} else {
|
||||||
if (mysql_query(conn, pquerystring)) {
|
if (mysql_query(conn, pquerystring)) {
|
||||||
|
Reference in New Issue
Block a user