4.0.1 ядро для 8266

This commit is contained in:
Dmitry Borisenko
2022-09-14 18:53:02 +02:00
parent 49dde6031a
commit 8ce79687bc
11 changed files with 208 additions and 204 deletions

View File

@@ -29,7 +29,7 @@ class Bme280t : public IoTItem {
SerialPrint("E", "Sensor Bme280t", "Error");
}
~Bme280t() {};
~Bme280t(){};
};
class Bme280h : public IoTItem {
@@ -49,7 +49,7 @@ class Bme280h : public IoTItem {
SerialPrint("E", "Sensor Bme280h", "Error");
}
~Bme280h() {};
~Bme280h(){};
};
class Bme280p : public IoTItem {
@@ -70,28 +70,27 @@ class Bme280p : public IoTItem {
SerialPrint("E", "Sensor Bme280p", "Error");
}
~Bme280p() {};
~Bme280p(){};
};
void* getAPI_Bme280(String subtype, String param) {
if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) {
String addr;
jsonRead(param, "addr", addr);
if (bmes.find(addr) == bmes.end()) {
bmes[addr] = new Adafruit_BME280();
bmes[addr]->begin(hexStringToUint8(addr));
}
if (subtype == F("Bme280t")) {
return new Bme280t(bmes[addr], param);
} else if (subtype == F("Bme280h")) {
return new Bme280h(bmes[addr], param);
} else if (subtype == F("Bme280p")) {
return new Bme280p(bmes[addr], param);
}
} else {
return nullptr;
}
void* getAPI_Bme280(String subtype, String param) {
// if (subtype == F("Bme280t") || subtype == F("Bme280h") || subtype == F("Bme280p")) {
// String addr;
// jsonRead(param, "addr", addr);
//
// if (bmes.find(addr) == bmes.end()) {
// bmes[addr] = new Adafruit_BME280();
// bmes[addr]->begin(hexStringToUint8(addr));
// }
//
// if (subtype == F("Bme280t")) {
// return new Bme280t(bmes[addr], param);
// } else if (subtype == F("Bme280h")) {
// return new Bme280h(bmes[addr], param);
// } else if (subtype == F("Bme280p")) {
// return new Bme280p(bmes[addr], param);
// }
//} else {
return nullptr;
//}
}

View File

@@ -54,21 +54,21 @@ class Bmp280p : public IoTItem {
};
void* getAPI_Bmp280(String subtype, String param) {
if (subtype == F("Bmp280t") || subtype == F("Bmp280p")) {
String addr;
jsonRead(param, "addr", addr);
if (bmps.find(addr) == bmps.end()) {
bmps[addr] = new Adafruit_BMP280();
bmps[addr]->begin(hexStringToUint8(addr));
}
if (subtype == F("Bmp280t")) {
return new Bmp280t(bmps[addr], param);
} else if (subtype == F("Bmp280p")) {
return new Bmp280p(bmps[addr], param);
}
} else {
return nullptr;
}
// if (subtype == F("Bmp280t") || subtype == F("Bmp280p")) {
// String addr;
// jsonRead(param, "addr", addr);
//
// if (bmps.find(addr) == bmps.end()) {
// bmps[addr] = new Adafruit_BMP280();
// bmps[addr]->begin(hexStringToUint8(addr));
// }
//
// if (subtype == F("Bmp280t")) {
// return new Bmp280t(bmps[addr], param);
// } else if (subtype == F("Bmp280p")) {
// return new Bmp280p(bmps[addr], param);
// }
//} else {
return nullptr;
//}
}

View File

