Merge pull request #242 from biveraxe/ver4dev

Добавляем модули давления, веса и качества воздуха
This commit is contained in:
2022-11-22 18:36:32 +03:00
committed by GitHub
6 changed files with 386 additions and 0 deletions

View File

@@ -0,0 +1,48 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include "HX710B.h"
class HX710b : public IoTItem {
private:
HX710B pressure_sensor;
public:
HX710b(String parameters) : IoTItem(parameters) {
int data, clock;
jsonRead(parameters, "data", data);
jsonRead(parameters, "clock", clock);
pressure_sensor.begin(data, clock);
pressure_sensor.tare();
}
void doByInterval() {
if (!pressure_sensor.is_ready()) return;
value.valD = pressure_sensor.mmHg();
regEvent(value.valD, "Hx710");
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (command == "tare") {
pressure_sensor.tare();
} else if (command == "read") {
value.valD = pressure_sensor.read();
return value;
}
return {};
}
~HX710b() {};
};
void* getAPI_Hx710(String subtype, String param) {
if (subtype == F("Hx710")) {
return new HX710b(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,58 @@
{
"menuSection": "Сенсоры",
"configItem": [{
"name": "HX710 Cенсор давления",
"type": "Reading",
"subtype": "Hx710",
"id": "hxp",
"widget": "anydataDef",
"page": "Давление",
"descr": "HX press",
"int": 15,
"plus": 0,
"multiply": 1,
"round": 1,
"data": 14,
"clock": 15
}],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "",
"moduleName": "Hx710",
"moduleVersion": "1.0",
"usedRam": {
"esp32_4mb": 15,
"esp8266_4mb": 15
},
"title": "HX710 Cенсор давления",
"moduleDesc": "Позволяет получить давление с датчика Hx710",
"propInfo": {
"clock": "GPIO шины данных",
"data": "GPIO шины данных",
"int": "Количество секунд между опросами датчика."
},
"retInfo": "Содержит mmHg значение датчика, необходима калибровка",
"funcInfo": [
{
"name": "read",
"descr": "Прочитать текущее значение. Полезно использовать при Int=0 и считывать RAW-data по событию.",
"params": []
}
]
},
"defActive": false,
"usedLibs": {
"esp32_4mb": [
"https://github.com/kurimawxx00/hx710B_pressure_sensor"
],
"esp8266_4mb": [
"https://github.com/kurimawxx00/hx710B_pressure_sensor"
]
}
}

View File

@@ -0,0 +1,56 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include <GyverHX711.h>
class GyverHX711g : public IoTItem {
private:
GyverHX711* _thermocouple = nullptr;
public:
GyverHX711g(String parameters) : IoTItem(parameters) {
int data, clock, chan;
jsonRead(parameters, "data", data);
jsonRead(parameters, "clock", clock);
jsonRead(parameters, "chan", chan);
_thermocouple = new GyverHX711(data, clock, chan);
_thermocouple->tare(); // калибровка нуля
}
void doByInterval() {
if (!_thermocouple->available()) return;
value.valD = _thermocouple->read();
regEvent(value.valD, "Hx711");
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (command == "tare") {
_thermocouple->tare();
} else if (command == "sleepMode") {
if (param.size() == 1) {
_thermocouple->sleepMode(param[0].valD);
}
} else if (command == "read") {
value.valD = _thermocouple->read();
regEvent(value.valD, "Hx711");
return value;
}
return {};
}
~GyverHX711g() {
if (_thermocouple) delete _thermocouple;
};
};
void* getAPI_Hx711(String subtype, String param) {
if (subtype == F("Hx711")) {
return new GyverHX711g(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,71 @@
{
"menuSection": "Сенсоры",
"configItem": [{
"name": "HX711 Cенсор весов",
"type": "Reading",
"subtype": "Hx711",
"id": "hx",
"widget": "anydataDef",
"page": "Весы",
"descr": "HX вес",
"int": 15,
"map": "1024,1024,1,100",
"plus": 0,
"multiply": 1,
"round": 1,
"data": 3,
"clock": 2,
"chan": 2
}],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "",
"moduleName": "Hx711",
"moduleVersion": "1.0",
"usedRam": {
"esp32_4mb": 15,
"esp8266_4mb": 15
},
"title": "HX711 Cенсор весов",
"moduleDesc": "Позволяет получить вес в килограммах с датчика Hx711",
"propInfo": {
"clock": "GPIO шины данных",
"data": "GPIO шины данных",
"chan": "Канал и усиление: =0 (HX_GAIN128_A) - канал А усиление 128, =1 (HX_GAIN32_B) - канал B усиление 32, =2 (HX_GAIN64_A) - канал А усиление 64",
"int": "Количество секунд между опросами датчика."
},
"retInfo": "Содержит RAW значение датчика, необходима калибровка",
"funcInfo": [
{
"name": "tare",
"descr": "Авто установка нуля",
"params": []
},
{
"name": "sleepMode",
"descr": "Перевести в режим сна",
"params": ["=1 режим сна, =0 проснуться"]
},
{
"name": "read",
"descr": "Прочитать текущее значение. Полезно использовать при Int=0 и считывать вес по событию.",
"params": []
}
]
},
"defActive": false,
"usedLibs": {
"esp32_4mb": [
"GyverHX711@1.2"
],
"esp8266_4mb": [
"GyverHX711@1.2"
]
}
}

View File

@@ -0,0 +1,89 @@
#include "Global.h"
#include "classes/IoTItem.h"
extern IoTGpio IoTgpio;
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
SGP30* mySensor = nullptr; //create an object of the SGP30 class
class Sgp30t : public IoTItem {
public:
Sgp30t(String parameters): IoTItem(parameters) {
if (!mySensor) mySensor = new SGP30();
mySensor->begin();
Wire.begin();
//Initialize sensor
if (mySensor->begin() == false) {
Serial.println("No SGP30 Detected. Check connections.");
//while (1);
}
//Initializes sensor for air quality readings
//measureAirQuality should be called in one second increments after a call to initAirQuality
mySensor->initAirQuality();
}
void doByInterval() {
mySensor->measureAirQuality();
value.valD = mySensor->CO2;
if (value.valD > -46.85F) regEvent(value.valD, "Sgp30t");
else SerialPrint("E", "Sensor Sgp30t", "Error");
}
~Sgp30t() {};
};
class Sgp30e : public IoTItem {
public:
Sgp30e(String parameters): IoTItem(parameters) {
if (!mySensor) mySensor = new SGP30();
mySensor->begin();
Wire.begin();
//Initialize sensor
if (mySensor->begin() == false) {
Serial.println("No SGP30 Detected. Check connections.");
while (1);
}
//Initializes sensor for air quality readings
//measureAirQuality should be called in one second increments after a call to initAirQuality
mySensor->initAirQuality();
}
void doByInterval() {
mySensor->measureAirQuality();
value.valD = mySensor->TVOC;
if (value.valD != -6) regEvent(value.valD, "Sgp30e");
else SerialPrint("E", "Sensor Sgp30e", "Error");
}
~Sgp30e() {};
};
void* getAPI_Sgp30(String subtype, String param) {
if (subtype == F("Sgp30t")) {
// mySensor.begin() ;
// mySensor.initAirQuality();
return new Sgp30t(param);
} else if (subtype == F("Sgp30e")) {
// mySensor.begin() ;
// mySensor.initAirQuality();
return new Sgp30e(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,64 @@
{
"menuSection": "Сенсоры",
"configItem": [
{
"global": 0,
"name": "SGP30 Cенсор качества воздуха",
"num": 3,
"type": "Reading",
"subtype": "Sgp30t",
"id": "sgp30t",
"widget": "anydatappm",
"page": "Сенсоры",
"descr": "TVOC",
"int": 30,
"round": 1
},
{
"global": 0,
"name": "SGP30 Cенсор газа",
"num": 4,
"type": "Reading",
"subtype": "Sgp30e",
"id": "sgp30e",
"widget": "anydatappm",
"page": "Сенсоры",
"descr": "eCO2",
"int": 30,
"round": 1
}
],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "Ilya Belyakov",
"moduleName": "Sgp30",
"moduleVersion": "1.0",
"usedRam": 15,
"subTypes": [
"Sgp30t",
"Sgp30e"
],
"title": "Датчик качества воздуха SGP30",
"moduleDesc": "Измеряет параметвы воздуха.",
"propInfo": {
"int": "Количество секунд между опросами датчика."
}
},
"defActive": false,
"usedLibs": {
"esp32_4mb": [
"sparkfun/SparkFun SGP30 Arduino Library@^1.0.5"
],
"esp8266_4mb": [
"sparkfun/SparkFun SGP30 Arduino Library@^1.0.5"
],
"esp8266_1mb": [
"sparkfun/SparkFun SGP30 Arduino Library@^1.0.5"
],
"esp8266_1mb_ota": [
"sparkfun/SparkFun SGP30 Arduino Library@^1.0.5"
]
}
}