logo elektroda
logo elektroda
X
logo elektroda

[BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

TurkeyMan 10560 67
ADVERTISEMENT
  • Teardown of this energy meter from AliExpress.

    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    This device is an interesting DIN rail energy meter with a hole through the middle to pass a wire for metering. No physical connection of the circuit being metered is required. It's a unique design; instead of connecting a CT clamp to a metering device, the CT is inside the DIN module, so it keeps the circuit box tidy.

    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    Opening the device is very simple, just 4 screws on the back:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    We can see the CT wrapped around the through-hole. Accessing the circuit board is quite a hassle; there are no screws holding it in place, it is secured by the 4 plastic clips you can see at the 4 corners of the board:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    It's obviously designed to be assembled, but not disassembled. It was very difficult to get out from the clips, I ended up using a blade to shave away one of the clips at the corner, and then when lifting that one corner out, I was able to wiggle it free from the remaining 3 clips.

    Now we can see there are 2 boards inside. The wifi board is connected to the power electronics board by a little ribbon:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    Closer look at the mainboard:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    And I disconnected the ribbon to have a closer look at the little daughterboard:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    It's running a CBU and BL0942 for metering.
    The BL0942 is NOT connected with RS232, it seems to be connected by SPI instead.

    Flashed OpenBK with no problem using the command:
    python uartprogram ./OpenBK7231N_QIO_1.15.152.bin --unprotect -d com7 -w --startaddr 0x0


    The pinouts I could trace:
    P9 - BL0942 - CF1
    P14 - BL0942 - SCLK_BPS
    P16 - BL0942 - RX/SDI
    P17 - BL0942 - TX/SDO
    P20 - Bluetooth button
    P22 - Status LED
    P28 - ??? E2 Via

    There is a button on the device with the bluetooth logo next to it:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    I guess this button will put it into discovery mode with stock firmware. It is connected to P20, and I'm not sure how to make this work in OpenBK? I guess it should be configured that a long-press might perform a factory reset, or go into some wifi discovery mode without wiping other config data.
    Alternatively, if OpenBK ever supports something like a quick local-read feature pairing with a nearby bluetooth device and run an app for a quick local reading?

    There is also an LED on the front with POWER/BLUETOOTH/WIFI written next to it. It just seems to be a red LED that you can turn on/off, so stock firmware probably uses some flashing states to communicate different information. It would be nice for OpenBK to model some sort of "status" led, which could communicate various status details via flash patterns on a status led. Many devices have these, and it's never quite sure what to do with them. I usually just assign them wifi state, but that's not how the stock firmware uses these lights.

    There is also one random track that leads from P28 to the big unpopulated VIA just below the E2 label on the circuit board... it doesn't go anywhere else. So P28 is not wired to anything, but it looks like the circuit design intended that it might be used for something.

    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter


    TODO: This device uses SPI, which is not yet supported. I'll update this post when it is working.

    For the impatient, a hack has been proposed, which will convert the device to be connected by UART instead of SPI.
    A modification like this can be made, and then load the existing bl0942 driver:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    Cool? Ranking DIY
    About Author
    TurkeyMan
    Level 3  
    Offline 
    TurkeyMan wrote 58 posts with rating 8. Been with us since 2022 year.
  • ADVERTISEMENT
  • #2 20362038
    p.kaczmarek2
    Moderator Smart Home
    Thank you for detailed pinout, we already have one user who was looking for it.

    We don't have SPI support yet and I don't have this meter at hand. I could try to get SPI running with some other device that I have and then do BL0942 SPI support remotely, but it would be a bit hard to test - would you like to have? In that case, you'll have to wait for now.

    Second option: as said in another topic, consider doing reroute to UART. It's just 2 or 3 traces to be cut and 2 jump wires to be soldered. It's really, 5 minutes (15 minutes at most) hack and done.

    But if you're not in hurry, then I will check my drawers for SPI devices and try to setup BK SPI driver.
    Helpful post? Buy me a coffee.
  • #3 20362040
    TurkeyMan
    Level 3  
    I can do the UART hack, but I'm not in a hurry, and I think the SPI working is a good goal for its own reason. You can see how much trouble the guy in the other thread had with his device :) ... better not to need cuts and jumpers in the future.

    I can give this device a public IP and you can OTA/remote debug if you like... is it enough to flash a binary and then watch the logs? I can put a known load onto the meter so you can see the values are reading correctly.

    On a side note; I'm working on another device just now with BL0942 connected to TuyaMCU... do you think I'll need to get UART logs from this device, or is energy metering message protocol already well known for TuyaMCU? It has no other functionality. I have no idea why this device creator used TuyaMCU rather than just BL0942 connected directly, it's just more cost and no additional features I can see.

    Added after 9 [minutes]:

    EDIT: I put this SPI device online, you can reach it at: XYZ.ABC.DE.XZ
    Feel free to do what you like with it. Tell me if you need to have a test load and I'll turn a light bulb on.
  • #4 20362070
    p.kaczmarek2
    Moderator Smart Home
    Thanks, but first I need to do basic SPI support on my side. I can test it with any SPI device. I edited your post to remove part of IP. It will be useful in the future, but not now.


    BL0942 and TuyaMCU? You need TuyaMCU logs. We will just figure out dpIDs and that's all what required there, I think. What kind of device?
    Helpful post? Buy me a coffee.
  • #5 20362165
    TurkeyMan
    Level 3  
    p.kaczmarek2 wrote:
    Thanks, but first I need to do basic SPI support on my side. I can test it with any SPI device. I edited your post to remove part of IP. It will be useful in the future, but not now.

    It's not sensitive, but thanks... that said, hiding 8 bits is like hiding no bits :P ... scanning 8 bit IP space is a few seconds effort.
    Best you take note of what it is and then redact it from the post completely?

    p.kaczmarek2 wrote:
    BL0942 and TuyaMCU? You need TuyaMCU logs. We will just figure out dpIDs and that's all what required there, I think. What kind of device?

    Another energy meter, no relay. This one has an external CT clamp. I grabbed ~5 different models to compare the build quality, and also to help populate your database with devices.
    Are you saying you haven't identified Tuya energy metering messages before? Many messages use a standard protocol across devices don't they? Like a kind of Tuya message standard?
  • #6 20362189
    p.kaczmarek2
    Moderator Smart Home
    OK, IP redacted, I was in hurry. I am doing some post-new-year stuff but still keeping an eye on forum so I can help you and other users.

    TurkeyMan wrote:

    Are you saying you haven't identified Tuya energy metering messages before? Many messages use a standard protocol across devices don't they? Like a kind of Tuya message standard?

    Ok, to clear up things:
    - TuyaMCU is supported for a very long time
    - but dpIDs are per-device, so dpID 1 on one device is Battery Status, on other it's Relay1, and on another it may be Voltage - so they always have to be figured out on per-device basis
    - some Tuya devices are also using a "RAW" packet type of TuyaMCU, which is basically defined per-device and can contain anything. Some RAW packets of power sensor may have, for example, 10 bytes and one must guess the meaning of the bytes because they are per-device model.

    So it's not possible to "just support it", it is always on per device basis.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 20363440
    gulson
    System Administrator
    I wonder how accurate this measurement is, where only the N cable passes?
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
  • #8 20364821
    TurkeyMan
    Level 3  
    Tuya device I mentioned is here: https://www.elektroda.com/rtvforum/topic3946128.html#20364819

    The device in this thread is pending SPI implementation.

    Added after 2 [hours] 5 [minutes]:

    FYI, I was scrolling the device list; you should update the entry for this device to point to this thread. The other thread doesn't have much information and it's long and hard to follow...
  • ADVERTISEMENT
  • #9 20365113
    p.kaczmarek2
    Moderator Smart Home
    Thanks, I will do that in a free moment.

    Are you going to attempt the UART modification?

    I am not able to do SPI support first. I will be looking into other requests first, like a software I2C.
    Helpful post? Buy me a coffee.
  • #10 20365420
    TurkeyMan
    Level 3  
    I don't need to do the UART mod. I'd rather reserve this as a test case for SPI whenever you get to it.
    My feeling is that devices in the support list should be minimally modified. The hack is fairly easy in this case, and some people could do it, but it's not where we should aim to land.
  • ADVERTISEMENT
  • #11 20444123
    Digga
    Level 9  
    Hi,
    thanks for the post and information.

    I'm trying to flash the module but it always fails with "Cannot get Bus." I tried many many times with different CEN to GND time but can't get it working. Did you cut any lines for flashing? Any tips?

    My 3.3V USB to Serial is working with my Orange Pi. The 5V on the Low Drop Regulator is directly connected to 5V USB and the CBU has it's 3.3V supply, when the USB is connected. The diode on the backside flashes slightly one time when connecting the USB.

    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter

    ./uartprogram OpenBK7231N_QIO_1.15.453.bin --unprotect -d /dev/ttyUSB0 -w --startaddr 0x0
    UartDownloader....
    programm....
    Cannot get bus. : |                                                  |[    ?k/s]
    


    Edit:
    I also tried the power reset method serveral times without success. Of course the TX from the serial is connect to RX from CBU and vise versa.
  • #12 20444369
    TurkeyMan
    Level 3  
    I didn't connect the 5V, I flashed with 3.3V directly to the wifi module. I find I usually have more success when as little of the surrounding electronics are powered as possible.
    I did not use the CEN technique, I've tried many times and that never works for me. I always control the power. Also, one less thing to solder.
    So I run the command, then supply power. If it doesn't work immediately, power off, Ctrl-C, run the command again, and power on again until it works. I often need to do this 2-3 times before it works. There's a timing thing; the flashing software needs to probe during a very short moment during boot-up.

    Be aware this device doesn't work currently unless you perform the SPI->UART conversion mod detailed up-thread. OpenBK doesn't support SPI connected peripherals yet.
  • #13 20445438
    Digga
    Level 9  
    Thanks for the quick reply.

    I tried it with directly 3.3V (CEN and power method), but still can't flash it. I double checked the TX/RX connection and never connected it the wrong way. The 3.3V LDO I used has 250mA (used with capacitors).

    Any more ideas?

    Edit: The SPI -> UART hack would be no problem.

    Edit2:
    Just for checking: I connected the pcbs and powered the board normally with 230V and registered it with the peacefair app. Everything is working. Thus the CBU is not broken. Of course one PIN i.e. TX or RX could be broken, but I can't imaging how it should happened.

    For the orange pi I have to disable hardware flow control in minicom. But as I understand it, this would use one more connection, which the uartprogram would use to reset the pin. Thus has nothing to do with the flashing problem, does it?
  • #14 20446298
    Digga
    Level 9  
    After some research the problem could be USB to Serial related. I read that the chip PL2303, which my USB to Serial is using, is no very stable/good. The best seems to be CP2102 followed by CH340G. Which one are you using?
  • #15 20446305
    p.kaczmarek2
    Moderator Smart Home
    We are using that one:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    as you can see on our YT channel:
    https://www.youtube.com/@elektrodacom
    Helpful post? Buy me a coffee.
  • #16 20449780
    Digga
    Level 9  
    I ordered that one. It should arrive in two days.

    I borrowed a FT2232H Mini Module from work. Connected everything, double cheking TX to RX and vise versa as usual. Still no success. Not even with RTS connected to CEN.

    What makes me nervous is, that the CBU pin 15 = TXD has almost 0V, the CBU pin 16 RXD has 3.3 V, but the FDTI TXD has 3.3V and the RXD has 2.3V. I thought TXD in idle should have 3.3V, and it looks like I'm connecting two TXDs. But maybe the pins just get a different function on runtime.

    Only one time from many many tries i got a bit further:
    UartDownloader....
    Read Getting Bus...
    Gotten Bus...
    Set baudrate failed
    


    But as I cannot flash it with this one my hope for the USB to TTL you are using is quite low.
  • #17 20453437
    Digga
    Level 9  
    I got it to work. Thanks for your support!

    1. My old serial adapter with 5V from USB to onboard LDO did not work
    2. My old serial adapter with 3.3V from external LDO powered by 5V USB did not work
    3. FTDI serial adapter with internal 3.3V LDO, which can do 150mA did not work
    4. The adapter you use with 3.3V from external LDO powered by 5V USB did not work
    5. The adapter you use with lab power supply did it!!!

    I think there was a voltage drop on the power supply and therefore flashing was not possible. I tried laptop and desktop USB...

    Now I have a look at SPI, but probably I end up with the UART hack :)
  • #18 20453556
    p.kaczmarek2
    Moderator Smart Home
    Do you have C programming skills and would like to help us?
    Helpful post? Buy me a coffee.
  • #19 20456625
    Digga
    Level 9  
    I will try to contribute, but I don't know if I will have success :D
  • #20 20456627
    p.kaczmarek2
    Moderator Smart Home
    Any help is welcome, you can also help with testing, docs, or with spreading the word (advertising) or... just donate so we can buy more devices for testing.
    Don't forget about our Youtube channel:
    https://www.youtube.com/@elektrodacom
    Helpful post? Buy me a coffee.
  • #21 20456642
    Digga
    Level 9  
    With contribute I meant programming :) So I will try to build first and then see if I can code something, i.e. the SPI support for the BL0942.
  • #22 20456648
    p.kaczmarek2
    Moderator Smart Home
    @Digga remember that our online builds are working even in pull requests, so you don't have to setup anything to get binaries.
    We also support Docker build:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/docker
    Helpful post? Buy me a coffee.
  • #23 20456667
    Digga
    Level 9  
    But don't I have to compile and test my code before I make any pull requests?

    I'm currently setting up the docker build. It is probably the best work flow, I guess.
  • #24 20456679
    p.kaczmarek2
    Moderator Smart Home
    Well, if you fork repository ,you will also get builds working, even without "poluting" the PRs.
    For example, like that user, doing IR stuff:
    https://github.com/vfonov/OpenBK7231T_App/tree/IR_UPGRADE
    If you go to the run:
    https://github.com/vfonov/OpenBK7231T_App/actions/runs/4060663402
    And look down here:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    you will get that file:
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    Everything is built online. Very easy and quick for testing.
    Helpful post? Buy me a coffee.
  • #25 20456705
    Digga
    Level 9  
    That sounds great. I definitely will try that. Thanks for the pictures and description how to do it.
    I have to admit, that I haven't done anything else than clone with github yet. But now is the right time :)
    Just finished building the docker... will try it with github later.
  • #26 20464271
    Digga
    Level 9  
    I invested a lot of time understanding the code and trying to get SPI running. Unfortunately without success.

    From spi_pub.h I'm using either:
    spi_init();
    bk_spi_master_init(100000, SPI_CPHA | SPI_MSB); // Returns no error
    bk_spi_master_xfer(&msg); // Does never return. I inserted some debug logs and I never get an interrupt (spi_isr is never called). Webapp is still available.

    or
    bk_spi_master_dma_tx_init(SPI_CPHA | SPI_MSB, 100000, &msg);
    bk_spi_master_dma_send(&msg); // Does never return. Webapp is not available anymore.


    Do you have any ideas here? I also couldn't find a proper datasheet of the chip with register descriptions.
    If I understood it correctly, the tuya/tuya-iotos-embeded-sdk-wifi-ble-bk7231n was forked, while it still was open source. Now they changed it to closed source. Probably in the version we forked, the SPI is buggy/not working.
  • #27 20465971
    smoku83
    Level 11  
    Hello
    Yesterday I received this device and after connecting it, it turned out that the wifi range is lost, because the electrical box is 50m away from the building with wifi. I know that you are dealing with something else in this topic, but I want to ask if you can solder an antenna to the CBU somewhere in the form of a few centimeters of copper wire to increase the range a bit, if so, where? Thanks
    Regards
  • #28 20466116
    p.kaczmarek2
    Moderator Smart Home
    I'm afraid that only CBU-IPEX has a connector for a mini antenna, but I don't think it will help at 50m anyway...
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    A regular CBU has only a pad in this place, there is no soldered connector ....
    [BK7231N / CBU] PZIOT-E01 DIN rail pass-through energy meter
    Helpful post? Buy me a coffee.
  • #29 20466928
    smoku83
    Level 11  
    Great really thanks a lot
    Regards
  • #30 20473261
    Digga
    Level 9  
    >>20453437

    Somehow one OTA update broke my device. Did you every had this problem?

    I had to flash via uart again. As expected with a bigger capacitor at the 3.3V it worked with the LDO. Also I bought the same adapter you use in the video and, at least at my adapter, the 5V pin is directly connected to the USB 5V. So I could use it for the LDO.

Topic summary

The discussion revolves around the PZIOT-E01 DIN rail pass-through energy meter, which features an internal current transformer (CT) for wire metering without physical connections. Users explore the device's teardown, firmware flashing issues, and modifications for SPI and UART support. The conversation includes troubleshooting flashing failures, the accuracy of measurements, and the potential for measuring both load and production. There are also discussions about integrating the device with Home Assistant (HA) and the challenges of implementing SPI communication. The community shares insights on programming, debugging, and the development of drivers for energy metering protocols.
Summary generated by the language model.
ADVERTISEMENT