mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-30 11:59:12 +03:00
переписан полностью датчик bme и bmp
This commit is contained in:
@@ -9,15 +9,15 @@
|
|||||||
0;analog-adc;adcid;fillgauge;Сенсоры;Аналоговый;order;pin[0];map[0,1024,0,100];c[1];int[10]*
|
0;analog-adc;adcid;fillgauge;Сенсоры;Аналоговый;order;pin[0];map[0,1024,0,100];c[1];int[10]*
|
||||||
0;dallas-temp;tmpid;anydataTemp;Сенсоры;Температура;order;pin[2];index[0];int[10]*
|
0;dallas-temp;tmpid;anydataTemp;Сенсоры;Температура;order;pin[2];index[0];int[10]*
|
||||||
0;ultrasonic-cm;cmid;anydata;Сенсоры;Расстояние;order;pin[12,13];map[0,500,0,100];c[1];int[10]*
|
0;ultrasonic-cm;cmid;anydata;Сенсоры;Расстояние;order;pin[12,13];map[0,500,0,100];c[1];int[10]*
|
||||||
0;dht;tmpid;anydataTemp;Сенсоры;Температура;1;pin[2];type[dht11];c[1];int[10]
|
0;dht;tmpid;anydataTemp;Сенсоры;Температура;1;pin[2];type[dht11];c[1]
|
||||||
0;dht;humid;anydataHum;Сенсоры;Влажность;2;pin[2];type[dht11];c[1];int[10]*
|
0;dht;humid;anydataHum;Сенсоры;Влажность;2;pin[2];type[dht11];c[1];int[10]*
|
||||||
0;dht;tmpid;anydataTemp;Сенсоры;Температура;1;pin[2];type[dht22];c[1];int[10]
|
0;dht;tmpid;anydataTemp;Сенсоры;Температура;1;pin[2];type[dht22];c[1]
|
||||||
0;dht;humid;anydataHum;Сенсоры;Влажность;2;pin[2];type[dht22];c[1];int[10]*
|
0;dht;humid;anydataHum;Сенсоры;Влажность;2;pin[2];type[dht22];c[1];int[10]*
|
||||||
0;bme280;tmpid;anydataTemp;Сенсоры;Температура;1;addr[0x76];c[1]
|
0;bme280;tmpid;anydataTemp;Сенсоры;Температура;1;c[1]
|
||||||
0;bme280;humid;anydataHum;Сенсоры;Влажность;2;addr[0x76];c[1]
|
0;bme280;humid;anydataHum;Сенсоры;Влажность;2;c[1]
|
||||||
0;bme280;prsid;anydataPress;Сенсоры;Давление;3;addr[0x76];c[1]*
|
0;bme280;prsid;anydataPress;Сенсоры;Давление;3;c[1];addr[0x76];int[10]*
|
||||||
0;bmp280;tmpid;anydataPress;Сенсоры;Давление;1;addr[0x76];c[1]
|
0;bmp280;tmpid;anydataTemp;Сенсоры;Температура;1;c[1]
|
||||||
0;bmp280;humid;anydataTemp;Сенсоры;Температура;2;addr[0x76];c[1]*
|
0;bmp280;prsid;anydataPress;Сенсоры;Давление;3;c[1];addr[0x76];int[10]*
|
||||||
0;impuls-out;impid;na;na;na;order;gpio*
|
0;impuls-out;impid;na;na;na;order;gpio*
|
||||||
0;count-down;cntid;anydata;Таймер;Обратный#отчет;order*
|
0;count-down;cntid;anydata;Таймер;Обратный#отчет;order*
|
||||||
0;inoutput;txtid;anydata;Вывод;Вывод#uart;order*
|
0;inoutput;txtid;anydata;Вывод;Вывод#uart;order*
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
extern void cmd_init();
|
extern void cmd_init();
|
||||||
|
|
||||||
extern void sensorsInit();
|
|
||||||
|
|
||||||
//extern void levelPr();
|
//extern void levelPr();
|
||||||
//extern void ultrasonicCm();
|
//extern void ultrasonicCm();
|
||||||
|
|||||||
@@ -47,8 +47,6 @@
|
|||||||
//================================================================================================================================================================
|
//================================================================================================================================================================
|
||||||
enum TimerTask_t { WIFI_SCAN,
|
enum TimerTask_t { WIFI_SCAN,
|
||||||
WIFI_MQTT_CONNECTION_CHECK,
|
WIFI_MQTT_CONNECTION_CHECK,
|
||||||
SENSORS10SEC,
|
|
||||||
SENSORS30SEC,
|
|
||||||
TIME,
|
TIME,
|
||||||
TIME_SYNC,
|
TIME_SYNC,
|
||||||
STATISTICS,
|
STATISTICS,
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
//===================Libraries===================================================================================================================================================
|
//===================Libraries===================================================================================================================================================
|
||||||
#include "Consts.h"
|
#include "Consts.h"
|
||||||
#include <Adafruit_BME280.h>
|
|
||||||
#include <Adafruit_BMP280.h>
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "CTBot.h"
|
#include "CTBot.h"
|
||||||
#include <ArduinoJson.h>
|
#include <ArduinoJson.h>
|
||||||
@@ -91,9 +91,7 @@ extern int logging_EnterCounter;
|
|||||||
extern int dht_EnterCounter;
|
extern int dht_EnterCounter;
|
||||||
//=========================================
|
//=========================================
|
||||||
|
|
||||||
// Sensors
|
|
||||||
extern String sensorReadingMap10sec;
|
|
||||||
extern String sensorReadingMap30sec;
|
|
||||||
|
|
||||||
extern String itemName;
|
extern String itemName;
|
||||||
extern String presetName;
|
extern String presetName;
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Consts.h"
|
|
||||||
#ifdef SensorBme280Enabled
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "Class/LineParsing.h"
|
|
||||||
#include "Global.h"
|
|
||||||
#include "items/SensorConvertingClass.h"
|
|
||||||
|
|
||||||
Adafruit_BME280 bme;
|
|
||||||
Adafruit_Sensor *bme_temp = bme.getTemperatureSensor();
|
|
||||||
Adafruit_Sensor *bme_pressure = bme.getPressureSensor();
|
|
||||||
Adafruit_Sensor *bme_humidity = bme.getHumiditySensor();
|
|
||||||
|
|
||||||
class SensorBme280Class : public SensorConvertingClass {
|
|
||||||
public:
|
|
||||||
SensorBme280Class() : SensorConvertingClass(){};
|
|
||||||
|
|
||||||
void SensorBme280Init() {
|
|
||||||
bme.begin(hexStringToUint8(_addr));
|
|
||||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
|
||||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
|
||||||
sensorReadingMap10sec += _key + ",";
|
|
||||||
}
|
|
||||||
|
|
||||||
void SensorBme280ReadTmp(String key) {
|
|
||||||
float value;
|
|
||||||
value = bme.readTemperature();
|
|
||||||
float valueFl = this->correction(key, value);
|
|
||||||
eventGen2(key, String(valueFl));
|
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
|
||||||
publishStatus(key, String(valueFl));
|
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SensorBme280ReadHum(String key) {
|
|
||||||
float value;
|
|
||||||
value = bme.readHumidity();
|
|
||||||
float valueFl = this->correction(key, value);
|
|
||||||
eventGen2(key, String(valueFl));
|
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
|
||||||
publishStatus(key, String(valueFl));
|
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SensorBme280ReadPress(String key) {
|
|
||||||
float value;
|
|
||||||
value = bme.readPressure();
|
|
||||||
value = value / 1.333224 / 100;
|
|
||||||
float valueFl = this->correction(key, value);
|
|
||||||
eventGen2(key, String(valueFl));
|
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
|
||||||
publishStatus(key, String(valueFl));
|
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
extern SensorBme280Class mySensorBme280;
|
|
||||||
#endif
|
|
||||||
@@ -1,50 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "Consts.h"
|
|
||||||
#ifdef SensorBmp280Enabled
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include "Class/LineParsing.h"
|
|
||||||
#include "Global.h"
|
|
||||||
#include "items/SensorConvertingClass.h"
|
|
||||||
|
|
||||||
Adafruit_BMP280 bmp;
|
|
||||||
Adafruit_Sensor *bmp_temp = bmp.getTemperatureSensor();
|
|
||||||
Adafruit_Sensor *bmp_pressure = bmp.getPressureSensor();
|
|
||||||
|
|
||||||
class SensorBmp280Class : public SensorConvertingClass {
|
|
||||||
public:
|
|
||||||
SensorBmp280Class() : SensorConvertingClass(){};
|
|
||||||
|
|
||||||
void SensorBmp280Init() {
|
|
||||||
bmp.begin(hexStringToUint8(_addr));
|
|
||||||
jsonWriteStr(configOptionJson, _key + "_map", _map);
|
|
||||||
jsonWriteStr(configOptionJson, _key + "_с", _c);
|
|
||||||
sensorReadingMap10sec += _key + ",";
|
|
||||||
}
|
|
||||||
|
|
||||||
void SensorBmp280ReadTmp(String key) {
|
|
||||||
float value;
|
|
||||||
sensors_event_t temp_event;
|
|
||||||
bmp_temp->getEvent(&temp_event);
|
|
||||||
value = temp_event.temperature;
|
|
||||||
float valueFl = this->correction(key, value);
|
|
||||||
eventGen2(key, String(valueFl));
|
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
|
||||||
publishStatus(key, String(valueFl));
|
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
|
||||||
}
|
|
||||||
|
|
||||||
void SensorBmp280ReadPress(String key) {
|
|
||||||
float value;
|
|
||||||
sensors_event_t pressure_event;
|
|
||||||
bmp_pressure->getEvent(&pressure_event);
|
|
||||||
value = pressure_event.pressure;
|
|
||||||
value = value / 1.333224;
|
|
||||||
float valueFl = this->correction(key, value);
|
|
||||||
eventGen2(key, String(valueFl));
|
|
||||||
jsonWriteStr(configLiveJson, key, String(valueFl));
|
|
||||||
publishStatus(key, String(valueFl));
|
|
||||||
SerialPrint("I", "Sensor", "'" + key + "' data: " + String(valueFl));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
extern SensorBmp280Class mySensorBmp280;
|
|
||||||
#endif
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
|
|
||||||
#include "Class/LineParsing.h"
|
|
||||||
#include "Global.h"
|
|
||||||
|
|
||||||
class SensorConvertingClass : public LineParsing {
|
|
||||||
public:
|
|
||||||
SensorConvertingClass() : LineParsing(){};
|
|
||||||
|
|
||||||
int mapping(String key, int input) {
|
|
||||||
String map_ = jsonReadStr(configOptionJson, key + "_map");
|
|
||||||
if (map_ != "") {
|
|
||||||
input = map(input,
|
|
||||||
selectFromMarkerToMarker(map_, ",", 0).toInt(),
|
|
||||||
selectFromMarkerToMarker(map_, ",", 1).toInt(),
|
|
||||||
selectFromMarkerToMarker(map_, ",", 2).toInt(),
|
|
||||||
selectFromMarkerToMarker(map_, ",", 3).toInt());
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
|
|
||||||
float correction(String key, float input) {
|
|
||||||
String corr = jsonReadStr(configOptionJson, key + "_с");
|
|
||||||
if (corr != "") {
|
|
||||||
float coef = corr.toFloat();
|
|
||||||
input = input * coef;
|
|
||||||
}
|
|
||||||
return input;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
39
include/items/vSensorBme280.h
Normal file
39
include/items/vSensorBme280.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Adafruit_BME280.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
extern Adafruit_BME280* bme;
|
||||||
|
|
||||||
|
class SensorBme280;
|
||||||
|
|
||||||
|
typedef std::vector<SensorBme280> MySensorBme280Vector;
|
||||||
|
|
||||||
|
struct paramsBme {
|
||||||
|
String key;
|
||||||
|
String addr;
|
||||||
|
unsigned long interval;
|
||||||
|
float c;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SensorBme280 {
|
||||||
|
public:
|
||||||
|
SensorBme280(const paramsBme& paramsTmp, const paramsBme& paramsHum, const paramsBme& paramsPrs);
|
||||||
|
~SensorBme280();
|
||||||
|
|
||||||
|
void loop();
|
||||||
|
void read();
|
||||||
|
|
||||||
|
private:
|
||||||
|
paramsBme _paramsTmp;
|
||||||
|
paramsBme _paramsHum;
|
||||||
|
paramsBme _paramsPrs;
|
||||||
|
|
||||||
|
unsigned long prevMillis;
|
||||||
|
unsigned long difference;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MySensorBme280Vector* mySensorBme280;
|
||||||
|
|
||||||
|
extern void bme280Sensor();
|
||||||
38
include/items/vSensorBmp280.h
Normal file
38
include/items/vSensorBmp280.h
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <Adafruit_BMP280.h>
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include "Global.h"
|
||||||
|
|
||||||
|
extern Adafruit_BMP280* bmp;
|
||||||
|
|
||||||
|
class SensorBmp280;
|
||||||
|
|
||||||
|
typedef std::vector<SensorBmp280> MySensorBmp280Vector;
|
||||||
|
|
||||||
|
struct paramsBmp {
|
||||||
|
String key;
|
||||||
|
String addr;
|
||||||
|
unsigned long interval;
|
||||||
|
float c;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SensorBmp280 {
|
||||||
|
public:
|
||||||
|
SensorBmp280(const paramsBmp& paramsTmp, const paramsBmp& paramsPrs);
|
||||||
|
~SensorBmp280();
|
||||||
|
|
||||||
|
void loop();
|
||||||
|
void read();
|
||||||
|
|
||||||
|
private:
|
||||||
|
paramsBmp _paramsTmp;
|
||||||
|
paramsBmp _paramsPrs;
|
||||||
|
|
||||||
|
unsigned long prevMillis;
|
||||||
|
unsigned long difference;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern MySensorBmp280Vector* mySensorBmp280;
|
||||||
|
|
||||||
|
extern void bmp280Sensor();
|
||||||
@@ -11,7 +11,7 @@ class SensorDht;
|
|||||||
|
|
||||||
typedef std::vector<SensorDht> MySensorDhtVector;
|
typedef std::vector<SensorDht> MySensorDhtVector;
|
||||||
|
|
||||||
struct params {
|
struct paramsDht {
|
||||||
String type;
|
String type;
|
||||||
String key;
|
String key;
|
||||||
unsigned long interval;
|
unsigned long interval;
|
||||||
@@ -21,17 +21,15 @@ struct params {
|
|||||||
|
|
||||||
class SensorDht {
|
class SensorDht {
|
||||||
public:
|
public:
|
||||||
SensorDht(const params& paramsTmp, const params& paramsHum);
|
SensorDht(const paramsDht& paramsTmp, const paramsDht& paramsHum);
|
||||||
~SensorDht();
|
~SensorDht();
|
||||||
|
|
||||||
void loop();
|
void loop();
|
||||||
void readTmpHum();
|
void readTmpHum();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
params _paramsTmp;
|
paramsDht _paramsTmp;
|
||||||
params _paramsHum;
|
paramsDht _paramsHum;
|
||||||
|
|
||||||
unsigned int _interval;
|
|
||||||
|
|
||||||
unsigned long prevMillis;
|
unsigned long prevMillis;
|
||||||
unsigned long difference;
|
unsigned long difference;
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "Global.h"
|
#include "Global.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "items/SensorConvertingClass.h"
|
|
||||||
#include "GyverFilters.h"
|
#include "GyverFilters.h"
|
||||||
|
|
||||||
class SensorUltrasonic;
|
class SensorUltrasonic;
|
||||||
|
|
||||||
typedef std::vector<SensorUltrasonic> MySensorUltrasonicVector;
|
typedef std::vector<SensorUltrasonic> MySensorUltrasonicVector;
|
||||||
|
|
||||||
class SensorUltrasonic : public SensorConvertingClass {
|
class SensorUltrasonic {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SensorUltrasonic(String key, unsigned long interval, unsigned int trig, unsigned int echo, int map1, int map2, int map3, int map4, float c);
|
SensorUltrasonic(String key, unsigned long interval, unsigned int trig, unsigned int echo, int map1, int map2, int map3, int map4, float c);
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
#include "items/vCountDown.h"
|
#include "items/vCountDown.h"
|
||||||
#include "items/vSensorAnalog.h"
|
#include "items/vSensorAnalog.h"
|
||||||
#include "items/vSensorDht.h"
|
#include "items/vSensorDht.h"
|
||||||
|
#include "items/vSensorBme280.h"
|
||||||
|
#include "items/vSensorBmp280.h"
|
||||||
|
|
||||||
void loopCmdAdd(const String& cmdStr) {
|
void loopCmdAdd(const String& cmdStr) {
|
||||||
if (cmdStr.endsWith(",")) {
|
if (cmdStr.endsWith(",")) {
|
||||||
@@ -79,22 +81,13 @@ void csvCmdExecute(String& cmdStr) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef SensorBme280Enabled
|
#ifdef SensorBme280Enabled
|
||||||
else if (order == F("bme280-temp")) {
|
else if (order == F("bme280")) {
|
||||||
sCmd.addCommand(order.c_str(), bme280Temp);
|
sCmd.addCommand(order.c_str(), bme280Sensor);
|
||||||
}
|
|
||||||
else if (order == F("bme280-hum")) {
|
|
||||||
sCmd.addCommand(order.c_str(), bme280Hum);
|
|
||||||
}
|
|
||||||
else if (order == F("bme280-press")) {
|
|
||||||
sCmd.addCommand(order.c_str(), bme280Press);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#ifdef SensorBmp280Enabled
|
#ifdef SensorBmp280Enabled
|
||||||
else if (order == F("bmp280-temp")) {
|
else if (order == F("bmp280")) {
|
||||||
sCmd.addCommand(order.c_str(), bmp280Temp);
|
sCmd.addCommand(order.c_str(), bmp280Sensor);
|
||||||
}
|
|
||||||
else if (order == F("bmp280-press")) {
|
|
||||||
sCmd.addCommand(order.c_str(), bmp280Press);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else if (order == F("uptime")) {
|
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) {
|
void addKey(String& key, String& keyNumberTable, int number) {
|
||||||
keyNumberTable += key + " " + String(number) + ",";
|
keyNumberTable += key + " " + String(number) + ",";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,9 +62,6 @@ int logging_EnterCounter = -1;
|
|||||||
int dht_EnterCounter = -1;
|
int dht_EnterCounter = -1;
|
||||||
//=========================================
|
//=========================================
|
||||||
|
|
||||||
// Sensors
|
|
||||||
String sensorReadingMap10sec;
|
|
||||||
String sensorReadingMap30sec;
|
|
||||||
|
|
||||||
String itemName;
|
String itemName;
|
||||||
String presetName;
|
String presetName;
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ void espInit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void deviceInit() {
|
void deviceInit() {
|
||||||
sensorReadingMap10sec = "";
|
|
||||||
|
|
||||||
//======clear dallas params======
|
//======clear dallas params======
|
||||||
if (mySensorDallas2 != nullptr) {
|
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();
|
myLineParsing.update();
|
||||||
String key = myLineParsing.gkey();
|
String key = myLineParsing.gkey();
|
||||||
sCmd.addCommand(key.c_str(), uptimeReading);
|
sCmd.addCommand(key.c_str(), uptimeReading);
|
||||||
sensorReadingMap30sec += key + ",";
|
//ensorReadingMap30sec += key + ",";
|
||||||
myLineParsing.clear();
|
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;
|
DHTesp* dht = nullptr;
|
||||||
|
|
||||||
SensorDht::SensorDht(const params& paramsTmp, const params& paramsHum) {
|
SensorDht::SensorDht(const paramsDht& paramsTmp, const paramsDht& paramsHum) {
|
||||||
_paramsTmp = params(paramsTmp);
|
_paramsTmp = paramsDht(paramsTmp);
|
||||||
_paramsHum = params(paramsHum);
|
_paramsHum = paramsDht(paramsHum);
|
||||||
|
|
||||||
if (!dht) {
|
if (!dht) {
|
||||||
dht = new DHTesp();
|
dht = new DHTesp();
|
||||||
@@ -23,26 +23,23 @@ SensorDht::SensorDht(const params& paramsTmp, const params& paramsHum) {
|
|||||||
dht->setup(_paramsTmp.pin, DHTesp::DHT22);
|
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() {}
|
SensorDht::~SensorDht() {}
|
||||||
|
|
||||||
void SensorDht::loop() {
|
void SensorDht::loop() {
|
||||||
difference = millis() - prevMillis;
|
difference = millis() - prevMillis;
|
||||||
if (difference >= _interval) {
|
if (difference >= _paramsHum.interval) {
|
||||||
prevMillis = millis();
|
prevMillis = millis();
|
||||||
readTmpHum();
|
readTmpHum();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorDht::readTmpHum() {
|
void SensorDht::readTmpHum() {
|
||||||
float tmp;
|
float tmp = dht->getTemperature();
|
||||||
float hum;
|
float hum = dht->getHumidity();
|
||||||
|
|
||||||
tmp = dht->getTemperature();
|
|
||||||
hum = dht->getHumidity();
|
|
||||||
|
|
||||||
if (String(tmp) != "nan" && String(hum) != "nan") {
|
if (String(tmp) != "nan" && String(hum) != "nan") {
|
||||||
tmp = tmp * _paramsTmp.c;
|
tmp = tmp * _paramsTmp.c;
|
||||||
@@ -77,8 +74,8 @@ void dhtSensor() {
|
|||||||
static int enterCnt = -1;
|
static int enterCnt = -1;
|
||||||
enterCnt++;
|
enterCnt++;
|
||||||
|
|
||||||
static params paramsTmp;
|
static paramsDht paramsTmp;
|
||||||
static params paramsHum;
|
static paramsDht paramsHum;
|
||||||
|
|
||||||
if (enterCnt == 0) {
|
if (enterCnt == 0) {
|
||||||
paramsTmp.type = type;
|
paramsTmp.type = type;
|
||||||
|
|||||||
13
src/main.cpp
13
src/main.cpp
@@ -26,6 +26,8 @@
|
|||||||
#include "items/vSensorDallas.h"
|
#include "items/vSensorDallas.h"
|
||||||
#include "items/vSensorDht.h"
|
#include "items/vSensorDht.h"
|
||||||
#include "items/vSensorUltrasonic.h"
|
#include "items/vSensorUltrasonic.h"
|
||||||
|
#include "items/vSensorBme280.h"
|
||||||
|
#include "items/vSensorBmp280.h"
|
||||||
|
|
||||||
void not_async_actions();
|
void not_async_actions();
|
||||||
|
|
||||||
@@ -50,7 +52,6 @@ void setup() {
|
|||||||
#endif
|
#endif
|
||||||
clockInit();
|
clockInit();
|
||||||
timeInit();
|
timeInit();
|
||||||
sensorsInit(); //Will be remooved
|
|
||||||
itemsListInit();
|
itemsListInit();
|
||||||
espInit();
|
espInit();
|
||||||
routerConnect();
|
routerConnect();
|
||||||
@@ -140,4 +141,14 @@ void loop() {
|
|||||||
mySensorDht->at(i).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