Bringinh all the pieces together. #2 #7

This commit is contained in:
2017-08-27 16:31:46 +02:00
parent 98a0e3ff5f
commit eca544a421
6 changed files with 72 additions and 6 deletions

View File

@@ -42,3 +42,33 @@ int cfgreadpinamount(void) {
pins = config_lookup(&cfg, "pins");
return config_setting_length(pins);
}
int cfgreadsensornodes(sensornode *nodes, int nodecount) {
sensornode *currentNode = nodes;
config_setting_t *sensornodes = config_lookup(&cfg, "sensornodes");
if (sensornodes != NULL) {
int count = nodecount = config_setting_length(sensornodes); //Read amount of sensornodes and save it in nodecount
int i;
for(i = 0; i < count; ++i) {
config_setting_t *sensornodesetting = config_setting_get_elem(sensornodes, i);
/* Only output the record if all of the expected fields are present. */
const char *ip;
if (!config_setting_lookup_string(sensornodesetting, "ip", &ip))
continue;
currentNode->ip = ip;
//if (i < count - 1) { //stop at last item
currentNode->next = malloc(sizeof(sensornode));
currentNode = currentNode->next;
//}
}
return 1;
}
}