запустил первый сенсор в прошивке 4 той версии

This commit is contained in:
Dmitry Borisenko
2022-01-15 02:01:22 +01:00
parent 2f4a280dcf
commit b6c714bec8
8 changed files with 65 additions and 6 deletions

View File

@@ -1,9 +1,16 @@
#include "Configuration.h"
#include "modules/IoTSensorA.h"
void configure(String& path) {
std::vector<IoTSensor*> iotSensors;
void configure(String path) {
File file = seekFile(path);
file.find("[");
while (file.available()) {
String jsonArrayElement = file.readStringUntil('}') + "}";
if (jsonArrayElement.startsWith(",")) {
jsonArrayElement = jsonArrayElement.substring(1, jsonArrayElement.length()); //это нужно оптимизировать в последствии
}
String subtype;
if (jsonRead(jsonArrayElement, F("subtype"), subtype)) {
if (subtype == F("button-out")) {
@@ -11,12 +18,13 @@ void configure(String& path) {
} else if (subtype == F("pwm-out")) {
//=============================
} else if (subtype == F("analog-adc")) {
// iotSensors.push_back(new IoTSensorAnalog(jsonArrayElement));
mySensorAnalog = new IoTSensorA(jsonArrayElement);
iotSensors.push_back(mySensorAnalog);
} else {
SerialPrint(F("E"), F("Config"), F("config.json error, type not exist"));
SerialPrint(F("E"), F("Config"), "type not exist " + subtype);
}
} else {
SerialPrint(F("E"), F("Config"), F("config.json error, type wrong or missing"));
SerialPrint(F("E"), F("Config"), F("json error"));
}
}
file.close();

View File

@@ -37,6 +37,8 @@ void setup() {
//создаем объект класса выгружающего json массив из файла
mySendJson = new SendJson;
configure("/config.json");
//выводим остаток оперативной памяти после старта
// 22.12.21 пустой код без wifi остаток = 50.28 kB
// 22.12.21 запустил wifi остаток = 48.59 kB
@@ -67,4 +69,8 @@ void loop() {
//обработка web сокетов
standWebSocket.loop();
#endif
for (unsigned int i = 0; i < iotSensors.size(); i++) {
iotSensors[i]->loop();
}
}

View File

@@ -0,0 +1,17 @@
#include "modules/IoTSensorA.h"
IoTSensorA::IoTSensorA(String parameters) {
init(jsonReadStr(parameters, "key"), jsonReadStr(parameters, "id"), jsonReadInt(parameters, "int"));
_pin = jsonReadInt(parameters, "pin");
}
IoTSensorA::~IoTSensorA() {}
void IoTSensorA::doByInterval() {
float value = analogRead(_pin);
regEvent((String)value, "analog"); //обязательный вызов для отправки результата работы
}
IoTSensorA* mySensorAnalog;

View File

@@ -2,7 +2,7 @@
#include "Utils/SerialPrint.h"
#include "Utils/StringUtils.h"
#include "Classes/IoTSensor.h"
#include <map>
class IoTSensorAnalog : public IoTSensor {
private:
//описание переменных экземпляра датчика - аналог глобальных переменных