Just received a PZEM004T (v3) and had to adapt my older monitor for the new MODBUS interface (this interface uses CRC16 checksum).
This is a routine I've made to calculate the checksum based on the specs guide at www.modbus.org.
Code: [Local Link Removed for Guests]
' Calc CRC16 for MODBUS
' Parameters:
' byte Array of bytes (1 for each occurence) (23 bytes for PZEM004T)
' size Size of array
' poly Polynomial to use (&hA001 for PZEM004T)
' crc16 Result (use 2 bytes of this value)
' First byte with hex$(crc16 mod 256)
' Second byte with hex$(crc16 >> 8)
sub MODBUS_crc16(byte(), size, poly, crc16)
local f, g
crc16 = &hFFFF
for f = 1 to size
crc16 = crc16 xor byte(f-1)
for g=1 to 8
if ((crc16 and &h01) <> 0) then
crc16 = crc16 >> 1
crc16 = crc16 xor poly
else
crc16 = crc16 >> 1
end if
next g
next f
end sub
The new version (v3), reports voltage (80v~260v), current (0~100A), frequency (45~60Hz), power factor (0~1 only on v3), power (0~22Kw) and active energy (0~9999Kwh).
By using MODBUS, the new version (v3) should allow more than device to be connected to ESP8266 on the same serial line.
Here you can see specs: https://innovatorsguru.com/pzem-004t-v3/
I've been using it (v1) for three years without any relevant problems (some inacurate values returned but easily eliminated and very rare).
I'm gathering data that I store in a database and analyze it later.
The first goal was to monitor my energy use in order help me define my energy supplier and energy rate to use (I review rates every year and change accordingly). I estimate that it helped me to reduce my energy bill in 15%, at least.
This year I used the collected data to profile my energy use in daylight (solar photovoltaic panel usable time) and decide (ROI based) the optimal size of my solar installation (still in plan).
A note for the fact that PZEM004T doesn't report current direction, so, if you have a grid-tied solar installation, readings will be inaccurate.
A MOD that allows the detection of current direction has been released, for v1 devices, by Bruno Horta https://github.com/brunohorta82/BH_PZEM_ESP8266 nevertheless, in my opinion, the values of energy will still be inaccurate.