openshwprojects / BK7231GUIFlashTool

Easy to use, GUI, BK7231T/BK7231N flash tool and GPIO config extractor for beginners. Dedicated for Windows platform, but works on Linux with Mono. This tool can automatically download latest firmware (on user request) and then do a full BK backup and then write new flash cycle. This tool replaces old bkWriter 1.60 and hid_download_py.
232 stars 24 forks source link

Feature request: Extract power calibration data #35

Open dwmw2 opened 3 months ago

dwmw2 commented 3 months ago

(This is a "duplicate" of https://github.com/libretiny-eu/ltchiptool/issues/38 )

I have a bunch of Tongou DIN rail power meters (https://www.elektroda.com/rtvforum/viewtopic.php?p=21191153#21191153),. and have finally got round to liberating them.

I've been experimenting with them, and found that the calibration parameters for the BL0942 chip are available both in the DPs that the Tuya firmware reports, and also in the flash. More details at https://github.com/esphome/issues/issues/6155

So apart from the one I already converted without reading its flash first, I can liberate them without losing the factory calibration. It would be nice if the tooling could help new users get this right.

Example firmware dump at http://david.woodhou.se/tongou-tuyafw.bin (sha256 a0b0a2804946f8760f5be0360a3b0325d204087c6aae6c7917297cba2f1341ba)

I found the calibration at 0x001d5000:

001d5000  60 3e 00 00 82 30 00 00  13 0c 00 00 5d 0a 00 00  |`>...0......]...|

That's

We can apply a sanity check to those, as the PREF can be derived from UREF/IREF, and EREF from PREF as described in the ESPHome ticket above.

dwmw2 commented 3 months ago

Now documented for ESPHome: https://devices.esphome.io/devices/Tongou-TO-Q-SY1-JWT