make a wiring connection for PZEM-004 v3.0 and ESP8266: (either NodeMCU and Wemos)
ESP8266 5V ==> PZEM 5V
ESP8266 G ==> PZEM GND
ESP8266 Rx ==> PZEM_Rx -> D6(GPIO12 - Tx)
ESP8266 Tx ==> PZEM_Tx -> D5(GPIO14 - Rx)
#include <SoftwareSerial.h>
SoftwareSerial pzem(14,12); // (RX,TX) connect to TX,RX of PZEM for ESP8266 bare board
void resetEnergy(uint8_t slaveAddr){
//The command to reset the slave's energy is (total 4 bytes):
//Slave address + 0x42 + CRC check high byte + CRC check low byte.
uint16_t u16CRC = 0xFFFF;
static uint8_t resetCommand = 0x42;
u16CRC = crc16_update(u16CRC, slaveAddr);
u16CRC = crc16_update(u16CRC, resetCommand);
Serial.println("Resetting Energy");
pzem.write(slaveAddr);
pzem.write(resetCommand);
pzem.write(lowByte(u16CRC));
pzem.write(highByte(u16CRC));
delay(100);
}