mandulaj / PZEM-004T-v30

Arduino library for the Updated PZEM-004T v3.0 Power and Energy meter
MIT License
256 stars 108 forks source link

HOW TO RESET PZEM004TV3 ESP32? #107

Open margohaux opened 1 year ago

margohaux commented 1 year ago

HI! I wanted to reset the energy but it does not work :( ...

if(thingspeak.readfloatfield(channel, apikey)==1){
            uint16_t u16CRC = 0xFFFF;                         /* declare CRC check 16 bits*/
            static uint8_t resetCommand = 0x42;               /* reset command code*/
            uint8_t slaveAddr =0X01;
            u16CRC = crc16_update(u16CRC, slaveAddr);
            u16CRC = crc16_update(u16CRC, resetCommand);
            preTransmission();                                           
            Serial.write(slaveAddr);                         
            Serial.write(resetCommand);                      
            Serial.write(lowByte(u16CRC));                    
            Serial.write(highByte(u16CRC));                   
            delay(10);
            postTransmission();                              
            delay(100);
          }
        }
mandulaj commented 1 year ago

Hey, have you tried using the resetEnergy function in the library?

Something along the lines of:


PZEM004Tv30 pzem(Serial);

psem.resetEnergy();

float energy = pzem.energy(); // -> 0