mirror of https://github.com/arendst/Tasmota.git
Fix PZEM default address and detection
* Change PZEM004T default address mask from 0.0.0.x to 192.168.1.x for legacy reason (#6585) * Fix PZEM004T, PZEMAC and PZEMDC autodetection (#6585)
This commit is contained in:
parent
afd3c64844
commit
6d31608fe0
|
@ -1,4 +1,8 @@
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
|
* 6.6.0.16 20191008
|
||||||
|
* Change PZEM004T default address mask from 0.0.0.x to 192.168.1.x for legacy reason (#6585)
|
||||||
|
* Fix PZEM004T, PZEMAC and PZEMDC autodetection (#6585)
|
||||||
|
*
|
||||||
* 6.6.0.15 20191003
|
* 6.6.0.15 20191003
|
||||||
* Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519)
|
* Change command PulseTime JSON message format and allow display of all pulsetimer information (#6519)
|
||||||
* Add support for Chint DDSU666 Modbus energy meter by Pablo Zerón
|
* Add support for Chint DDSU666 Modbus energy meter by Pablo Zerón
|
||||||
|
|
|
@ -85,9 +85,9 @@ void PzemSend(uint8_t cmd)
|
||||||
PZEMCommand pzem;
|
PZEMCommand pzem;
|
||||||
|
|
||||||
pzem.command = cmd;
|
pzem.command = cmd;
|
||||||
pzem.addr[0] = 0; // Address 0.0.0.1
|
pzem.addr[0] = 192; // Address 192.168.1.1 for Tasmota legacy reason
|
||||||
pzem.addr[1] = 0;
|
pzem.addr[1] = 168;
|
||||||
pzem.addr[2] = 0;
|
pzem.addr[2] = 1;
|
||||||
pzem.addr[3] = ((PZEM_SET_ADDRESS == cmd) && Pzem.address) ? Pzem.address : 1 + Pzem.phase;
|
pzem.addr[3] = ((PZEM_SET_ADDRESS == cmd) && Pzem.address) ? Pzem.address : 1 + Pzem.phase;
|
||||||
pzem.data = 0;
|
pzem.data = 0;
|
||||||
|
|
||||||
|
@ -113,6 +113,7 @@ bool PzemRecieve(uint8_t resp, float *data)
|
||||||
// A1 00 00 0A 00 00 AB - Current (0.1A)
|
// A1 00 00 0A 00 00 AB - Current (0.1A)
|
||||||
// A1 00 00 00 00 00 A1 - No current
|
// A1 00 00 00 00 00 A1 - No current
|
||||||
// A2 00 16 00 00 00 B8 - Power (22W)
|
// A2 00 16 00 00 00 B8 - Power (22W)
|
||||||
|
// A2 08 98 00 00 00 42 - Power (2200W)
|
||||||
// A2 00 00 00 00 00 A2 - No power
|
// A2 00 00 00 00 00 A2 - No power
|
||||||
// A3 00 08 A4 00 00 4F - Energy (2.212kWh)
|
// A3 00 08 A4 00 00 4F - Energy (2.212kWh)
|
||||||
// A3 01 86 9F 00 00 C9 - Energy (99.999kWh)
|
// A3 01 86 9F 00 00 C9 - Energy (99.999kWh)
|
||||||
|
@ -124,11 +125,7 @@ bool PzemRecieve(uint8_t resp, float *data)
|
||||||
while ((len < sizeof(PZEMCommand)) && (millis() - start < PZEM_DEFAULT_READ_TIMEOUT)) {
|
while ((len < sizeof(PZEMCommand)) && (millis() - start < PZEM_DEFAULT_READ_TIMEOUT)) {
|
||||||
if (PzemSerial->available() > 0) {
|
if (PzemSerial->available() > 0) {
|
||||||
uint8_t c = (uint8_t)PzemSerial->read();
|
uint8_t c = (uint8_t)PzemSerial->read();
|
||||||
if (!c && !len) {
|
if (!len && ((c & 0xF8) != 0xA0)) { // 10100xxx
|
||||||
continue; // skip 0 at startup
|
|
||||||
}
|
|
||||||
if ((1 == len) && (buffer[0] == c)) {
|
|
||||||
len--;
|
|
||||||
continue; // fix skewed data
|
continue; // fix skewed data
|
||||||
}
|
}
|
||||||
buffer[len++] = c;
|
buffer[len++] = c;
|
||||||
|
@ -172,7 +169,7 @@ bool PzemRecieve(uint8_t resp, float *data)
|
||||||
const uint8_t pzem_commands[] { PZEM_SET_ADDRESS, PZEM_VOLTAGE, PZEM_CURRENT, PZEM_POWER, PZEM_ENERGY };
|
const uint8_t pzem_commands[] { PZEM_SET_ADDRESS, PZEM_VOLTAGE, PZEM_CURRENT, PZEM_POWER, PZEM_ENERGY };
|
||||||
const uint8_t pzem_responses[] { RESP_SET_ADDRESS, RESP_VOLTAGE, RESP_CURRENT, RESP_POWER, RESP_ENERGY };
|
const uint8_t pzem_responses[] { RESP_SET_ADDRESS, RESP_VOLTAGE, RESP_CURRENT, RESP_POWER, RESP_ENERGY };
|
||||||
|
|
||||||
void PzemEvery200ms(void)
|
void PzemEvery250ms(void)
|
||||||
{
|
{
|
||||||
bool data_ready = PzemReceiveReady();
|
bool data_ready = PzemReceiveReady();
|
||||||
|
|
||||||
|
@ -202,17 +199,26 @@ void PzemEvery200ms(void)
|
||||||
if (5 == Pzem.read_state) {
|
if (5 == Pzem.read_state) {
|
||||||
Pzem.read_state = 1;
|
Pzem.read_state = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PZM: Retry %d"), 5 - Pzem.send_retry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == Pzem.send_retry || data_ready) {
|
if (0 == Pzem.send_retry || data_ready) {
|
||||||
Pzem.phase++;
|
if (1 == Pzem.read_state) {
|
||||||
if (Pzem.phase >= Energy.phase_count) {
|
if (0 == Pzem.phase) {
|
||||||
Pzem.phase = 0;
|
Pzem.phase = Energy.phase_count -1;
|
||||||
|
} else {
|
||||||
|
Pzem.phase--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("PZM: Probing address %d, Max phases %d"), Pzem.phase +1, Energy.phase_count);
|
||||||
|
}
|
||||||
|
|
||||||
if (Pzem.address) {
|
if (Pzem.address) {
|
||||||
Pzem.read_state = 0; // Set address
|
Pzem.read_state = 0; // Set address
|
||||||
}
|
}
|
||||||
|
|
||||||
Pzem.send_retry = 5;
|
Pzem.send_retry = 5;
|
||||||
PzemSend(pzem_commands[Pzem.read_state]);
|
PzemSend(pzem_commands[Pzem.read_state]);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +239,7 @@ void PzemSnsInit(void)
|
||||||
ClaimSerial();
|
ClaimSerial();
|
||||||
}
|
}
|
||||||
Energy.phase_count = 3; // Start off with three phases
|
Energy.phase_count = 3; // Start off with three phases
|
||||||
Pzem.phase = 2;
|
Pzem.phase = 0;
|
||||||
Pzem.read_state = 1;
|
Pzem.read_state = 1;
|
||||||
} else {
|
} else {
|
||||||
energy_flg = ENERGY_NONE;
|
energy_flg = ENERGY_NONE;
|
||||||
|
@ -252,8 +258,10 @@ bool PzemCommand(void)
|
||||||
bool serviced = true;
|
bool serviced = true;
|
||||||
|
|
||||||
if (CMND_MODULEADDRESS == Energy.command_code) {
|
if (CMND_MODULEADDRESS == Energy.command_code) {
|
||||||
|
if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 4)) {
|
||||||
Pzem.address = XdrvMailbox.payload; // Valid addresses are 1, 2 and 3
|
Pzem.address = XdrvMailbox.payload; // Valid addresses are 1, 2 and 3
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else serviced = false; // Unknown command
|
else serviced = false; // Unknown command
|
||||||
|
|
||||||
return serviced;
|
return serviced;
|
||||||
|
@ -268,8 +276,8 @@ bool Xnrg03(uint8_t function)
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_EVERY_200_MSECOND:
|
case FUNC_EVERY_250_MSECOND:
|
||||||
if (PzemSerial) { PzemEvery200ms(); }
|
if (PzemSerial && (uptime > 4)) { PzemEvery250ms(); }
|
||||||
break;
|
break;
|
||||||
case FUNC_COMMAND:
|
case FUNC_COMMAND:
|
||||||
result = PzemCommand();
|
result = PzemCommand();
|
||||||
|
|
|
@ -84,9 +84,10 @@ void PzemAcEverySecond(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == PzemAc.send_retry || data_ready) {
|
if (0 == PzemAc.send_retry || data_ready) {
|
||||||
PzemAc.phase++;
|
if (0 == PzemAc.phase) {
|
||||||
if (PzemAc.phase >= Energy.phase_count) {
|
PzemAc.phase = Energy.phase_count -1;
|
||||||
PzemAc.phase = 0;
|
} else {
|
||||||
|
PzemAc.phase--;
|
||||||
}
|
}
|
||||||
PzemAc.send_retry = ENERGY_WATCHDOG;
|
PzemAc.send_retry = ENERGY_WATCHDOG;
|
||||||
if (ADDR_SEND == PzemAc.address_step) {
|
if (ADDR_SEND == PzemAc.address_step) {
|
||||||
|
@ -111,7 +112,7 @@ void PzemAcSnsInit(void)
|
||||||
if (result) {
|
if (result) {
|
||||||
if (2 == result) { ClaimSerial(); }
|
if (2 == result) { ClaimSerial(); }
|
||||||
Energy.phase_count = 3; // Start off with three phases
|
Energy.phase_count = 3; // Start off with three phases
|
||||||
PzemAc.phase = 2;
|
PzemAc.phase = 0;
|
||||||
} else {
|
} else {
|
||||||
energy_flg = ENERGY_NONE;
|
energy_flg = ENERGY_NONE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,9 +82,10 @@ void PzemDcEverySecond(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == PzemDc.send_retry || data_ready) {
|
if (0 == PzemDc.send_retry || data_ready) {
|
||||||
PzemDc.channel++;
|
if (0 == PzemDc.channel) {
|
||||||
if (PzemDc.channel >= Energy.phase_count) {
|
PzemDc.channel = Energy.phase_count -1;
|
||||||
PzemDc.channel = 0;
|
} else {
|
||||||
|
PzemDc.channel--;
|
||||||
}
|
}
|
||||||
PzemDc.send_retry = ENERGY_WATCHDOG;
|
PzemDc.send_retry = ENERGY_WATCHDOG;
|
||||||
if (ADDR_SEND == PzemDc.address_step) {
|
if (ADDR_SEND == PzemDc.address_step) {
|
||||||
|
@ -110,7 +111,7 @@ void PzemDcSnsInit(void)
|
||||||
if (2 == result) { ClaimSerial(); }
|
if (2 == result) { ClaimSerial(); }
|
||||||
Energy.type_dc = true;
|
Energy.type_dc = true;
|
||||||
Energy.phase_count = 3; // Start off with three channels
|
Energy.phase_count = 3; // Start off with three channels
|
||||||
PzemDc.channel = 2;
|
PzemDc.channel = 0;
|
||||||
} else {
|
} else {
|
||||||
energy_flg = ENERGY_NONE;
|
energy_flg = ENERGY_NONE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue