2022-01-14 22:51:28 +01:00
|
|
|
#include "Configuration.h"
|
2022-01-15 02:01:22 +01:00
|
|
|
#include "modules/IoTSensorA.h"
|
2022-01-14 20:22:52 +01:00
|
|
|
|
2022-01-15 02:01:22 +01:00
|
|
|
std::vector<IoTSensor*> iotSensors;
|
|
|
|
|
|
|
|
|
|
void configure(String path) {
|
2022-01-14 20:42:11 +01:00
|
|
|
File file = seekFile(path);
|
2022-01-15 02:01:22 +01:00
|
|
|
file.find("[");
|
2022-01-14 20:42:11 +01:00
|
|
|
while (file.available()) {
|
|
|
|
|
String jsonArrayElement = file.readStringUntil('}') + "}";
|
2022-01-15 02:01:22 +01:00
|
|
|
if (jsonArrayElement.startsWith(",")) {
|
|
|
|
|
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
|
|
|
|
|
}
|
2022-01-14 22:51:28 +01:00
|
|
|
String subtype;
|
|
|
|
|
if (jsonRead(jsonArrayElement, F("subtype"), subtype)) {
|
|
|
|
|
if (subtype == F("button-out")) {
|
2022-01-14 20:42:11 +01:00
|
|
|
//=============================
|
2022-01-14 22:51:28 +01:00
|
|
|
} else if (subtype == F("pwm-out")) {
|
2022-01-14 21:48:43 +01:00
|
|
|
//=============================
|
2022-01-14 22:51:28 +01:00
|
|
|
} else if (subtype == F("analog-adc")) {
|
2022-01-15 02:01:22 +01:00
|
|
|
mySensorAnalog = new IoTSensorA(jsonArrayElement);
|
|
|
|
|
iotSensors.push_back(mySensorAnalog);
|
2022-01-14 20:47:24 +01:00
|
|
|
} else {
|
2022-01-15 02:01:22 +01:00
|
|
|
SerialPrint(F("E"), F("Config"), "type not exist " + subtype);
|
2022-01-14 20:42:11 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2022-01-15 02:01:22 +01:00
|
|
|
SerialPrint(F("E"), F("Config"), F("json error"));
|
2022-01-14 20:42:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
file.close();
|
2022-01-14 20:22:52 +01:00
|
|
|
}
|