mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
переписан полностью датчик bme и bmp
This commit is contained in:
@@ -4,7 +4,6 @@
|
||||
|
||||
extern void cmd_init();
|
||||
|
||||
extern void sensorsInit();
|
||||
|
||||
//extern void levelPr();
|
||||
//extern void ultrasonicCm();
|
||||
|
||||
@@ -47,8 +47,6 @@
|
||||
//================================================================================================================================================================
|
||||
enum TimerTask_t { WIFI_SCAN,
|
||||
WIFI_MQTT_CONNECTION_CHECK,
|
||||
SENSORS10SEC,
|
||||
SENSORS30SEC,
|
||||
TIME,
|
||||
TIME_SYNC,
|
||||
STATISTICS,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
//===================Libraries===================================================================================================================================================
|
||||
#include "Consts.h"
|
||||
#include <Adafruit_BME280.h>
|
||||
#include <Adafruit_BMP280.h>
|
||||
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "CTBot.h"
|
||||
#include <ArduinoJson.h>
|
||||
@@ -91,9 +91,7 @@ extern int logging_EnterCounter;
|
||||
extern int dht_EnterCounter;
|
||||
//=========================================
|
||||
|
||||
// Sensors
|
||||
extern String sensorReadingMap10sec;
|
||||
extern String sensorReadingMap30sec;
|
||||
|
||||
|
||||
extern String itemName;
|
||||
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;
|
||||
|
||||
struct params {
|
||||
struct paramsDht {
|
||||
String type;
|
||||
String key;
|
||||
unsigned long interval;
|
||||
@@ -21,18 +21,16 @@ struct params {
|
||||
|
||||
class SensorDht {
|
||||
public:
|
||||
SensorDht(const params& paramsTmp, const params& paramsHum);
|
||||
SensorDht(const paramsDht& paramsTmp, const paramsDht& paramsHum);
|
||||
~SensorDht();
|
||||
|
||||
void loop();
|
||||
void readTmpHum();
|
||||
|
||||
private:
|
||||
params _paramsTmp;
|
||||
params _paramsHum;
|
||||
paramsDht _paramsTmp;
|
||||
paramsDht _paramsHum;
|
||||
|
||||
unsigned int _interval;
|
||||
|
||||
unsigned long prevMillis;
|
||||
unsigned long difference;
|
||||
};
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
#pragma once
|
||||
#include "Global.h"
|
||||
#include <Arduino.h>
|
||||
#include "items/SensorConvertingClass.h"
|
||||
#include "GyverFilters.h"
|
||||
|
||||
class SensorUltrasonic;
|
||||
|
||||
typedef std::vector<SensorUltrasonic> MySensorUltrasonicVector;
|
||||
|
||||
class SensorUltrasonic : public SensorConvertingClass {
|
||||
class SensorUltrasonic {
|
||||
public:
|
||||
|
||||
SensorUltrasonic(String key, unsigned long interval, unsigned int trig, unsigned int echo, int map1, int map2, int map3, int map4, float c);
|
||||
|
||||
Reference in New Issue
Block a user