2022-01-15 17:41:12 +01:00
|
|
|
|
#include "ESPConfiguration.h"
|
2022-02-14 18:33:52 +03:00
|
|
|
|
#include "classes/IoTGpio.h"
|
|
|
|
|
|
|
|
|
|
|
|
extern IoTGpio IoTgpio;
|
2022-01-15 17:10:14 +01:00
|
|
|
|
|
2022-02-25 14:03:30 +03:00
|
|
|
|
std::list<IoTItem*> IoTItems;
|
2022-01-16 13:31:05 +01:00
|
|
|
|
void* getAPI(String subtype, String params);
|
|
|
|
|
|
|
2022-01-15 02:01:22 +01:00
|
|
|
|
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-02-16 00:53:52 +01:00
|
|
|
|
if (jsonArrayElement == "]}") {
|
|
|
|
|
|
jsonArrayElement = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
if (jsonArrayElement != "") {
|
|
|
|
|
|
String subtype;
|
|
|
|
|
|
if (!jsonRead(jsonArrayElement, F("subtype"), subtype)) { //если нет такого ключа в представленном json или он не валидный
|
|
|
|
|
|
SerialPrint(F("E"), F("Config"), "json error " + subtype);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
} else {
|
2022-08-12 22:13:50 +02:00
|
|
|
|
//(IoTItem*) - getAPI вернула ссылку, что бы ее привести к классу IoTItem используем
|
2022-02-16 00:53:52 +01:00
|
|
|
|
myIoTItem = (IoTItem*)getAPI(subtype, jsonArrayElement);
|
|
|
|
|
|
if (myIoTItem) {
|
2022-04-24 23:32:06 +03:00
|
|
|
|
// пробуем спросить драйвер GPIO
|
2022-08-12 22:13:50 +02:00
|
|
|
|
if (myIoTItem->isGpioDriver()) IoTgpio.regDriver((IoTGpio*)myIoTItem);
|
|
|
|
|
|
|
2022-02-16 00:53:52 +01:00
|
|
|
|
IoTItems.push_back(myIoTItem);
|
|
|
|
|
|
}
|
2022-01-16 12:17:53 +05:00
|
|
|
|
}
|
2022-01-14 20:42:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
file.close();
|
2022-02-16 00:53:52 +01:00
|
|
|
|
SerialPrint("i", "Config", "Configured");
|
2022-02-14 22:20:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void clearConfigure() {
|
|
|
|
|
|
Serial.printf("Start clearing config\n");
|
2022-08-12 22:13:50 +02:00
|
|
|
|
for (std::list<IoTItem*>::iterator it = IoTItems.begin(); it != IoTItems.end(); ++it) {
|
2022-04-28 10:05:28 +03:00
|
|
|
|
Serial.printf("Start delete iotitem %s \n", (*it)->getID().c_str());
|
2022-02-25 14:03:30 +03:00
|
|
|
|
if (*it) delete *it;
|
2022-02-14 22:20:35 +03:00
|
|
|
|
}
|
|
|
|
|
|
IoTItems.clear();
|
2022-01-14 20:22:52 +01:00
|
|
|
|
}
|