mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-27 06:32:19 +03:00
переписан полностью датчик bme и bmp
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
#include "items/vCountDown.h"
|
||||
#include "items/vSensorAnalog.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorBme280.h"
|
||||
#include "items/vSensorBmp280.h"
|
||||
|
||||
void loopCmdAdd(const String& cmdStr) {
|
||||
if (cmdStr.endsWith(",")) {
|
||||
@@ -79,22 +81,13 @@ void csvCmdExecute(String& cmdStr) {
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorBme280Enabled
|
||||
else if (order == F("bme280-temp")) {
|
||||
sCmd.addCommand(order.c_str(), bme280Temp);
|
||||
}
|
||||
else if (order == F("bme280-hum")) {
|
||||
sCmd.addCommand(order.c_str(), bme280Hum);
|
||||
}
|
||||
else if (order == F("bme280-press")) {
|
||||
sCmd.addCommand(order.c_str(), bme280Press);
|
||||
else if (order == F("bme280")) {
|
||||
sCmd.addCommand(order.c_str(), bme280Sensor);
|
||||
}
|
||||
#endif
|
||||
#ifdef SensorBmp280Enabled
|
||||
else if (order == F("bmp280-temp")) {
|
||||
sCmd.addCommand(order.c_str(), bmp280Temp);
|
||||
}
|
||||
else if (order == F("bmp280-press")) {
|
||||
sCmd.addCommand(order.c_str(), bmp280Press);
|
||||
else if (order == F("bmp280")) {
|
||||
sCmd.addCommand(order.c_str(), bmp280Sensor);
|
||||
}
|
||||
#endif
|
||||
else if (order == F("uptime")) {
|
||||
@@ -136,31 +129,6 @@ void loopCmdExecute() {
|
||||
}
|
||||
}
|
||||
|
||||
void sensorsInit() {
|
||||
ts.add(
|
||||
SENSORS10SEC, 10000, [&](void*) {
|
||||
String buf = sensorReadingMap10sec;
|
||||
while (buf.length()) {
|
||||
String tmp = selectToMarker(buf, ",");
|
||||
sCmd.readStr(tmp);
|
||||
buf = deleteBeforeDelimiter(buf, ",");
|
||||
}
|
||||
},
|
||||
nullptr, true);
|
||||
|
||||
ts.add(
|
||||
SENSORS30SEC, 30000, [&](void*) {
|
||||
String buf = sensorReadingMap30sec;
|
||||
while (buf.length()) {
|
||||
String tmp = selectToMarker(buf, ",");
|
||||
sCmd.readStr(tmp);
|
||||
buf = deleteBeforeDelimiter(buf, ",");
|
||||
}
|
||||
},
|
||||
nullptr, true);
|
||||
SerialPrint("I", F("Sensors"), F("Sensors Init"));
|
||||
}
|
||||
|
||||
void addKey(String& key, String& keyNumberTable, int number) {
|
||||
keyNumberTable += key + " " + String(number) + ",";
|
||||
}
|
||||
|
||||
@@ -62,9 +62,6 @@ int logging_EnterCounter = -1;
|
||||
int dht_EnterCounter = -1;
|
||||
//=========================================
|
||||
|
||||
// Sensors
|
||||
String sensorReadingMap10sec;
|
||||
String sensorReadingMap30sec;
|
||||
|
||||
String itemName;
|
||||
String presetName;
|
||||
|
||||
@@ -43,7 +43,6 @@ void espInit() {
|
||||
}
|
||||
|
||||
void deviceInit() {
|
||||
sensorReadingMap10sec = "";
|
||||
|
||||
//======clear dallas params======
|
||||
if (mySensorDallas2 != nullptr) {
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
#include "Consts.h"
|
||||
#ifdef SensorBme280Enabled
|
||||
#include "items/SensorBme280Class.h"
|
||||
#include "BufferExecute.h"
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//bme280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//bme280-hum;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//bme280-press;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//=========================================================================================================================================
|
||||
SensorBme280Class mySensorBme280;
|
||||
|
||||
void bme280Temp() {
|
||||
mySensorBme280.update();
|
||||
String key = mySensorBme280.gkey();
|
||||
sCmd.addCommand(key.c_str(), bme280ReadingTemp);
|
||||
mySensorBme280.SensorBme280Init();
|
||||
mySensorBme280.clear();
|
||||
}
|
||||
void bme280ReadingTemp() {
|
||||
String key = sCmd.order();
|
||||
mySensorBme280.SensorBme280ReadTmp(key);
|
||||
}
|
||||
|
||||
void bme280Hum() {
|
||||
mySensorBme280.update();
|
||||
String key = mySensorBme280.gkey();
|
||||
sCmd.addCommand(key.c_str(), bme280ReadingHum);
|
||||
mySensorBme280.SensorBme280Init();
|
||||
mySensorBme280.clear();
|
||||
}
|
||||
void bme280ReadingHum() {
|
||||
String key = sCmd.order();
|
||||
mySensorBme280.SensorBme280ReadHum(key);
|
||||
}
|
||||
|
||||
void bme280Press() {
|
||||
mySensorBme280.update();
|
||||
String key = mySensorBme280.gkey();
|
||||
sCmd.addCommand(key.c_str(), bme280ReadingPress);
|
||||
mySensorBme280.SensorBme280Init();
|
||||
mySensorBme280.clear();
|
||||
}
|
||||
void bme280ReadingPress() {
|
||||
String key = sCmd.order();
|
||||
mySensorBme280.SensorBme280ReadPress(key);
|
||||
}
|
||||
#endif
|
||||
@@ -1,35 +0,0 @@
|
||||
#include "Consts.h"
|
||||
#ifdef SensorBmp280Enabled
|
||||
#include "items/SensorBmp280Class.h"
|
||||
#include "BufferExecute.h"
|
||||
//=========================================Модуль ультрозвукового дальномера==================================================================
|
||||
//bmp280-temp;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//bmp280-hum;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//bmp280-press;id;anydata;Сенсоры;Температура;order;c[1]
|
||||
//=========================================================================================================================================
|
||||
SensorBmp280Class mySensorBmp280;
|
||||
|
||||
void bmp280Temp() {
|
||||
mySensorBmp280.update();
|
||||
String key = mySensorBmp280.gkey();
|
||||
sCmd.addCommand(key.c_str(), bmp280ReadingTemp);
|
||||
mySensorBmp280.SensorBmp280Init();
|
||||
mySensorBmp280.clear();
|
||||
}
|
||||
void bmp280ReadingTemp() {
|
||||
String key = sCmd.order();
|
||||
mySensorBmp280.SensorBmp280ReadTmp(key);
|
||||
}
|
||||
|
||||
void bmp280Press() {
|
||||
mySensorBmp280.update();
|
||||
String key = mySensorBmp280.gkey();
|
||||
sCmd.addCommand(key.c_str(), bmp280ReadingPress);
|
||||
mySensorBmp280.SensorBmp280Init();
|
||||
mySensorBmp280.clear();
|
||||
}
|
||||
void bmp280ReadingPress() {
|
||||
String key = sCmd.order();
|
||||
mySensorBmp280.SensorBmp280ReadPress(key);
|
||||
}
|
||||
#endif
|
||||
@@ -7,7 +7,7 @@ void sysUptime() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
sCmd.addCommand(key.c_str(), uptimeReading);
|
||||
sensorReadingMap30sec += key + ",";
|
||||
//ensorReadingMap30sec += key + ",";
|
||||
myLineParsing.clear();
|
||||
}
|
||||
|
||||
|
||||
100
src/items/vSensorBme280.cpp
Normal file
100
src/items/vSensorBme280.cpp
Normal file
@@ -0,0 +1,100 @@
|
||||
#include "items/vSensorBme280.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
Adafruit_BME280* bme = nullptr;
|
||||
|
||||
SensorBme280::SensorBme280(const paramsBme& paramsTmp, const paramsBme& paramsHum, const paramsBme& paramsPrs) {
|
||||
_paramsTmp = paramsBme(paramsTmp);
|
||||
_paramsHum = paramsBme(paramsHum);
|
||||
_paramsPrs = paramsBme(paramsPrs);
|
||||
|
||||
if (!bme) {
|
||||
bme = new Adafruit_BME280;
|
||||
}
|
||||
|
||||
bme->getTemperatureSensor();
|
||||
bme->getPressureSensor();
|
||||
bme->getHumiditySensor();
|
||||
bme->begin(hexStringToUint8(_paramsPrs.addr));
|
||||
}
|
||||
|
||||
SensorBme280::~SensorBme280() {}
|
||||
|
||||
void SensorBme280::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsPrs.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorBme280::read() {
|
||||
float tmp = bme->readTemperature();
|
||||
float hum = bme->readHumidity();
|
||||
float prs = bme->readPressure();
|
||||
prs = prs / 1.333224 / 100;
|
||||
|
||||
tmp = tmp * _paramsTmp.c;
|
||||
hum = hum * _paramsHum.c;
|
||||
prs = prs * _paramsPrs.c;
|
||||
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsHum.key, String(hum));
|
||||
jsonWriteStr(configLiveJson, _paramsHum.key, String(hum));
|
||||
publishStatus(_paramsHum.key, String(hum));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsHum.key + "' data: " + String(hum));
|
||||
|
||||
eventGen2(_paramsPrs.key, String(prs));
|
||||
jsonWriteStr(configLiveJson, _paramsPrs.key, String(prs));
|
||||
publishStatus(_paramsPrs.key, String(prs));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPrs.key + "' data: " + String(prs));
|
||||
}
|
||||
|
||||
MySensorBme280Vector* mySensorBme280 = nullptr;
|
||||
|
||||
void bme280Sensor() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String addr = myLineParsing.gaddr();
|
||||
String interval = myLineParsing.gint();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsBme paramsTmp;
|
||||
static paramsBme paramsHum;
|
||||
static paramsBme paramsPrs;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsTmp.key = key;
|
||||
paramsTmp.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsHum.key = key;
|
||||
paramsHum.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 2) {
|
||||
paramsPrs.key = key;
|
||||
paramsPrs.addr = addr;
|
||||
paramsPrs.interval = interval.toInt() * 1000;
|
||||
paramsPrs.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorBme280 = new MySensorBme280Vector();
|
||||
firstTime = false;
|
||||
mySensorBme280->push_back(SensorBme280(paramsTmp, paramsHum, paramsPrs));
|
||||
}
|
||||
}
|
||||
86
src/items/vSensorBmp280.cpp
Normal file
86
src/items/vSensorBmp280.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "items/vSensorBmp280.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#include "BufferExecute.h"
|
||||
#include "Class/LineParsing.h"
|
||||
#include "Global.h"
|
||||
|
||||
Adafruit_BMP280* bmp = nullptr;
|
||||
|
||||
SensorBmp280::SensorBmp280(const paramsBmp& paramsTmp, const paramsBmp& paramsPrs) {
|
||||
_paramsTmp = paramsBmp(paramsTmp);
|
||||
_paramsPrs = paramsBmp(paramsPrs);
|
||||
|
||||
if (!bmp) {
|
||||
bmp = new Adafruit_BMP280;
|
||||
}
|
||||
|
||||
bmp->getTemperatureSensor();
|
||||
bmp->getPressureSensor();
|
||||
bmp->begin(hexStringToUint8(_paramsPrs.addr));
|
||||
}
|
||||
|
||||
SensorBmp280::~SensorBmp280() {}
|
||||
|
||||
void SensorBmp280::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _paramsPrs.interval) {
|
||||
prevMillis = millis();
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorBmp280::read() {
|
||||
float tmp = bmp->readTemperature();
|
||||
float prs = bmp->readPressure();
|
||||
prs = prs / 1.333224 / 100;
|
||||
|
||||
tmp = tmp * _paramsTmp.c;
|
||||
prs = prs * _paramsPrs.c;
|
||||
|
||||
eventGen2(_paramsTmp.key, String(tmp));
|
||||
jsonWriteStr(configLiveJson, _paramsTmp.key, String(tmp));
|
||||
publishStatus(_paramsTmp.key, String(tmp));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsTmp.key + "' data: " + String(tmp));
|
||||
|
||||
eventGen2(_paramsPrs.key, String(prs));
|
||||
jsonWriteStr(configLiveJson, _paramsPrs.key, String(prs));
|
||||
publishStatus(_paramsPrs.key, String(prs));
|
||||
SerialPrint("I", "Sensor", "'" + _paramsPrs.key + "' data: " + String(prs));
|
||||
}
|
||||
|
||||
MySensorBmp280Vector* mySensorBmp280 = nullptr;
|
||||
|
||||
void bmp280Sensor() {
|
||||
myLineParsing.update();
|
||||
String key = myLineParsing.gkey();
|
||||
String addr = myLineParsing.gaddr();
|
||||
String interval = myLineParsing.gint();
|
||||
String c = myLineParsing.gc();
|
||||
myLineParsing.clear();
|
||||
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static paramsBmp paramsTmp;
|
||||
static paramsBmp paramsHum;
|
||||
static paramsBmp paramsPrs;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsTmp.key = key;
|
||||
paramsTmp.c = c.toFloat();
|
||||
}
|
||||
|
||||
if (enterCnt == 1) {
|
||||
paramsPrs.key = key;
|
||||
paramsPrs.addr = addr;
|
||||
paramsPrs.interval = interval.toInt() * 1000;
|
||||
paramsPrs.c = c.toFloat();
|
||||
|
||||
static bool firstTime = true;
|
||||
if (firstTime) mySensorBmp280 = new MySensorBmp280Vector();
|
||||
firstTime = false;
|
||||
mySensorBmp280->push_back(SensorBmp280(paramsTmp, paramsPrs));
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
DHTesp* dht = nullptr;
|
||||
|
||||
SensorDht::SensorDht(const params& paramsTmp, const params& paramsHum) {
|
||||
_paramsTmp = params(paramsTmp);
|
||||
_paramsHum = params(paramsHum);
|
||||
SensorDht::SensorDht(const paramsDht& paramsTmp, const paramsDht& paramsHum) {
|
||||
_paramsTmp = paramsDht(paramsTmp);
|
||||
_paramsHum = paramsDht(paramsHum);
|
||||
|
||||
if (!dht) {
|
||||
dht = new DHTesp();
|
||||
@@ -23,26 +23,23 @@ SensorDht::SensorDht(const params& paramsTmp, const params& paramsHum) {
|
||||
dht->setup(_paramsTmp.pin, DHTesp::DHT22);
|
||||
}
|
||||
}
|
||||
_interval = _paramsTmp.interval < _paramsHum.interval ? _paramsTmp.interval : _paramsHum.interval;
|
||||
_interval = _interval + dht->getMinimumSamplingPeriod();
|
||||
|
||||
_paramsHum.interval = _paramsHum.interval + dht->getMinimumSamplingPeriod();
|
||||
}
|
||||
|
||||
SensorDht::~SensorDht() {}
|
||||
|
||||
void SensorDht::loop() {
|
||||
difference = millis() - prevMillis;
|
||||
if (difference >= _interval) {
|
||||
if (difference >= _paramsHum.interval) {
|
||||
prevMillis = millis();
|
||||
readTmpHum();
|
||||
}
|
||||
}
|
||||
|
||||
void SensorDht::readTmpHum() {
|
||||
float tmp;
|
||||
float hum;
|
||||
|
||||
tmp = dht->getTemperature();
|
||||
hum = dht->getHumidity();
|
||||
float tmp = dht->getTemperature();
|
||||
float hum = dht->getHumidity();
|
||||
|
||||
if (String(tmp) != "nan" && String(hum) != "nan") {
|
||||
tmp = tmp * _paramsTmp.c;
|
||||
@@ -77,8 +74,8 @@ void dhtSensor() {
|
||||
static int enterCnt = -1;
|
||||
enterCnt++;
|
||||
|
||||
static params paramsTmp;
|
||||
static params paramsHum;
|
||||
static paramsDht paramsTmp;
|
||||
static paramsDht paramsHum;
|
||||
|
||||
if (enterCnt == 0) {
|
||||
paramsTmp.type = type;
|
||||
|
||||
13
src/main.cpp
13
src/main.cpp
@@ -26,6 +26,8 @@
|
||||
#include "items/vSensorDallas.h"
|
||||
#include "items/vSensorDht.h"
|
||||
#include "items/vSensorUltrasonic.h"
|
||||
#include "items/vSensorBme280.h"
|
||||
#include "items/vSensorBmp280.h"
|
||||
|
||||
void not_async_actions();
|
||||
|
||||
@@ -50,7 +52,6 @@ void setup() {
|
||||
#endif
|
||||
clockInit();
|
||||
timeInit();
|
||||
sensorsInit(); //Will be remooved
|
||||
itemsListInit();
|
||||
espInit();
|
||||
routerConnect();
|
||||
@@ -140,4 +141,14 @@ void loop() {
|
||||
mySensorDht->at(i).loop();
|
||||
}
|
||||
}
|
||||
if (mySensorBme280 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorBme280->size(); i++) {
|
||||
mySensorBme280->at(i).loop();
|
||||
}
|
||||
}
|
||||
if (mySensorBmp280 != nullptr) {
|
||||
for (unsigned int i = 0; i < mySensorBmp280->size(); i++) {
|
||||
mySensorBmp280->at(i).loop();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user