mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 22:22:16 +03:00
Merge pull request #99 from DmitryBorisenko33/ver3
добавил AHTX0 HDC1080
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Arduino.h>
|
||||
float yourSensorReading(String type);
|
||||
float yourSensorReading(String type, String addr);
|
||||
|
||||
void HDC1080_init(String &addr);
|
||||
void AHTX0_init();
|
||||
|
||||
@@ -41,6 +41,8 @@ lib_deps =
|
||||
adafruit/Adafruit CCS811 Library
|
||||
milesburton/DallasTemperature
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
ClosedCube HDC1080
|
||||
Adafruit AHTX0
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -65,6 +67,8 @@ lib_deps =
|
||||
adafruit/Adafruit CCS811 Library
|
||||
milesburton/DallasTemperature
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
ClosedCube HDC1080
|
||||
Adafruit AHTX0
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -82,7 +86,6 @@ lib_deps =
|
||||
ESPAsyncUDP
|
||||
CTBot @2.1.6
|
||||
MySensors @2.3.2
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
monitor_filters = esp8266_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
@@ -108,6 +111,8 @@ lib_deps =
|
||||
adafruit/Adafruit CCS811 Library
|
||||
milesburton/DallasTemperature
|
||||
robtillaart/SHT2x@^0.1.1
|
||||
ClosedCube HDC1080
|
||||
Adafruit AHTX0
|
||||
monitor_filters = esp32_exception_decoder
|
||||
upload_speed = 921600
|
||||
monitor_speed = 115200
|
||||
|
||||
@@ -1,23 +1,63 @@
|
||||
#include "YourSensor.h"
|
||||
|
||||
float yourSensorReading(String type) {
|
||||
#include "Utils/StringUtils.h"
|
||||
|
||||
//подключаем необходимые файлы библиотеки
|
||||
#include <Adafruit_AHTX0.h>
|
||||
|
||||
#include "ClosedCube_HDC1080.h"
|
||||
|
||||
//создаем объект HDC1080
|
||||
ClosedCube_HDC1080 hdc1080;
|
||||
|
||||
//создаем объект AHTX0
|
||||
Adafruit_AHTX0 aht;
|
||||
Adafruit_Sensor *aht_humidity, *aht_temp;
|
||||
sensors_event_t tmpEvent_t;
|
||||
|
||||
float yourSensorReading(String type, String addr) {
|
||||
float value;
|
||||
if (type == "type1") { // type1 - замените на название вашего датчика, потом это же название указывайте в type[], в вебе
|
||||
//сюда вставляем процедуру чтения одного датчика
|
||||
static int a;
|
||||
a++;
|
||||
value = a;
|
||||
} else if (type == "type2") {
|
||||
//сюда вставляем процедуру чтения другого датчика
|
||||
static int b;
|
||||
b--;
|
||||
value = b;
|
||||
} else if (type == "type3") {
|
||||
//сюда третьего и так далее, создавайте сколько угодно else if....
|
||||
//если у одного датчика несколько параметров то под каждый из них делайте свой else if и свое имя type
|
||||
static int c;
|
||||
c++;
|
||||
value = c * 10;
|
||||
//========================================================HDC1080================================================================
|
||||
if (type == "HDC1080_temp") {
|
||||
HDC1080_init(addr);
|
||||
value = hdc1080.readTemperature();
|
||||
} else if (type == "HDC1080_hum") {
|
||||
HDC1080_init(addr);
|
||||
value = hdc1080.readHumidity();
|
||||
}
|
||||
//==========================================================AHTX0=================================================================
|
||||
if (type == "AHTX0_temp") {
|
||||
AHTX0_init();
|
||||
aht_temp->getEvent(&tmpEvent_t);
|
||||
value = tmpEvent_t.temperature;
|
||||
} else if (type == "typeAHTX0_hum") {
|
||||
AHTX0_init();
|
||||
aht_humidity->getEvent(&tmpEvent_t);
|
||||
value = tmpEvent_t.relative_humidity;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
void HDC1080_init(String &addr) {
|
||||
static bool HDC1080_flag = true;
|
||||
if (HDC1080_flag) {
|
||||
hdc1080.begin(hexStringToUint8(addr));
|
||||
HDC1080_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
void AHTX0_init() {
|
||||
static bool AHTX0_flag = true;
|
||||
if (AHTX0_flag) {
|
||||
if (!aht.begin()) {
|
||||
Serial.println("Failed to find AHT10/AHT20 chip");
|
||||
// return -127;
|
||||
}
|
||||
aht_temp = aht.getTemperatureSensor();
|
||||
aht_temp->printSensorDetails();
|
||||
|
||||
aht_humidity = aht.getHumiditySensor();
|
||||
aht_humidity->printSensorDetails();
|
||||
AHTX0_flag = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void SensorAny::loop() {
|
||||
}
|
||||
|
||||
void SensorAny::read() {
|
||||
float value = yourSensorReading(_type);
|
||||
float value = yourSensorReading(_type, _addr);
|
||||
|
||||
value = value * _c;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user