добавление сброса и установки адресов pzem из прошивки

This commit is contained in:
Dmitry Borisenko
2022-12-11 23:17:41 +01:00
parent dbee4f48f0
commit cdcebc4736
4 changed files with 128 additions and 53 deletions

View File

@@ -61,7 +61,8 @@
"int": 1, "int": 1,
"logid": "t", "logid": "t",
"points": 365, "points": 365,
"column": 0 "telegram": 0,
"test": 0
}, },
{ {
"global": 0, "global": 0,
@@ -435,7 +436,23 @@
}, },
{ {
"global": 0, "global": 0,
"name": "30. Sht20 Температура", "name": "30. PZEM настройка",
"type": "Reading",
"subtype": "Pzem004smd",
"id": "set",
"widget": "nil",
"page": "",
"descr": "",
"int": 15,
"addr": "0xF8",
"changeaddr": 0,
"setaddr": "0x01",
"reset": 0,
"num": 30
},
{
"global": 0,
"name": "31. Sht20 Температура",
"type": "Reading", "type": "Reading",
"subtype": "Sht20t", "subtype": "Sht20t",
"id": "tmp2", "id": "tmp2",
@@ -444,11 +461,11 @@
"descr": "Температура", "descr": "Температура",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 30 "num": 31
}, },
{ {
"global": 0, "global": 0,
"name": "31. Sht20 Влажность", "name": "32. Sht20 Влажность",
"type": "Reading", "type": "Reading",
"subtype": "Sht20h", "subtype": "Sht20h",
"id": "Hum2", "id": "Hum2",
@@ -457,11 +474,11 @@
"descr": "Влажность", "descr": "Влажность",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 31 "num": 32
}, },
{ {
"global": 0, "global": 0,
"name": "32. Sht30 Температура", "name": "33. Sht30 Температура",
"type": "Reading", "type": "Reading",
"subtype": "Sht30t", "subtype": "Sht30t",
"id": "tmp30", "id": "tmp30",
@@ -470,11 +487,11 @@
"descr": "SHT30 Температура", "descr": "SHT30 Температура",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 32 "num": 33
}, },
{ {
"global": 0, "global": 0,
"name": "33. Sht30 Влажность", "name": "34. Sht30 Влажность",
"type": "Reading", "type": "Reading",
"subtype": "Sht30h", "subtype": "Sht30h",
"id": "Hum30", "id": "Hum30",
@@ -483,12 +500,12 @@
"descr": "SHT30 Влажность", "descr": "SHT30 Влажность",
"int": 15, "int": 15,
"round": 1, "round": 1,
"num": 33 "num": 34
}, },
{ {
"global": 0, "global": 0,
"name": "34. HC-SR04 Ультразвуковой дальномер", "name": "35. HC-SR04 Ультразвуковой дальномер",
"num": 34, "num": 35,
"type": "Reading", "type": "Reading",
"subtype": "Sonar", "subtype": "Sonar",
"id": "sonar", "id": "sonar",
@@ -500,7 +517,7 @@
"int": 5 "int": 5
}, },
{ {
"name": "35. UART", "name": "36. UART",
"type": "Reading", "type": "Reading",
"subtype": "UART", "subtype": "UART",
"page": "", "page": "",
@@ -512,14 +529,14 @@
"line": 2, "line": 2,
"speed": 9600, "speed": 9600,
"eventFormat": 0, "eventFormat": 0,
"num": 35 "num": 36
}, },
{ {
"header": "Исполнительные устройства" "header": "Исполнительные устройства"
}, },
{ {
"global": 0, "global": 0,
"name": "36. Кнопка подключенная к пину", "name": "37. Кнопка подключенная к пину",
"type": "Writing", "type": "Writing",
"subtype": "ButtonIn", "subtype": "ButtonIn",
"id": "btn", "id": "btn",
@@ -533,11 +550,11 @@
"pinMode": "INPUT", "pinMode": "INPUT",
"debounceDelay": 50, "debounceDelay": 50,
"fixState": 0, "fixState": 0,
"num": 36 "num": 37
}, },
{ {
"global": 0, "global": 0,
"name": "37. Управление пином", "name": "38. Управление пином",
"type": "Writing", "type": "Writing",
"subtype": "ButtonOut", "subtype": "ButtonOut",
"needSave": 0, "needSave": 0,
@@ -548,11 +565,11 @@
"int": 0, "int": 0,
"inv": 0, "inv": 0,
"pin": 2, "pin": 2,
"num": 37 "num": 38
}, },
{ {
"global": 0, "global": 0,
"name": "38. Сервопривод", "name": "39. Сервопривод",
"type": "Writing", "type": "Writing",
"subtype": "IoTServo", "subtype": "IoTServo",
"id": "servo", "id": "servo",
@@ -563,11 +580,11 @@
"pin": 12, "pin": 12,
"apin": -1, "apin": -1,
"amap": "0, 4096, 0, 180", "amap": "0, 4096, 0, 180",
"num": 38 "num": 39
}, },
{ {
"global": 0, "global": 0,
"name": "39. Расширитель портов Mcp23017", "name": "40. Расширитель портов Mcp23017",
"type": "Reading", "type": "Reading",
"subtype": "Mcp23017", "subtype": "Mcp23017",
"id": "Mcp", "id": "Mcp",
@@ -577,11 +594,11 @@
"int": "0", "int": "0",
"addr": "0x20", "addr": "0x20",
"index": 1, "index": 1,
"num": 39 "num": 40
}, },
{ {
"global": 0, "global": 0,
"name": "40. MP3 плеер", "name": "41. MP3 плеер",
"type": "Reading", "type": "Reading",
"subtype": "Mp3", "subtype": "Mp3",
"id": "mp3", "id": "mp3",
@@ -591,11 +608,11 @@
"int": 1, "int": 1,
"pins": "14,12", "pins": "14,12",
"volume": 20, "volume": 20,
"num": 40 "num": 41
}, },
{ {
"global": 0, "global": 0,
"name": "41. Сенсорная кнопка", "name": "42. Сенсорная кнопка",
"type": "Writing", "type": "Writing",
"subtype": "Multitouch", "subtype": "Multitouch",
"id": "impulse", "id": "impulse",
@@ -609,11 +626,11 @@
"pinMode": "INPUT", "pinMode": "INPUT",
"debounceDelay": 50, "debounceDelay": 50,
"PWMDelay": 500, "PWMDelay": 500,
"num": 41 "num": 42
}, },
{ {
"global": 0, "global": 0,
"name": "42. Расширитель портов Pcf8574", "name": "43. Расширитель портов Pcf8574",
"type": "Reading", "type": "Reading",
"subtype": "Pcf8574", "subtype": "Pcf8574",
"id": "Pcf", "id": "Pcf",
@@ -623,11 +640,11 @@
"int": "0", "int": "0",
"addr": "0x20", "addr": "0x20",
"index": 1, "index": 1,
"num": 42 "num": 43
}, },
{ {
"global": 0, "global": 0,
"name": "43. PWM ESP8266", "name": "44. PWM ESP8266",
"type": "Writing", "type": "Writing",
"subtype": "Pwm8266", "subtype": "Pwm8266",
"id": "pwm", "id": "pwm",
@@ -639,11 +656,11 @@
"freq": 5000, "freq": 5000,
"val": 0, "val": 0,
"apin": -1, "apin": -1,
"num": 43 "num": 44
}, },
{ {
"global": 0, "global": 0,
"name": "44. Телеграм-Лайт", "name": "45. Телеграм-Лайт",
"type": "Writing", "type": "Writing",
"subtype": "TelegramLT", "subtype": "TelegramLT",
"id": "tg", "id": "tg",
@@ -652,14 +669,14 @@
"descr": "", "descr": "",
"token": "", "token": "",
"chatID": "", "chatID": "",
"num": 44 "num": 45
}, },
{ {
"header": "Экраны" "header": "Экраны"
}, },
{ {
"global": 0, "global": 0,
"name": "45. LCD экран 2004", "name": "46. LCD экран 2004",
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -671,10 +688,10 @@
"size": "20,4", "size": "20,4",
"coord": "0,0", "coord": "0,0",
"id2show": "id датчика", "id2show": "id датчика",
"num": 45 "num": 46
}, },
{ {
"name": "46. LCD экран 1602", "name": "47. LCD экран 1602",
"type": "Reading", "type": "Reading",
"subtype": "Lcd2004", "subtype": "Lcd2004",
"id": "Lcd", "id": "Lcd",
@@ -686,6 +703,6 @@
"size": "16,2", "size": "16,2",
"coord": "0,0", "coord": "0,0",
"id2show": "id датчика", "id2show": "id датчика",
"num": 46 "num": 47
} }
] ]

