logo elektroda
logo elektroda
X
logo elektroda

Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

p.kaczmarek2 90573 372
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #241 20905472
    p.kaczmarek2
    Moderator Smart Home
    Please send the binary file here, I can extract config for you.

    Have you seen our Hass Pairing tutorial?


    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #242 20907370
    greg_li
    Level 2  
    >>20905357
    Finally I managed to do it using the published pin assignment. Both my plugs fully work now (still have to calibrate power, but it's roughly correct detecting ~240V and current as soon as I plug something, with a power less than 30% off actual power.
    The one with the tight CB2S was not resoldered correctly, probably because I partially stripped copper pads when pulling it off. BL0937_SEL (P24) and button (RX1-P10) were not contacting, but after some more use of my cheap soldering iron and more ugly solder blobs it works. Damn I reglued the plug before noticing this, First disassembly left the plugs pristine (clamp method)...Second one not so much, cyanoacrylate is stronger than the factory glue ;-)

    For power calibration I need to find an old resistive bulb somewhere, or some other resistive stuff where I am confident the advertised power is accurate....not so easy nowadays.

    The config is the one posted above and also the one proposed for the only tuya smart wifi plug with BL0937 in the database, so no surprise here....

    Looking at the MQTT stuff now, I can connect to my emqx server (although with user/passwd, all my other MQTT devices (zigbee2mqtt and handmade esp32 ) have those fields blank. But homeassistant do not see the 2 plugs, while all the other stuff is detected. I am looking at the advised youtube video (https://www.youtube.com/watch?v=pkcspey25V4), I see there is an additional step for homeasssitant after succesfully connecting to the mqtt server. Will try that :)
  • ADVERTISEMENT
  • #243 20907532
    p.kaczmarek2
    Moderator Smart Home
    Well, some users prefer to write the Yaml code themselves instead of using Hass discovery, so Hass discovery has to be manually run.
    Helpful post? Buy me a coffee.
  • #244 20909863
    greg_li
    Level 2  
    Done the Homeassistant config/start Homeassistant discovery after configuring MQTT ang my plugs showing they reached successfully the mqtt server (emqx on a linux NUC in my case, the same machine that run homeassistant the old way (no container, no hass OS ).

    Before doing that, the plugs were not seen by homeassistant even if the mqtt server showed them as connected. After, everything is in order, I can control wifi led, relay (and button led reflect relay status while button manually control it too). Even Power is shown and seems roughly correct, even before I did a proper calibration....

    In short, all is working exactly as it should :-)

    So for those using mqtt, seeing the device as connected in the mqtt broker but not seeing it in homeassistant, "start Homeassistant discovery" may be the only thing you still need to do ;-)
  • #245 20928892
    uchristo
    Level 6  
    Hi there!
    I got a bunch of new GoSund EP2 Sockets with Power Measurement. They incorporate a Board CUCO-Z06-N consisting of a Beken 7231N and a BL0942 connected to TX1/RX1
    While programming, the Header with the GPIO-Infos wasn't readable (see attached BIN-File) so I had to roll the dice myself.

    P6 (PWM0): Relais 1
    P7 (PWM1): Button 1
    P8 (PWM2): Green LED
    P9 (PWM3): Blue LED

    But I'm unable to readout BL0942. I already typed StartDriver BL0942 into Startup and used
    Voltageset 240
    CurrentSet 0.1
    PowerSet 7

    but the device still shows nothing useful:
    OpenBekenX user interface with power measurement information, toggle buttons, and BL0942 error.
    What am I doing wrong??? It's definitely connected to the same UART I used for Flashing-

    Close-up of a BL0942 integrated circuit on a circuit board. Close-up of a PCB with a BL0942 integrated circuit and visible wire connections. Close-up of the Beken BK7231N electronic module on a PCB.
  • ADVERTISEMENT
  • #246 20929217
    p.kaczmarek2
    Moderator Smart Home
    @uchristo can you remove the wires used to flash firmware before testing BL0942? They are using the same port
    Helpful post? Buy me a coffee.
  • #247 20929220
    uchristo
    Level 6  
    I did that already. To be honest: I had no device handy from which I definitely knew the power consumption so dialed in some fantasy Digits for power and current…
    240Volts*0.1Ampere will never be 7Watts… is this a problem? Should I dial in some sane values in the correct relation for testing?
  • #248 20929223
    p.kaczmarek2
    Moderator Smart Home
    Wait, do you even know how to do a calibration? You must take a resistive load, take a calibrated device, and enter real devices with VoltageSet, CurrentSet, etc commands...
    https://tasmota.github.io/docs/Power-Monitoring-Calibration/
    Helpful post? Buy me a coffee.
  • #249 20929250
    uchristo
    Level 6  
    Never did that before on any of my tasmotized shelly2.5….
    But these read some digits not zero even if not calibrated.
    Will I have to change module config in order to let the driver know which uart to read? There‘s no BL0942 available for Pin-configuration

    Edit: Never did that on my shellies, because these are driving shutters and powermeasurements did not seem useful to me back in the days. But the new EP2s shall be used to monitor the device loads.
    I got a (quite old tbh) Metrix PX120 Wattmeter, so calibration should be quite easy with a lightbulb connected when I know that everything else is fine. My main concern is, that all values are zero right now even with non-zero fantasy-loads configured
  • #250 20929341
    p.kaczmarek2
    Moderator Smart Home
    Well, at least the voltage value should be non zero, unless you entered some random values to calibration...
    Alternatively, it's possible that your device is using BL0942 in SPI mode, and if that's the case, you need to use BL0942SPI driver.
    https://www.elektroda.com/rtvforum/find.php?q=BL0942SPI

    BL0942 is always using UART1 (or SPI) and we haven't encountered yet any devices with config different than that, but if you are unsure, you can check with a multimeter how BL0924 is connected.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #251 20929391
    uchristo
    Level 6  
    That did the trick!
    The Board uses SPI. I traced back the tx/rx Pins of BL0942 to tx/rx on bk7231N.
    Values are complete nonesense, but atleast non-zero



    Screenshot of measurement data from an electronic device.
  • #252 20929445
    p.kaczmarek2
    Moderator Smart Home
    So you have a a new device that we haven't seen yet. Can you create a new, separate teardown topic with device details, photos, model name and full config, so we can add it to our devices list?
    Helpful post? Buy me a coffee.
  • #253 20929489
    uchristo
    Level 6  
    Sure, I‘ll be able to do that by mid of next week….
  • #254 20936011
    uchristo
    Level 6  
    Back home, but unfortunately with bad news.....
    BL0942SPI is loading somehow and showing weird digits. Tried to calibrate like linked in Tasmota-documentation, but with no success. Then had a look in Web Application -> Logs and this is what I see:
    Warn:EnergyMeter:Failed to read reg 03: bad checksum FF wanted A7
    Warn:EnergyMeter:Failed to read reg 04: bad checksum FF wanted A6
    Warn:EnergyMeter:Failed to read reg 06: bad checksum FF wanted A4
    Warn:EnergyMeter:Failed to read reg 07: bad checksum FF wanted A3
    Warn:EnergyMeter:Failed to read reg 08: bad checksum FF wanted A2

    Using UART, there's no data at all. How can I do further debugging?

    I'll trace PIN 7 of BL0942 to determine if it's really using SPI ( http://m.huazhoucn.com/downloads/belling/pdf/370-BL0942_V1.06_en.pdf )

    Added after 1 [hours] 40 [minutes]:

    PIN 7 of BL0942 is not connected to 3,3V (VDD) and not connected to GND. According to Datasheet, it's internally pulled down, so UART will be the correct method. TX and RX are connected to BK7231 with ~18 Ohms each
  • #255 20936166
    p.kaczmarek2
    Moderator Smart Home
    Wait, but wasn't it working just few days ago?

    Did something broke in a meantime?

    Or maybe... that SPI "working" was just a random noise.

    So you need to try UART route again.

    Why do you have two buttons on the main page?
    Helpful post? Buy me a coffee.
  • #256 20936194
    uchristo
    Level 6  
    The second button appears because of the second LED (green and blue)
    The output in SPI Mode seem to be just noise, the frequency was always shown as 0,23 Hz from the beginning.

    As the continuity Tests from Pin 7 to VDD/GND were "not connected", could it be that one PIN on BK7231N should be configured as output and set to "high" in Order to get sth out of the BL0942? If I understood correctly, per default all pins are in pull-down mode on BK7231... This should force BL0942 to UART-Mode, right? I already tried Option25+26

    Tracing the BK7231-Pins on the tiny PCB is quite a hassle, because all my multimeter-probes are huge in relation to BKs tiny PINs :-(

    Added after 1 [minutes]:

    I still have 6 EP2s with default firmware.... should I solder a cable to BL0942 PIN7 in order to see how stock firmware handles EnergyMonitoring?


    Second EDIT: If driven in UART-Modus, PIN 8 should be somehow wired to BK7231 in order to set Baud-rate, shoudn't it?
  • #257 20936260
    kyantobam
    Level 4  
    helo,

    I have a Smart Plug with CB2S wifi module and BL0942, installed the latest OpenBK firmware(1.17.436) and everything works fine.
    How to publish Frequency and power factor to homeassistant?
    Screen displaying frequency and power data from a Smart Plug with a Wi-Fi module. Screenshot of a table with sensor parameters.
    Thanks
  • #258 20937974
    uchristo
    Level 6  
    Did some further testing. I took the next plug with stock firmware, soldered cables to TX from BK7231N and BL0942 and SEL/SCLK_BPS from BL0942.

    I measured 0,03Volts for SEL, this means UART is the chosen protocol.
    On SCLK_BPS there were 2,877Volts

    I then captured on
    stty -F /dev/ttyUSB0 4800 raw
    (stty raw; cat > received_from_OpenBK.txt) < /dev/ttyUSB0

    Requests from BK7231N with stock Firmware:
    root@laeppilin:/home/uwe# od received_from_BK.txt
    0000000 007016 007016 007016 007016 007016 007016 167016 007016
    0000020 007016 007016 007016 007016 161016 007016 007016 007016
    0000040 007016 007356 007016 007016 007016 007016 007016 007016
    0000060 161016 007016 147016 007016 007016 007016 007016 007016
    0000100 007016 007016 007356 007016 007016 007016 007016 007216
    0000120 007016 007016 007016 007016 007016 161016 007016 007016
    0000140 007016 007016 163016 007016 007016 007016 007016 007016
    0000160 007342 007016 007016 161016 007016 007016 007016 007016
    0000200 007016 007016 007016 007016 007016 007016 007016 007016

    Response from BL0942:
    root@laeppilin:/home/uwe# od received_from_BL.txt
    0000000 054010 103411 004010 006410 044030 034010 007302 004010
    0000020 124010 000010 004375 004710 004337 004010 006410 164030
    0000040 124010 000502 004010 124010 000010 004377 041150 004004
    0000060 004010 004250 177400 144010 103702 004010 006410 064030
    0000100 024010 156411 004010 004010 014015 004310 141330 004002
    0000120 004010 004250 004000 141270 004000 004010 004250 004000
    0000140 041230 004016 004010 004250 004000 041330 004004 004010
    0000160 004250 177000 164010 071411 004010 124010 000010 004377
    0000200 141130 004000 004010 014015 004030 004550 004014 004010
    0000220 004250 177000 054010 071702 004010 124010 000010 004377
    0000240 041310 004207 004010 014015 004270 004510 004254 004010
    0000260 006410 054030 024010 034502 004010 124010 000010 164010
    0000300 124411 004010 004010 014015 004230 004570 004156 004010
    0000320 004250 004000 000350 004067 004010 004250 177400 164010
    0000340 145011 004010 004010 014015 004030 000000 004010 124010

    I then flashed openBeken, issued startDriver BL0942 and measured SEL/SCLK_BPS, both the same like with stock FW
    Now I captured the requests from BK7231N:
    root@laeppilin:/home/uwe# od received_from_OpenBK.txt
    0000000 125130 125130 125130 125130 125130 125130 125130 125130
    *
    0000640 125130 125130 125130 125130 125130

    >>> There was no Response from BL0942
  • #259 20939210
    uchristo
    Level 6  
    Used RealTerm for Testing now. Here's what the original Firmware is doing on UART (Device is NOT connected to mains, just to 3,3V on LM1337 and USBtoUART:

    Initialization
    E0
    78 08 43 2B 08

    Frequent Polling after the Initialization:
    0E


    This is what the BL0942 answers:
    E0
    08 78 09 FA 08 08 08 08 0D 18
    18 08 F8 85 F7 08 08 08 A8 08
    00 08 38 08 EE 08 08 08 08 0D
    18 E8 08 48 08 00 08 08 08 0D
    18 58 08 E8 84 01 08 08 08 A8
    08 00 08 D8 08 DB 08 08 08 08
    0D 18 18 00 F8 00


    With OpenBeken and Startup-Text "backlog startDriver NTP; StartDriver BL0942; PowerSave 1; SetupEnergyStats 1 60 60 "
    The Request from BK7231N will always be:
    58 AA

    and there will be no anwer. I saw that it's possible to enable "Flag 31 - [UART] Enable UART command line". How to use it in Order to send the correct Request for Testing?


    EDIT:
    The Code below shows that it will contact BL0942 with 0x58 0xAA, so that's works as designed in openBeken. But why does original Firmware just sends 0x0E and will get an Answer from BL0942?

    #define BL0942_BAUD_RATE 4800

    #define BL0942_READ_COMMAND 0x58

    void BL0942_SendRequest() {
    UART_InitUART(BL0942_BAUD_RATE);
    UART_SendByte(BL0942_READ_COMMAND);
    UART_SendByte(0xAA);
    }
  • #260 20957896
    Wimmi
    Level 4  
    Hi all,

    the solution for the BL0942 (board CUCO-6Z) in Godsund EP2 is quite easy:

    take baudrate = 9600 for the uart. Then it's running.


    Screenshot of a user interface displaying information about the BL0942 energy device.

    You can check it with small changes in file drv_bl0942.c. Compilation is easiest with the Docker container.

    Shown values above without any calibration, url=https://obrazki.elektroda.pl/4400100600_1707741927.png]Screenshot showing measurement data from a device named obk688C8405.[/url] I only have [started the driver.

    Values are directly pushed via MQTT into HA.

    Cheerio
    Wimmi
  • #261 20958036
    uchristo
    Level 6  
    Well,
    that's pretty cool. I just tried to build using the docker.
    Building the docker image suceeded but when running
    ~/OpenBK7231T_App/docker$ docker run -it -v "$(pwd)/..":/OpenBK7231T_App openbk_build
    or
    ~/OpenBK7231T_App/docker$ docker run -it -v "$(pwd)/..":/OpenBK7231T_App openbk_build --env TARGET_SDKS=OpenBK7231N
    from

    Docker tries to clone the repos and ignores my local changes to OpenBK7231T_App/src/driver/drv_bl0942.c

    I'm no docker-expert btw.....
  • #262 20958073
    p.kaczmarek2
    Moderator Smart Home
    Thank you for bringing this to my attention, @Wimmi

    I've added baud switch to the code:
    https://github.com/openshwprojects/OpenBK7231...mmit/a515a5f0f307ec2ca993e3794c4c0858d6877f25
    In the lastest update, you can set baud 9600 by using startDriver command in the following manner:
    
    startDriver BL0942 9600
    
    Helpful post? Buy me a coffee.
  • #263 20958094
    Wimmi
    Level 4  
    Hi,

    many thanks back for integrating the baud parameter into the driver!
    And many, many thanks for this great alternative firmware! It's really great!

    By the way, calibration of the CUCO-6Z seems also work well. Due to lack of 60W bulb, I used a 40W bulb, but with calibration data of 60W ;-) Screenshot of an energy management application showing values for frequency, voltage, current, and power. ( 230 V, 0.26 A, 60 W) as given in Web-App. The following picture shows the situation after calibration with 40W bulb. Reasonable values (except the power value of 60 W, of course.) Screenshot displaying measurement data including power, voltage, and frequency parameters.

    Cheerio,

    Wimmi

    Added after 14 [minutes]:

    >>20958036
    Hi uchristo,

    misaligned parameter in your command. Start it with this command:

    docker run -it --env TARGET_SDKS=OpenBK7231N -v "$(pwd)/..":/OpenBK7231T_App openbk_build

    Cheerio

    Wimmi
  • #264 20959133
    uchristo
    Level 6  
    When I sorted the parameter out, the public build 458 was already online. Great service @p.kaczmarek2 !!!
    It's working like a charm now. I calibrated with 40Watt light bulb aswell and monitored with my wattmeter, so there are reasonable Results now.
  • #265 20959137
    p.kaczmarek2
    Moderator Smart Home
    Thanks ,can anyone now share the device template for that alternate baud smart socket? With a model name, a photo, etc? I want to add it to:
    https://openbekeniot.github.io/webapp/devicesList.html
    Helpful post? Buy me a coffee.
  • #266 20959163
    uchristo
    Level 6  
    I've taken some Pics and will upload them. Is there a easy way to extract a template from a working device?
  • #267 20959193
    p.kaczmarek2
    Moderator Smart Home
    Open the Web App and copy-paste the JSON
    Helpful post? Buy me a coffee.
  • #268 20959216
    uchristo
    Level 6  
    Pin8 + 9 Combinations:
    Pin8 High, Pin9 Low: LED green
    Pin8 Low, Pin9 High: LED blue
    Pin8 Low, Pin9 Low: LED turquoise
    Pin8 High, Pin9 High: LED OFF

    Code: JSON
    Log in, to see the code


    Close-up of CUCO-Z6-N circuit board with BL0942 integrated circuit. Close-up of an electronic module with components on a circuit board.
  • #269 21011312
    Dark Man
    Level 13  
    Hi
    I`m back after a few months with a working clone socket that started acting weird in terms of energy measurements read with the relay turned on:
    1. With a 40W bulb connected and calibrated, it shows well, but of course the results jump a bit, although I think the jumps are a bit too big
    2. Without load connected, it mostly shows 0 everywhere
    2. When connecting a switching power supply from a battery charger (consumption per wattmeter), it shows a voltage of 30-45V and a power of about 12W and all results jump
    User interface screen showing electric energy measurements. Control panel of an outlet showing energy parameters. User interface of a socket displaying voltage and energy consumption statistics.

    I tried to solder the contacts from the measuring system and the Bekens module, but it didn`t help.
    
    {
      "vendor": "Tuya",
      "bDetailed": "0",
      "name": "Full Device Name Here",
      "model": "enter short model name here",
      "chip": "BK7231N",
      "board": "TODO",
      "flags": "1073742848",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "6": "BL0937CF;0",
        "7": "BL0937CF1;0",
        "8": "WifiLED;1",
        "10": "Btn;1",
        "23": "Btn;1",
        "24": "BL0937SEL;0",
        "26": "Rel;1"
      },
      "command": "backlog PowerSave 1; startDriver NTP; startDriver BL0937;ntp_setServer 192.168.5.5; SetupEnergyStats 1 60 5; VCPPrecision 0 1 1 2; VCPPublishThreshold 10 0.2 10 0.1; SetStartValue 1 0",
      "image": "https://obrazki.elektroda.pl/YOUR_IMAGE.jpg",
      "wiki": "https://www.elektroda.com/rtvforum/topic_YOUR_TOPIC.html"
    }


    Any ideas?
  • #270 21011326
    p.kaczmarek2
    Moderator Smart Home
    Do you mean that you updated and the new version broke something?

    If these are not problems after OTA, then the capacitor may be to blame...
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around the Tuya LSPA9 smart socket, focusing on its teardown, flashing OpenBeken firmware, and configuring the BL0942 energy metering chip. Users share their experiences with various versions of the LSPA9, including issues with calibration, communication protocols (UART vs. SPI), and the stability of energy readings. Solutions include using specific commands for calibration, adjusting baud rates, and troubleshooting connectivity issues. The conversation also touches on the integration of these devices with Home Assistant and the challenges faced in ensuring accurate power measurements and MQTT communication.
Summary generated by the language model.
ADVERTISEMENT