Added compare inside with outside sensors; webserver template files
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
config_t cfg;
|
||||
const config_setting_t *pins;
|
||||
const config_setting_t *compareIDs;
|
||||
|
||||
void cfginit(void) {
|
||||
|
||||
@@ -74,3 +75,19 @@ int cfgreadsensornodes(sensornode *nodes, int nodecount) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cfgreadcompareidamount(void) {
|
||||
compareIDs = config_lookup(&cfg, "compare_ids");
|
||||
return config_setting_length(compareIDs);
|
||||
}
|
||||
|
||||
int cfgreadcompareidvalue(int element) {
|
||||
compareIDs = config_lookup(&cfg, "compare_ids");
|
||||
int length = config_setting_length(compareIDs);
|
||||
if (element < length) {
|
||||
return config_setting_get_int_elem(compareIDs, element);
|
||||
} else {
|
||||
printf("No compare configuration item found.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@ void cfgreinit(void);
|
||||
int cfgreadpinnumber(int element);
|
||||
int cfgreadpinamount(void);
|
||||
int cfgreadsensornodes(sensornode *nodes, int nodecount);
|
||||
|
||||
int cfgreadcompareidamount(void); //currently unused but will be necessary if there'll be any node filters
|
||||
int cfgreadcompareidvalue(int element); //same
|
||||
|
||||
#endif
|
||||
|
@@ -7,6 +7,7 @@
|
||||
#include "configreader.h"
|
||||
#include "restcurl.h"
|
||||
#include <string.h>
|
||||
#include "calculate.h" //for comparing the nodes
|
||||
|
||||
//Temporary include
|
||||
#include "calculate.h"
|
||||
@@ -51,26 +52,40 @@ int main(void) {
|
||||
printf("Reading Sensornodes\n");
|
||||
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[nodecount]; //Should be a linked list for further data usage
|
||||
sensornode *currentNode = &nodes;
|
||||
nodedata.pin = 0; //This data isn't relevant for a sensornode
|
||||
//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
|
||||
nodedata[i].pin = 0; //This data isn't relevant for a sensornode
|
||||
strcpy(nodedata[i].ip, currentNode->ip);
|
||||
getRestSensor(&nodedata[i]);
|
||||
nodedata[i].isoutside = currentNode->isoutside; //copy the boolean value
|
||||
printf("Acquiring rest response\n");
|
||||
|
||||
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));
|
||||
printf("Temperature: %f, Humidity: %f, NodeID: %i, Outside: %s, AbsoluteHumidity: %f\n", nodedata[i].temperature, nodedata[i].humidity, nodedata[i].node_id, nodedata[i].isoutside ? "Yes" : "No", absoluteHumidity(&nodedata[i]));
|
||||
|
||||
//Insert data into database
|
||||
printf("Insert data into stats table\n");
|
||||
insertData(&nodedata);
|
||||
insertData(&nodedata[i]);
|
||||
|
||||
currentNode = currentNode->next;
|
||||
}
|
||||
|
||||
//Compare the sensors
|
||||
//int comparecount = cfgreadcompareidamount();
|
||||
int j, k;
|
||||
for (j = 0; j < nodecount; j++) {
|
||||
for (k = 0; k < nodecount; k++) {
|
||||
if (j != k && nodedata[j].isoutside == 0 && nodedata[k].isoutside == 1) { //Compare all inside nodes with all outside nodes
|
||||
printf("Node %i (%s) - Node %i (%s): %s\n", nodedata[j].node_id, nodedata[j].isoutside ? "Inside" : "Outside", \
|
||||
nodedata[k].node_id, nodedata[k].isoutside ? "Inside" : "Outside", \
|
||||
compareSensors(&nodedata[j], &nodedata[k]) ? "Open the window" : "Close the window");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//free
|
||||
//freeNodeLinkedList(nodes.next);
|
||||
|
@@ -4,3 +4,5 @@ pins=[7];
|
||||
sensornodes = ( { ip = "192.168.0.101"; outside = 0;},
|
||||
{ ip = "192.168.0.102"; outside = 1;}
|
||||
);
|
||||
|
||||
#compare_ids = [0, 1]; //Compare 2 sensors
|
||||
|
Reference in New Issue
Block a user