@@ -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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user