Fix issue #2054. PZEM004T Component doesn't set the module address. (#1784)

This commit is contained in:
Tercio Filho 2021-09-13 10:36:01 -03:00 committed by GitHub
parent a4867a00ea
commit aad03f1bf5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -6,6 +6,14 @@ namespace pzem004t {
static const char *const TAG = "pzem004t";
void PZEM004T::setup() {
// Clear UART buffer
while (this->available())
this->read();
// Set module address
this->write_state_(SET_ADDRESS);
}
void PZEM004T::loop() {
const uint32_t now = millis();
if (now - this->last_read_ > 500 && this->available() < 7) {

View File

@ -14,6 +14,8 @@ class PZEM004T : public PollingComponent, public uart::UARTDevice {
void set_power_sensor(sensor::Sensor *power_sensor) { power_sensor_ = power_sensor; }
void set_energy_sensor(sensor::Sensor *energy_sensor) { energy_sensor_ = energy_sensor; }
void setup() override;
void loop() override;
void update() override;