@@ -4,77 +4,77 @@
https://github.com/beegee-tokyo/arduino-DHTesp
******************************************************************/
#include "Global.h"
#include "classes/IoTItem.h"
#include "DHTesp.h"
#include <map>
std::map<int, DHTesp*> dhts;
class Dht1122t : public IoTItem {
private:
DHTesp* _dht;
DHTesp* _dht;
public:
Dht1122t(DHTesp* dht, String parameters): IoTItem(parameters) {
Dht1122t(DHTesp* dht, String parameters) : IoTItem(parameters) {
_dht = dht;
}
void doByInterval() {
value.valD = _dht->getTemperature();
if (String(value.valD) != "nan") regEvent(value.valD, "Dht1122t");
else SerialPrint("E", "Sensor DHTt", "Error");
if (String(value.valD) != "nan")
regEvent(value.valD, "Dht1122t");
else
SerialPrint("E", "Sensor DHTt", "Error");
}
~Dht1122t() {};
~Dht1122t(){};
};
class Dht1122h : public IoTItem {
private:
DHTesp* _dht;
DHTesp* _dht;
public:
Dht1122h(DHTesp* dht, String parameters): IoTItem(parameters) {
Dht1122h(DHTesp* dht, String parameters) : IoTItem(parameters) {
_dht = dht;
}
void doByInterval() {
value.valD = _dht->getHumidity();
if (String(value.valD) != "nan") regEvent(value.valD, "Dht1122h");
else SerialPrint("E", "Sensor DHTh", "Error");
if (String(value.valD) != "nan")
regEvent(value.valD, "Dht1122h");
else
SerialPrint("E", "Sensor DHTh", "Error");
}
~Dht1122h() {};
~Dht1122h(){};
};
void* getAPI_Dht1122(String subtype, String param) {
if (subtype == F("Dht1122t") || subtype == F("Dht1122h")) {
int pin;
String senstype;
jsonRead(param, "pin", pin);
jsonRead(param, "senstype", senstype);
if (dhts.find(pin) == dhts.end()) {
dhts[pin] = new DHTesp();
if (senstype == "dht11") {
dhts[pin]->setup(pin, DHTesp::DHT11);
} else if (senstype == "dht22") {
dhts[pin]->setup(pin, DHTesp::DHT22);
}
}
if (subtype == F("Dht1122t")) {
return new Dht1122t(dhts[pin], param);
} else if (subtype == F("Dht1122h")) {
return new Dht1122h(dhts[pin], param);
}
} else {
return nullptr;
}
void* getAPI_Dht1122(String subtype, String param) {
// if (subtype == F("Dht1122t") || subtype == F("Dht1122h")) {
// int pin;
// String senstype;
// jsonRead(param, "pin", pin);
// jsonRead(param, "senstype", senstype);
//
// if (dhts.find(pin) == dhts.end()) {
// dhts[pin] = new DHTesp();
//
// if (senstype == "dht11") {
// dhts[pin]->setup(pin, DHTesp::DHT11);
// } else if (senstype == "dht22") {
// dhts[pin]->setup(pin, DHTesp::DHT22);
// }
// }
//
// if (subtype == F("Dht1122t")) {
// return new Dht1122t(dhts[pin], param);
// } else if (subtype == F("Dht1122h")) {
// return new Dht1122h(dhts[pin], param);
// }
//} else {
return nullptr;
//}
}

View File

@@ -15,45 +15,49 @@ GY21* sensor = nullptr;
class GY21t : public IoTItem {
public:
GY21t(String parameters): IoTItem(parameters) { }
GY21t(String parameters) : IoTItem(parameters) {}
void doByInterval() {
//wire->read();
// wire->read();
value.valD = sensor->GY21_Temperature();
if (value.valD < 300) regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных
else SerialPrint("E", "Sensor GY21t", "Error");
if (value.valD < 300)
regEvent(value.valD, "GY21"); // TODO: найти способ понимания ошибки получения данных
else
SerialPrint("E", "Sensor GY21t", "Error");
}
~GY21t() {};
~GY21t(){};
};
class GY21h : public IoTItem {
public:
GY21h(String parameters): IoTItem(parameters) { }
void doByInterval() {
//sht->read();
value.valD = sensor->GY21_Humidity();
if (value.valD != 0) regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных
else SerialPrint("E", "Sensor GY21h", "Error");
}
GY21h(String parameters) : IoTItem(parameters) {}
~GY21h() {};
void doByInterval() {
// sht->read();
value.valD = sensor->GY21_Humidity();
if (value.valD != 0)
regEvent(value.valD, "GY21h"); // TODO: найти способ понимания ошибки получения данных
else
SerialPrint("E", "Sensor GY21h", "Error");
}
~GY21h(){};
};
void* getAPI_GY21(String subtype, String param) {
if (subtype == F("GY21t") || subtype == F("GY21h")) {
if (!sensor) {
sensor = new GY21;
if (sensor) Wire.begin(SDA, SCL);
}
if (subtype == F("GY21t")) {
return new GY21t(param);
} else if (subtype == F("GY21h")) {
return new GY21h(param);
}
} else {
return nullptr;
}
// if (subtype == F("GY21t") || subtype == F("GY21h")) {
// if (!sensor) {
// sensor = new GY21;
// if (sensor) Wire.begin(SDA, SCL);
// }
//
// if (subtype == F("GY21t")) {
// return new GY21t(param);
// } else if (subtype == F("GY21h")) {
// return new GY21h(param);
// }
//} else {
return nullptr;
//}
}

View File

@@ -4,51 +4,53 @@
#include "Wire.h"
#include "SHT2x.h"
SHT2x* sht = nullptr;
class Sht20t : public IoTItem {
public:
Sht20t(String parameters): IoTItem(parameters) { }
Sht20t(String parameters) : IoTItem(parameters) {}
void doByInterval() {
sht->read();
value.valD = sht->getTemperature();
if (value.valD > -46.85F) regEvent(value.valD, "Sht20t");
else SerialPrint("E", "Sensor Sht20t", "Error");
if (value.valD > -46.85F)
regEvent(value.valD, "Sht20t");
else
SerialPrint("E", "Sensor Sht20t", "Error");
}
~Sht20t() {};
~Sht20t(){};
};
class Sht20h : public IoTItem {
public:
Sht20h(String parameters): IoTItem(parameters) { }
Sht20h(String parameters) : IoTItem(parameters) {}
void doByInterval() {
sht->read();
value.valD = sht->getHumidity();
if (value.valD != -6) regEvent(value.valD, "Sht20h");
else SerialPrint("E", "Sensor Sht20h", "Error");
}
if (value.valD != -6)
regEvent(value.valD, "Sht20h");
else
SerialPrint("E", "Sensor Sht20h", "Error");
}
~Sht20h() {};
~Sht20h(){};
};
void* getAPI_Sht20(String subtype, String param) {
if (subtype == F("Sht20t") || subtype == F("Sht20h")) {
if (!sht) {
sht = new SHT2x;
if (sht) sht->begin();
}
if (subtype == F("Sht20t")) {
return new Sht20t(param);
} else if (subtype == F("Sht20h")) {
return new Sht20h(param);
}
} else {
return nullptr;
}
// if (subtype == F("Sht20t") || subtype == F("Sht20h")) {
// if (!sht) {
// sht = new SHT2x;
// if (sht) sht->begin();
// }
//
// if (subtype == F("Sht20t")) {
// return new Sht20t(param);
// } else if (subtype == F("Sht20h")) {
// return new Sht20h(param);
// }
//} else {
return nullptr;
//}
}