mirror of
https://github.com/IoTManagerProject/IoTManager.git
synced 2026-03-26 14:12:16 +03:00
uart
This commit is contained in:
13
.vscode/settings.json
vendored
Normal file
13
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"files.associations": {
|
||||
"array": "cpp",
|
||||
"deque": "cpp",
|
||||
"list": "cpp",
|
||||
"string": "cpp",
|
||||
"unordered_map": "cpp",
|
||||
"vector": "cpp",
|
||||
"string_view": "cpp",
|
||||
"initializer_list": "cpp",
|
||||
"ranges": "cpp"
|
||||
}
|
||||
}
|
||||
@@ -454,18 +454,16 @@
|
||||
"num": 34
|
||||
},
|
||||
{
|
||||
"name": "35. PWM ESP32",
|
||||
"name": "35. PWM ESP8266",
|
||||
"type": "Writing",
|
||||
"subtype": "Pwm32",
|
||||
"subtype": "Pwm8266",
|
||||
"id": "pwm",
|
||||
"widget": "range",
|
||||
"page": "Кнопки",
|
||||
"descr": "PWM",
|
||||
"int": 0,
|
||||
"pin": 2,
|
||||
"pin": 15,
|
||||
"freq": 5000,
|
||||
"ledChannel": 2,
|
||||
"PWM_resolution": 10,
|
||||
"val": 0,
|
||||
"apin": -1,
|
||||
"num": 35
|
||||
|
||||
@@ -22,18 +22,39 @@
|
||||
"after": "",
|
||||
"icon": ""
|
||||
},
|
||||
{
|
||||
"name": "anydataVlt",
|
||||
"label": "Вольты",
|
||||
"widget": "anydata",
|
||||
"after": "V",
|
||||
"icon": "speedometer"
|
||||
},
|
||||
{
|
||||
"name": "anydataAmp",
|
||||
"label": "Амперы",
|
||||
"widget": "anydata",
|
||||
"after": "Amp",
|
||||
"after": "A",
|
||||
"icon": "speedometer"
|
||||
},
|
||||
{
|
||||
"name": "anydataWt",
|
||||
"label": "Ватты",
|
||||
"widget": "anydata",
|
||||
"after": "Wt",
|
||||
"icon": "speedometer"
|
||||
},
|
||||
{
|
||||
"name": "anydataWth",
|
||||
"label": "Энергия",
|
||||
"widget": "anydata",
|
||||
"after": "Wt/hr",
|
||||
"icon": "speedometer"
|
||||
},
|
||||
{
|
||||
"name": "anydataHtz",
|
||||
"label": "Герцы",
|
||||
"widget": "anydata",
|
||||
"after": "Htz",
|
||||
"after": "Hz",
|
||||
"icon": "speedometer"
|
||||
},
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
},
|
||||
"projectProp": {
|
||||
"platformio": {
|
||||
"default_envs": "esp32_4mb",
|
||||
"default_envs": "esp8266_4mb",
|
||||
"data_dir": "data_svelte"
|
||||
}
|
||||
},
|
||||
@@ -117,6 +117,10 @@
|
||||
"path": "src\\modules\\sensors\\Sht30",
|
||||
"active": true
|
||||
},
|
||||
{
|
||||
"path": "src\\modules\\sensors\\SoftUart",
|
||||
"active": false
|
||||
},
|
||||
{
|
||||
"path": "src\\modules\\sensors\\Sonar",
|
||||
"active": true
|
||||
|
||||
@@ -41,7 +41,7 @@ build_src_filter =
|
||||
${env:esp32_4mb_fromitems.build_src_filter}
|
||||
|
||||
[platformio]
|
||||
default_envs = esp32_4mb
|
||||
default_envs = esp8266_4mb
|
||||
data_dir = data_svelte
|
||||
|
||||
[common_env_data]
|
||||
|
||||
@@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params);
|
||||
void* getAPI_IoTServo(String subtype, String params);
|
||||
void* getAPI_Mcp23017(String subtype, String params);
|
||||
void* getAPI_Mp3(String subtype, String params);
|
||||
void* getAPI_Pwm32(String subtype, String params);
|
||||
void* getAPI_Pwm8266(String subtype, String params);
|
||||
void* getAPI_TelegramLT(String subtype, String params);
|
||||
void* getAPI_Lcd2004(String subtype, String params);
|
||||
|
||||
@@ -50,7 +50,7 @@ if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mcp23017(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm32(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Pwm8266(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
|
||||
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
|
||||
return nullptr;
|
||||
|
||||
@@ -3,91 +3,22 @@
|
||||
#include "classes/IoTItem.h"
|
||||
|
||||
#include "PZEMSensor.h"
|
||||
#include "SoftUART.h"
|
||||
//#include "SoftUART.h"
|
||||
|
||||
#include <map>
|
||||
PZEMSensor* pzem;
|
||||
|
||||
// std::map<String, Adafruit_Pzem004*> bmes;
|
||||
//
|
||||
// class Pzem004t : public IoTItem {
|
||||
// private:
|
||||
// Adafruit_Pzem004* _bme;
|
||||
//
|
||||
// public:
|
||||
// Pzem004t(Adafruit_Pzem004* bme, String parameters) : IoTItem(parameters) {
|
||||
// _bme = bme;
|
||||
// }
|
||||
//
|
||||
// void doByInterval() {
|
||||
// value.valD = _bme->readTemperature();
|
||||
// if (value.valD < 145)
|
||||
// regEvent(value.valD, "Pzem004t");
|
||||
// else
|
||||
// SerialPrint("E", "Sensor Pzem004t", "Error");
|
||||
// }
|
||||
//
|
||||
// ~Pzem004t(){};
|
||||
// };
|
||||
//
|
||||
// class Pzem004h : public IoTItem {
|
||||
// private:
|
||||
// Adafruit_Pzem004* _bme;
|
||||
//
|
||||
// public:
|
||||
// Pzem004h(Adafruit_Pzem004* bme, String parameters) : IoTItem(parameters) {
|
||||
// _bme = bme;
|
||||
// }
|
||||
//
|
||||
// void doByInterval() {
|
||||
// value.valD = _bme->readHumidity();
|
||||
// if (value.valD < 100)
|
||||
// regEvent(value.valD, "Pzem004h");
|
||||
// else
|
||||
// SerialPrint("E", "Sensor Pzem004h", "Error");
|
||||
// }
|
||||
//
|
||||
// ~Pzem004h(){};
|
||||
// };
|
||||
//
|
||||
// class Pzem004p : public IoTItem {
|
||||
// private:
|
||||
// Adafruit_Pzem004* _bme;
|
||||
//
|
||||
// public:
|
||||
// Pzem004p(Adafruit_Pzem004* bme, String parameters) : IoTItem(parameters) {
|
||||
// _bme = bme;
|
||||
// }
|
||||
//
|
||||
// void doByInterval() {
|
||||
// value.valD = _bme->readPressure();
|
||||
// if (value.valD > 0) {
|
||||
// value.valD = value.valD / 1.333224 / 100;
|
||||
// regEvent(value.valD, "Pzem004p");
|
||||
// } else
|
||||
// SerialPrint("E", "Sensor Pzem004p", "Error");
|
||||
// }
|
||||
//
|
||||
// ~Pzem004p(){};
|
||||
// };
|
||||
//
|
||||
// void* getAPI_Pzem004(String subtype, String param) {
|
||||
// if (subtype == F("Pzem004t") || subtype == F("Pzem004h") || subtype == F("Pzem004p")) {
|
||||
// String addr;
|
||||
// jsonRead(param, "addr", addr);
|
||||
//
|
||||
// if (bmes.find(addr) == bmes.end()) {
|
||||
// bmes[addr] = new Adafruit_Pzem004();
|
||||
// bmes[addr]->begin(hexStringToUint8(addr));
|
||||
// }
|
||||
//
|
||||
// if (subtype == F("Pzem004t")) {
|
||||
// return new Pzem004t(bmes[addr], param);
|
||||
// } else if (subtype == F("Pzem004h")) {
|
||||
// return new Pzem004h(bmes[addr], param);
|
||||
// } else if (subtype == F("Pzem004p")) {
|
||||
// return new Pzem004p(bmes[addr], param);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return nullptr;
|
||||
// }
|
||||
class Pzem004v : public IoTItem {
|
||||
private:
|
||||
String addr;
|
||||
|
||||
public:
|
||||
Pzem004v(String parameters) : IoTItem(parameters) {
|
||||
addr = jsonReadStr(parameters, "addr");
|
||||
// pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
|
||||
}
|
||||
|
||||
~Pzem004v(){};
|
||||
};
|
||||
|
||||
void* getAPI_Pzem004(String subtype, String param) {
|
||||
}
|
||||
|
||||
@@ -4,11 +4,59 @@
|
||||
{
|
||||
"name": "PZEM 004t Напряжение",
|
||||
"type": "Reading",
|
||||
"subtype": "Bme280t",
|
||||
"id": "tmp3",
|
||||
"widget": "anydataTmp",
|
||||
"subtype": "Pzem004v",
|
||||
"id": "V",
|
||||
"widget": "anydataVlt",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Температура",
|
||||
"descr": "Напряжение",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "PZEM 004t Сила тока",
|
||||
"type": "Reading",
|
||||
"subtype": "Pzem004a",
|
||||
"id": "A",
|
||||
"widget": "anydataAmp",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Сила тока",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "PZEM 004t Мощность",
|
||||
"type": "Reading",
|
||||
"subtype": "Pzem004w",
|
||||
"id": "A",
|
||||
"widget": "anydataWt",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Мощность",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "PZEM 004t Энергия",
|
||||
"type": "Reading",
|
||||
"subtype": "Pzem004wh",
|
||||
"id": "Wh",
|
||||
"widget": "anydataWth",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Энергия",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
},
|
||||
{
|
||||
"name": "PZEM 004t Частота",
|
||||
"type": "Reading",
|
||||
"subtype": "Pzem004hz",
|
||||
"id": "Hz",
|
||||
"widget": "anydataHtz",
|
||||
"page": "Сенсоры",
|
||||
"descr": "Энергия",
|
||||
"int": 15,
|
||||
"addr": "0x77",
|
||||
"round": 1
|
||||
@@ -26,8 +74,8 @@
|
||||
"Pzem004v",
|
||||
"Pzem004a",
|
||||
"Pzem004w",
|
||||
"Pzem004hz",
|
||||
"Pzem004wh"
|
||||
"Pzem004wh",
|
||||
"Pzem004hz"
|
||||
],
|
||||
"title": "Счетчик электроэнергии PZEM 004t версии 3.0 (с модбасом)",
|
||||
"moduleDesc": "Считает потраченную электроэнергию, измеряет напряжение, частоту, силу тока и прочие параметры",
|
||||
|
||||
66
src/modules/sensors/SoftUart/SoftUart.cpp
Normal file
66
src/modules/sensors/SoftUart/SoftUart.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
#include "Global.h"
|
||||
#include "classes/IoTItem.h"
|
||||
#include <Arduino.h>
|
||||
//#include "SoftUART.h"
|
||||
|
||||
#ifdef ESP8266
|
||||
SoftwareSerial* myUART = nullptr;
|
||||
#else
|
||||
HardwareSerial* myUART = nullptr;
|
||||
#endif
|
||||
|
||||
class SoftUART : public IoTItem {
|
||||
private:
|
||||
int tx;
|
||||
int rx;
|
||||
|
||||
public:
|
||||
SoftUART(String parameters) : IoTItem(parameters) {
|
||||
tx = jsonReadInt(parameters, "tx");
|
||||
rx = jsonReadInt(parameters, "rx");
|
||||
speed = jsonReadInt(parameters, "speed");
|
||||
|
||||
if (!myUART) {
|
||||
#ifdef ESP8266
|
||||
myUART = new SoftwareSerial(tx, rx);
|
||||
myUART->begin(speed);
|
||||
#endif
|
||||
#ifdef ESP32
|
||||
myUART = new HardwareSerial(2);
|
||||
myUART->begin(speed, SERIAL_8N1, rx, tx);
|
||||
#endif
|
||||
}
|
||||
SerialPrint("i", F("UART"), F("UART Init"));
|
||||
}
|
||||
|
||||
void uartHandle() {
|
||||
if (myUART) {
|
||||
if (!jsonReadBool(configSetupJson, "uart")) {
|
||||
return;
|
||||
}
|
||||
static String incStr;
|
||||
if (myUART->available()) {
|
||||
char inc;
|
||||
inc = myUART->read();
|
||||
incStr += inc;
|
||||
if (inc == '\n') {
|
||||
parse(incStr);
|
||||
incStr = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void parse(String& incStr) {
|
||||
SerialPrint("I", "=>UART", incStr);
|
||||
}
|
||||
};
|
||||
|
||||
void* getAPI_SoftUART(String subtype, String param) {
|
||||
if (subtype == F("SoftUART")) {
|
||||
return new SoftUART(param);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
42
src/modules/sensors/SoftUart/modinfo.json
Normal file
42
src/modules/sensors/SoftUart/modinfo.json
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"menuSection": "Сенсоры",
|
||||
"configItem": [
|
||||
{
|
||||
"name": "UART",
|
||||
"type": "Reading",
|
||||
"subtype": "SoftUART",
|
||||
"id": "u",
|
||||
"tx": 15,
|
||||
"rx": 16,
|
||||
"speed": 9600
|
||||
}
|
||||
],
|
||||
"about": {
|
||||
"authorName": "Dmitry Borisenko",
|
||||
"authorContact": "https://t.me/Dmitry_Borisenko",
|
||||
"authorGit": "https://github.com/DmitryBorisenko33",
|
||||
"specialThanks": "Serghei Crasnicov @Serghei63",
|
||||
"moduleName": "Bme280",
|
||||
"moduleVersion": "1.0",
|
||||
"usedRam": 15,
|
||||
"subTypes": [
|
||||
"SoftUART"
|
||||
],
|
||||
"title": "Софтовый uart для esp8266 или harware uart для esp32",
|
||||
"moduleDesc": "Используется вместе с Pzem004t",
|
||||
"propInfo": {
|
||||
"tx": "TX пин",
|
||||
"rx": "RX пин",
|
||||
"speed": "Скорость UART"
|
||||
}
|
||||
},
|
||||
"defActive": false,
|
||||
"devices": {
|
||||
"esp32_4mb": [
|
||||
"plerup/espsoftwareserial"
|
||||
],
|
||||
"esp8266_4mb": [
|
||||
"plerup/espsoftwareserial"
|
||||
]
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user