New: the AI firewall watches the whole platform and explains each incident in plain words. See how it works

Reply To: Cheap Wi-Fi plug opened up: what are the signals between the logic board and the power board?

Translated from Türkçe by AI ·

Most of these plugs have an HLW8012 or its clone BL0937, 8 legs, and the pins you described match exactly. I used the same chip modules in water pump panels at the municipality, and this is how it works:

  • CF (your pin 5): pulse output whose frequency is proportional to active power.
  • CF1 (pin 4): depending on the SEL pin, a pulse proportional to either current or voltage.
  • SEL (pin 6): selection pin going from the logic board to the chip. On HLW8012 SEL=1 is current, on BL0937 it’s the opposite, and if you mix these up the values come out nonsense.

It’s easy to read: connect the two pins to an interrupt, count pulses in a 1 second window. For power, roughly:

volatile uint32_t cfPulses = 0;
void IRAM_ATTR onCF() { cfPulses++; }

// setup:
attachInterrupt(digitalPinToInterrupt(PIN_CF), onCF, RISING);

// every second:
noInterrupts(); uint32_t n = cfPulses; cfPulses = 0; interrupts();
float power_w = n * powerFactor;     // kalibrasyonla bulunacak
energy_wh += power_w / 3600.0;

Find the powerFactor value with a known load: plug in a 100 W heater or an incandescent bulb, divide the counted pulses by the real power. For voltage, do the same by changing SEL and using CF1.
Safety: when uploading the code, unplug the socket from the mains, program the ESP32-C3 via USB, then disconnect and plug it back in. Connecting to the mains while USB is attached means connecting your computer to the mains. Do the calibration by watching the log over Wi-Fi.
Send a energy_wh counter that increases, together with power_w, to Hermetry; getting the daily consumption from the counter later is much cleaner.

Accepted solution♥ 6