IsOutside boolean added to config and insertData. Readme updated
This commit is contained in:
@@ -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, 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, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id) );`
|
||||
|
||||
Show all entries in table: `select * from stats;`
|
||||
|
||||
|
@@ -57,11 +57,12 @@ int cfgreadsensornodes(sensornode *nodes, int nodecount) {
|
||||
|
||||
/* Only output the record if all of the expected fields are present. */
|
||||
const char *ip;
|
||||
|
||||
if (!config_setting_lookup_string(sensornodesetting, "ip", &ip))
|
||||
int outside;
|
||||
if (!(config_setting_lookup_string(sensornodesetting, "ip", &ip) && config_setting_lookup_int(sensornodesetting, "outside", &outside)))
|
||||
continue;
|
||||
|
||||
strcpy(currentNode->ip, ip);
|
||||
currentNode->isoutside = outside;
|
||||
//if (i < count - 1) { //stop at last item
|
||||
currentNode->next = malloc(sizeof(sensornode));
|
||||
currentNode = currentNode->next;
|
||||
|
@@ -4,6 +4,7 @@
|
||||
|
||||
typedef struct sensornode {
|
||||
char ip[50];
|
||||
int isoutside; //Inside = 0; outside = 1
|
||||
struct sensornode *next;
|
||||
} sensornode;
|
||||
|
||||
|
@@ -10,7 +10,8 @@ extern "C" {
|
||||
typedef struct {
|
||||
int pin;
|
||||
int node_id;
|
||||
char ip[16]; //15 digits + '\0'
|
||||
char ip[50]; //IP or name can be used
|
||||
int isoutside;
|
||||
float humidity;
|
||||
float temperature;
|
||||
} sensor;
|
||||
|
@@ -8,6 +8,20 @@
|
||||
#include "restcurl.h"
|
||||
#include <string.h>
|
||||
|
||||
|
||||
void freeNodeLinkedList(sensornode *node) {
|
||||
void *victim;
|
||||
if (node != NULL) {
|
||||
while (node) {
|
||||
victim = node;
|
||||
node = node->next;
|
||||
free(victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(void) {
|
||||
if (wiringPiSetup () == -1)
|
||||
exit(EXIT_FAILURE) ;
|
||||
@@ -37,23 +51,27 @@ int main(void) {
|
||||
printf("Reading Sensornodes done Nodecount: %i\n", nodecount);
|
||||
sensor nodedata; //Should be a linked list for further data usage
|
||||
sensornode *currentNode = &nodes;
|
||||
|
||||
nodedata.pin = 0; //This data isn't relevant for a sensornode
|
||||
printf("First IP: %s\n", nodes.ip);
|
||||
|
||||
for (i = 0; i <= nodecount; i++) {
|
||||
//start rest requests
|
||||
strcpy(nodedata.ip, currentNode->ip);
|
||||
getRestSensor(&nodedata);
|
||||
nodedata.isoutside = currentNode->isoutside; //copy the boolean value
|
||||
printf("Acquiring rest response\n");
|
||||
|
||||
printf("Temperature: %f, Humidity: %f, NodeID: %i\n", nodedata.temperature, nodedata.humidity, nodedata.node_id);
|
||||
printf("Temperature: %f, Humidity: %f, NodeID: %i, Outside: %s\n", nodedata.temperature, nodedata.humidity, nodedata.node_id, nodedata.isoutside ? "Yes" : "No");
|
||||
|
||||
//Insert data into database
|
||||
|
||||
printf("Insert data into stats table\n");
|
||||
insertData(&nodedata);
|
||||
currentNode = currentNode->next;
|
||||
}
|
||||
|
||||
|
||||
//free
|
||||
//freeNodeLinkedList(nodes.next);
|
||||
cfgdestroy();
|
||||
return 0;
|
||||
}
|
||||
|
@@ -88,6 +88,7 @@ int getRestSensor(sensor *sensor) {
|
||||
|
||||
//free
|
||||
cJSON_Delete(jsondata);
|
||||
free(data);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@@ -42,7 +42,7 @@ void insertData(sensor *s) {
|
||||
char *pquerystring = NULL;
|
||||
|
||||
if (-1 == asprintf(&pquerystring,
|
||||
"INSERT INTO stats (node_id, pin, humidity, temperature) VALUES (%i, %i, %f, %f)", s->node_id, s->pin, s->humidity, s->temperature)) {
|
||||
"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)) {
|
||||
perror("asprintf() failed");
|
||||
} else {
|
||||
if (mysql_query(conn, pquerystring)) {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
pins=[7];
|
||||
|
||||
|
||||
sensornodes = ( { ip = "192.168.0.101";},
|
||||
{ ip = "192.168.0.102";}
|
||||
sensornodes = ( { ip = "192.168.0.101"; outside = 0;},
|
||||
{ ip = "192.168.0.102"; outside = 1;}
|
||||
);
|
||||
|
Reference in New Issue
Block a user