Closed alfs closed 1 month ago
I've implemented extended data readout to also get current power, flow rate, temperature of inflow, outflow and temperature difference, using the /#!
command instead of /?!
(See #7)
The commit includes a reworked OBIS parsing code, put into a separate module.
Note - this code expects the entire telegram to be available for reading, ca 2 kB. In my tests, using ESP32-S2, this has never failed, however some chips may have a faster processor vs UART reading which causes parts of the telegram to be read in chunks. 2 kB at 2400 baud (bps) is sent in about 850ms, so I am a bit surprised all data is there since the event loop is much shorter. If there is a problem, one solution is to implement line-reading of read() from UARTDevice, for example int i=0; while (b=read()) { buffer[i++] = b; if (b == '!') publish(obis); elseif (b=='\n') process_obisline(buffer)
) instead of read_array()
. Or just busy-wait-sleep 50ms until available() stops increasing and then do the readout, as long as UARTDevice can hold the buffer space until data is read.
Note 2 - the commits also reduce the meter reading interval from 10 minutes to 1 minute, since instantaneous values need to be read more frequently. If the meter is battery powered, this will increase power drain by 10x, so adjust the reading interval accordingly if needed. Grid-powered meters are unaffected by the reading interval, naturally.
Awesome changes! I have no way of testing them since my heating distributor unfortunately replaced my UH50 with another, non-compatible meter but I merge this PR for the greater good 😄 👍
When UART receive pin is not connected to the Serial device, the reading fails.
This patch instead reads from UARTDevice from the configured rx-pin.
In my system, the whole telegram (about 1 kB) is already buffered and available to be read when the reading code is reached. I therefore increased the buffer size to hold the whole telegram with a read_array() call, instead of the previous line-based reading. This also implies the detection of "!" is not at the start of a line, so the publishing is triggered when no more data is available instead.
An alternative could be to do looped read() into the buffer until newline is detected, if the read_array() is not working sufficiently well. E.g.
Having the full buffered read is however a preparation for the next step of parsing all OBIS objects for publishing.