View File

@@ -196,7 +196,7 @@
}, },
{ {
"path": "src/modules/exec/MySensors", "path": "src/modules/exec/MySensors",
"active": true "active": false
}, },
{ {
"path": "src/modules/exec/Pcf8574", "path": "src/modules/exec/Pcf8574",

View File

@@ -181,20 +181,61 @@ class Pzem004pf : public IoTItem {
~Pzem004pf(){}; ~Pzem004pf(){};
}; };
void* getAPI_Pzem004(String subtype, String param) { class Pzem004cmd : public IoTItem {
if (subtype == F("Pzem004v")) { private:
return new Pzem004v(param); String addr;
} else if (subtype == F("Pzem004a")) { int changeaddr;
return new Pzem004a(param); String setaddr;
} else if (subtype == F("Pzem004w")) { int reset;
return new Pzem004w(param); PZEMSensor* pzem;
} else if (subtype == F("Pzem004wh")) {
return new Pzem004wh(param); public:
} else if (subtype == F("Pzem004hz")) { Pzem004cmd(String parameters) : IoTItem(parameters) {
return new Pzem004hz(param); jsonRead(parameters, F("addr"), addr);
} else if (subtype == F("Pzem004pf")) { jsonRead(parameters, F("changeaddr"), changeaddr);
return new Pzem004pf(param); jsonRead(parameters, F("setaddr"), setaddr);
} else { jsonRead(parameters, F("reset"), reset);
return nullptr;
if (myUART) {
pzem = new PZEMSensor(myUART, hexStringToUint8(addr));
if (changeaddr == 1) {
if (pzem->setAddress(hexStringToUint8(setaddr))) {
SerialPrint("i", "Pzem", "address set: " + setaddr);
} else {
SerialPrint("i", "Pzem", "set adress error");
}
}
if (reset == 1) {
if (pzem->reset()) {
SerialPrint("i", "Pzem", "reset done");
} else {
SerialPrint("i", "Pzem", "reset error");
}
}
}
}
void doByInterval() {
if (pzem) {
}
}
~Pzem004cmd(){};
void* getAPI_Pzem004(String subtype, String param) {
if (subtype == F("Pzem004v")) {
return new Pzem004v(param);
} else if (subtype == F("Pzem004a")) {
return new Pzem004a(param);
} else if (subtype == F("Pzem004w")) {
return new Pzem004w(param);
} else if (subtype == F("Pzem004wh")) {
return new Pzem004wh(param);
} else if (subtype == F("Pzem004hz")) {
return new Pzem004hz(param);
} else if (subtype == F("Pzem004pf")) {
return new Pzem004pf(param);
} else {
return nullptr;
}
} }
}

View File

@@ -78,6 +78,21 @@
"int": 15, "int": 15,
"addr": "0xF8", "addr": "0xF8",
"round": 1 "round": 1
},
{
"global": 0,
"name": "PZEM настройка",
"type": "Reading",
"subtype": "Pzem004smd",
"id": "set",
"widget": "nil",
"page": "",
"descr": "",
"int": 15,
"addr": "0xF8",
"changeaddr": 0,
"setaddr": "0x01",
"reset": 0
} }
], ],
"about": { "about": {
@@ -103,7 +118,9 @@
"moduleDesc": "Считает потраченную электроэнергию, измеряет напряжение, частоту, силу тока и прочие параметры", "moduleDesc": "Считает потраченную электроэнергию, измеряет напряжение, частоту, силу тока и прочие параметры",
"propInfo": { "propInfo": {
"addr": "Адрес modbus", "addr": "Адрес modbus",
"int": "Количество секунд между опросами датчика. Желателно устанавливать разные интервалы для параметров что бы опросы происходили в разное время." "int": "Количество секунд между опросами датчика. Желателно устанавливать разные интервалы для параметров что бы опросы происходили в разное время.",
"changeaddr": "Поставьте этот параметр равным 1 и перезагрузите esp - будет установлен адрес указанный в setaddr. Смотрите в логе результат: [i] Pzem address set: 0x01",
"reset": "Поставьте этот параметр равным 1 и pzem будет сброшен к нулю. Смотрите в логе результат: [i] Pzem reset done"
} }
}, },
"defActive": true, "defActive": true,