psvanstrom / esphome-uh50reader

ESPHome custom component for communicating with Landis+Gyr T550 (UH50) heat/cold meters and reading usage data
MIT License
7 stars 3 forks source link

ESP32-S2 / PiggyMeter support for UH50 #5

Open alfs opened 1 week ago

alfs commented 1 week ago

The PiggyMeter (https://aquaticus.info/meter.html) kit ships with ESP32-S2 chips, but the software (https://github.com/aquaticus/piggymeter_esphome_yaml) doesn't work with the UH50 / T550 meter, and neither with this project. However I think this project is easier to adapt than adding UH50 decoding to the other project (including baud separation).

After troubleshooting, enabling serial debugging, and printing the available() bytes to read (that are actually not being read from the buffer), my conclusion is the reason is the Serial.readBytesUntil() at https://github.com/psvanstrom/esphome-uh50reader/blob/b26e0121ad7d971e74c97ef91267655b19889e18/uh50reader.h#L138

Checking Serial.available(), there is no data in the buffer as available() reports, which explains why reading from Serial does not yield data.

Instead of using Serial.read functions, just using read() from UARTDevice (https://esphome.io/api/classesphome_1_1uart_1_1_u_a_r_t_device#af6640e87989a465b2fac209d932f1c40) produces reliable results.

Most likely this is because of pins GPIO11 and GPIO12 is used for the UART on the ESP32-S2 + PiggyMeter, not mapped to Serial communications.

So I'm currently trying to replace Serial.read with UARTDevice reads, as well as implementing support for all meter sensors (ca 1 kB telegram is delivered from the meter).

I assume reading from UARTDevice will also work for the other/all ESP-chips, so it'll be a more generic implementation. Just like the sendDataCmd is using uart_out.write, not Serial write.

alfs commented 1 week ago

See PR https://github.com/psvanstrom/esphome-uh50reader/pull/6