bme 280 support

This commit is contained in:
Dmitry Borisenko
2020-09-17 22:49:55 +03:00
parent 716dfd095d
commit 16b2498d6a
13 changed files with 139 additions and 74 deletions

View File

@@ -76,6 +76,9 @@ class LineParsing {
if (arg.indexOf("type[") != -1) {
_type = extractInner(arg);
}
if (arg.indexOf("addr[") != -1) {
_addr = extractInner(arg);
}
}
}
@@ -121,6 +124,10 @@ class LineParsing {
String gtype() {
return _type;
}
String gaddr() {
return _addr;
}
void clear() {
_key = "";
@@ -136,6 +143,7 @@ class LineParsing {
_state = "";
_db = "";
_type = "";
_addr = "";
}
String extractInnerDigit(String str) {

View File

@@ -30,4 +30,11 @@ extern void dallasReading();
extern void dhtTemp();
extern void dhtReadingTemp();
extern void dhtHum();
extern void dhtReadingHum();
extern void dhtReadingHum();
extern void bme280Temp();
extern void bme280ReadingTemp();
extern void bme280Hum();
extern void bme280ReadingHum();
extern void bme280Press();
extern void bme280ReadingPress();

View File

@@ -1,15 +1,21 @@
#pragma once
#include <Arduino.h>
#include "Class/LineParsing.h"
#include "items/SensorConvertingClass.h"
#include "Global.h"
#include "items/SensorConvertingClass.h"
class SensorAnalogClass : public SensorConvertingClass {
public:
SensorAnalogClass() : SensorConvertingClass(){};
void SensorAnalogInit() {
jsonWriteStr(configOptionJson, _key + "_pin", _pin);
jsonWriteStr(configOptionJson, _key + "_map", _map);
jsonWriteStr(configOptionJson, _key + "_с", _c);
}
int SensorAnalogRead(String key, String pin) {
int pinInt = pin.toInt();
int value;

View File

@@ -1,45 +1,53 @@
//#pragma once
//#include <Arduino.h>
//#include "Class/LineParsing.h"
//#include "Global.h"
//#include "items/SensorConvertingClass.h"
//
//class SensorBme280Class : public SensorConvertingClass {
// public:
// SensorBme280Class() : SensorConvertingClass(){};
//
// void SensorBme280Init() {
// oneWire = new OneWire((uint8_t)_pin.toInt());
// sensors.setOneWire(oneWire);
// sensors.begin();
// sensors.setResolution(48);
//
// sensorReadingMap += _key + ",";
// //Bme280EnterCounter++;
//
// //jsonWriteInt(configOptionJson, _key + "_num", Bme280EnterCounter);
// jsonWriteStr(configOptionJson, _key + "_map", _map);
// jsonWriteStr(configOptionJson, _key + "_с", _c);
// }
//
// void SensorBme280Read(String key) {
// float value;
// byte num = sensors.getDS18Count();
// sensors.requestTemperatures();
//
// int cnt = jsonReadInt(configOptionJson, key + "_num");
//
// for (byte i = 0; i < num; i++) {
// if (i == cnt) {
// value = sensors.getTempCByIndex(i);
// //value = this->mapping(key, value);
// float valueFl = this->correction(key, value);
// eventGen(key, "");
// jsonWriteStr(configLiveJson, key, String(valueFl));
// MqttClient::publishStatus(key, String(valueFl));
// Serial.println("I sensor '" + key + "' data: " + String(valueFl));
// }
// }
// }
//};
//extern SensorBme280Class mySensorBme280;
#pragma once
#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);
}
void SensorBme280ReadTmp(String key) {
float value;
value = bme.readTemperature();
float valueFl = this->correction(key, value);
eventGen(key, "");
jsonWriteStr(configLiveJson, key, String(valueFl));
MqttClient::publishStatus(key, String(valueFl));
Serial.println("I sensor '" + key + "' data: " + String(valueFl));
}
void SensorBme280ReadHum(String key) {
float value;
value = bme.readHumidity();
float valueFl = this->correction(key, value);
eventGen(key, "");
jsonWriteStr(configLiveJson, key, String(valueFl));
MqttClient::publishStatus(key, String(valueFl));
Serial.println("I sensor '" + key + "' data: " + String(valueFl));
}
void SensorBme280ReadPress(String key) {
float value;
value = bme.readPressure();
float valueFl = this->correction(key, value);
eventGen(key, "");
jsonWriteStr(configLiveJson, key, String(valueFl));
MqttClient::publishStatus(key, String(valueFl));
Serial.println("I sensor '" + key + "' data: " + String(valueFl));
}
};
extern SensorBme280Class mySensorBme280;

View File

@@ -4,6 +4,7 @@
#include "Class/LineParsing.h"
#include "Global.h"
#include "items/SensorConvertingClass.h"
DHTesp dht;
class SensorDhtClass : public SensorConvertingClass {
public: