This commit is contained in:
Dmitry Borisenko
2022-09-26 21:56:54 +02:00
parent c75d6dd66d
commit c091f1b4cc
10 changed files with 226 additions and 103 deletions

13
.vscode/settings.json vendored Normal file
View 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"
}
}

View File

@@ -454,18 +454,16 @@
"num": 34 "num": 34
}, },
{ {
"name": "35. PWM ESP32", "name": "35. PWM ESP8266",
"type": "Writing", "type": "Writing",
"subtype": "Pwm32", "subtype": "Pwm8266",
"id": "pwm", "id": "pwm",
"widget": "range", "widget": "range",
"page": "Кнопки", "page": "Кнопки",
"descr": "PWM", "descr": "PWM",
"int": 0, "int": 0,
"pin": 2, "pin": 15,
"freq": 5000, "freq": 5000,
"ledChannel": 2,
"PWM_resolution": 10,
"val": 0, "val": 0,
"apin": -1, "apin": -1,
"num": 35 "num": 35

View File

@@ -22,18 +22,39 @@
"after": "", "after": "",
"icon": "" "icon": ""
}, },
{
"name": "anydataVlt",
"label": "Вольты",
"widget": "anydata",
"after": "V",
"icon": "speedometer"
},
{ {
"name": "anydataAmp", "name": "anydataAmp",
"label": "Амперы", "label": "Амперы",
"widget": "anydata", "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" "icon": "speedometer"
}, },
{ {
"name": "anydataHtz", "name": "anydataHtz",
"label": "Герцы", "label": "Герцы",
"widget": "anydata", "widget": "anydata",
"after": "Htz", "after": "Hz",
"icon": "speedometer" "icon": "speedometer"
}, },
{ {

View File

@@ -21,7 +21,7 @@
}, },
"projectProp": { "projectProp": {
"platformio": { "platformio": {
"default_envs": "esp32_4mb", "default_envs": "esp8266_4mb",
"data_dir": "data_svelte" "data_dir": "data_svelte"
} }
}, },
@@ -117,6 +117,10 @@
"path": "src\\modules\\sensors\\Sht30", "path": "src\\modules\\sensors\\Sht30",
"active": true "active": true
}, },
{
"path": "src\\modules\\sensors\\SoftUart",
"active": false
},
{ {
"path": "src\\modules\\sensors\\Sonar", "path": "src\\modules\\sensors\\Sonar",
"active": true "active": true

View File

@@ -41,7 +41,7 @@ build_src_filter =
${env:esp32_4mb_fromitems.build_src_filter} ${env:esp32_4mb_fromitems.build_src_filter}
[platformio] [platformio]
default_envs = esp32_4mb default_envs = esp8266_4mb
data_dir = data_svelte data_dir = data_svelte
[common_env_data] [common_env_data]

View File

@@ -22,7 +22,7 @@ void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params); void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mcp23017(String subtype, String params); void* getAPI_Mcp23017(String subtype, String params);
void* getAPI_Mp3(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_TelegramLT(String subtype, String params);
void* getAPI_Lcd2004(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_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mcp23017(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_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_TelegramLT(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI; if ((tmpAPI = getAPI_Lcd2004(subtype, params)) != nullptr) return tmpAPI;
return nullptr; return nullptr;

View File

@@ -3,91 +3,22 @@
#include "classes/IoTItem.h" #include "classes/IoTItem.h"
#include "PZEMSensor.h" #include "PZEMSensor.h"
#include "SoftUART.h" //#include "SoftUART.h"
#include <map> PZEMSensor* pzem;
// std::map<String, Adafruit_Pzem004*> bmes; class Pzem004v : public IoTItem {
// private:
// class Pzem004t : public IoTItem { String addr;
// private:
// Adafruit_Pzem004* _bme; public:
// Pzem004v(String parameters) : IoTItem(parameters) {
// public: addr = jsonReadStr(parameters, "addr");
// Pzem004t(Adafruit_Pzem004* bme, String parameters) : IoTItem(parameters) { // pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
// _bme = bme; }
// }
// ~Pzem004v(){};
// void doByInterval() { };
// value.valD = _bme->readTemperature();
// if (value.valD < 145) void* getAPI_Pzem004(String subtype, String param) {
// 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;
// }

View File

@@ -4,11 +4,59 @@
{ {
"name": "PZEM 004t Напряжение", "name": "PZEM 004t Напряжение",
"type": "Reading", "type": "Reading",
"subtype": "Bme280t", "subtype": "Pzem004v",
"id": "tmp3", "id": "V",
"widget": "anydataTmp", "widget": "anydataVlt",
"page": "Сенсоры", "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, "int": 15,
"addr": "0x77", "addr": "0x77",
"round": 1 "round": 1
@@ -26,8 +74,8 @@
"Pzem004v", "Pzem004v",
"Pzem004a", "Pzem004a",
"Pzem004w", "Pzem004w",
"Pzem004hz", "Pzem004wh",
"Pzem004wh" "Pzem004hz"
], ],
"title": "Счетчик электроэнергии PZEM 004t версии 3.0 (с модбасом)", "title": "Счетчик электроэнергии PZEM 004t версии 3.0 (с модбасом)",
"moduleDesc": "Считает потраченную электроэнергию, измеряет напряжение, частоту, силу тока и прочие параметры", "moduleDesc": "Считает потраченную электроэнергию, измеряет напряжение, частоту, силу тока и прочие параметры",

View 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;
}
}

View 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"
]
}
}