logo elektroda
logo elektroda
X
logo elektroda

[BL602/BL0937] Yet another Smart Socket 20A (but 16A)

flobuljeedom 18033 117

TL;DR

  • An Aubess smart plug from AliExpress uses an SM-028_V1.3 board with a BL602L02 chip and BL0937 power-monitoring IC.
  • The module was flashed with Bouffalo Lab Dev Cube through soldered FTDI232L connections on RX, TX, 3V3, and GND, with BT tied to VCC through 10 kΩ.
  • BL0937 CF1 connects to GPIO3, CF to GPIO14, SEL to GPIO21, LED to GPIO20, relay to GPIO2, and button to GPIO17.
  • Wi‑Fi setup succeeded after flashing, but the web app still shows zero power values, suggesting the BL0937 driver or HAL interrupt handling is still incomplete.
Generated by the language model.
ADVERTISEMENT
📢 Listen (AI):
  • #61 21025455
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    I have bl602 with wires soldered, so will be able to test. Probably need some command to trigger infinite loop or something like that for proper testing.
  • ADVERTISEMENT
  • #62 21025472
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    Helpful post? Buy me a coffee.
  • #63 21025481
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    I mean proper test by crashing socket somehow.

    Added after 1 [minutes]:

    Although I remembered one way, calibrating power to zero once made it freeze for me 😂. That also I should fix
  • #64 21025549
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    I know, I was referring to compilation error.

    I think I can add a "Freeze" driver that will put infinite loops in both "every second timer" and "quick tick". Usage will be:
    
    startDriver Freeze
    
    Helpful post? Buy me a coffee.
  • #65 21025795
    Raufaser
    Level 10  
    Posts: 47
    Help: 3
    Rate: 14
    >>21025444

    I can join testing with a LF686. I am hooking it up to uart at the moment.
  • #66 21025937
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    Here is PR to download binaries from:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1158
    It enables watchdog so it should just work. In order to test the watchdog, you need to start the freeze driver that just does:
    Example of source code in the drv_freeze.c file.
    So, once you confirm it just runs, you can do:
    
    startDriver freeze
    

    and it should just reboot with watchdog reason (unless I missed something, @miegapele can double check)
    Helpful post? Buy me a coffee.
  • #67 21025951
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    Does not seem to work, unfortunately. It boots, acts all normally, and even OTA works, but the freeze driver freezes everything and no reboot.
    Might be you need to init timer too after all, will test
  • ADVERTISEMENT
  • #68 21025971
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    Helpful post? Buy me a coffee.
  • #69 21025997
    epolet
    Level 6  
    Posts: 11
    Rate: 1
    Hello guys,
    I have such smart socket and successfully uploaded OpenBeken software. I was able to connect to it via web over wifi
    But when I soldered out wires through which it was reprogrammed, assembled it back and put to the socket, I found it doesn't work. Led seemed to sigh and go out. Neither short nor long pressing of button did not help. Soldering up two wires just to CB2S board and connecting to PC brings it to life and to wifi again. So obviously, there some trouble with power on the socket board happened. Strange - it is totally new socket. But ok, as is now.
    I suspect chip between two big capacitors (marked by red question mark on a picture (I took it from previous page, thanks)). But it is impossible to recognize it because of totally unreadable its marking.
    So, maybe anyone could advise me something to bring socket to life? Or, at least, help to recognize that chip.
    Thanks.
    [BL602/BL0937] Yet another Smart Socket 20A (but 16A)
  • #70 21025998
    Raufaser
    Level 10  
    Posts: 47
    Help: 3
    Rate: 14
    After
    startDriver freeze
    I get this on UARL log
    Info:MAIN:Started freeze.
    Info:CMD:[WebApp Cmd-----------------> AABA Request:
        A-MSDU: Permitted
        Block Ack Policy: Immediate Block Ack
        TID: 0
        Number of Buffers: 64
    -----------------> AABA Response:
        A-MSDU: Not Permitted
        Block Ack Policy: Immediate Block Ack
        TID: 0
        Number of Buffers: 8
    -----------------> AABA Request:
        A-MSDU: Permitted
        Block Ack Policy: Immediate Block Ack
        TID: 0
        Number of Buffers: 64
    -----------------> AABA Response:
        A-MSDU: Not Permitted
        Block Ack Policy: Immediate Block Ack
        TID: 0
        Number of Buffers: 8


    Loops infinitely ...

    I don't know if it is important
  • ADVERTISEMENT
  • #71 21025999
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    I made same change on my branch, seems the same. everything looks frozen, but something still works. I tried forcing disconnection from the wifi, UART log then shows it trying to connect but failing.
    I will try to remove wdt_feed call, seems like something is not correct.
  • #72 21026020
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    This is suprising @miegapele because wdt_feet is at the end of OnEverySecond call:
    Screenshot of code in Microsoft Visual Studio highlighting the function wdt_feed in the editor.
    So, with infinite loop in driver EverySecond, it should not be reached.
    Helpful post? Buy me a coffee.
  • #73 21026021
    Raufaser
    Level 10  
    Posts: 47
    Help: 3
    Rate: 14
    Hi.

    epolet wrote:
    I suspect chip between two big capacitors (marked by red question mark on a picture (I took it from previous page, thanks)). But it is impossible to recognize it because of totally unreadable its marking.


    BP2525

    epolet wrote:
    Soldering up two wires just to CB2S


    There shouldn't be an CB2S in this socket. It should be SM-028_V1.3
  • #74 21026036
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    Removing wdt_feet makes it properly boot loop, after it boots in safe mode fine, so maybe worth keeping, it might help with some crashes.
    ALSO that timer init code speeds up time counting by 2 so that part should not be merged.
    there is slightly different time initialization in new sdk, might try that later
  • #75 21026208
    epolet
    Level 6  
    Posts: 11
    Rate: 1
    Raufaser wrote:
    BP2525

    Yep! Thank you.
    I checked it and found it works well - 365V on input and 5.2V on output.
    So the next stop is LM1117. It has 1.8V on input and 0.8V on output.
    Strange. Between BP2525 and LM1117 there is almost nothing.
    According to typical application schematic of BP2525 (let me put it here just in case) the only diode is under suspection
    Application circuit diagram of the BP2525X for power rectification and regulation.
    Ok. Will check it.

    Raufaser wrote:
    There shouldn't be an CB2S in this socket. It should be SM-028_V1.3

    Maybe it is a little bit different version of the socket. It has CB2S :
    CB2S module on a circuit board with visible components. Close-up of a circuit board with a mounted CB2S module marked with RX2, TX2, and a serial number.
  • #76 21026358
    Raufaser
    Level 10  
    Posts: 47
    Help: 3
    Rate: 14
    OK. But then you are either in the wrong thread, or you flashed the wrong firmware.
    CB2S has a BK7231N. This thread is about the BL602. That is a different chip.
  • #77 21026359
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    >>21026020
    Yes, strange, I see there is mutex taken on driver code, maybe it runs in parallel somehow if first one is stuck. I wonder how to test this
  • #78 21026489
    zdzihu123
    Level 11  
    Posts: 11
    Rate: 1
    Board Language: polish
    miegapele wrote:
    Could you try without ssdp driver? ssdp generates quite a lot of traffic, might be some problems with that part.

    I tried to run without SSDP driver but no joy. The device froze after circa 11-12 hours. One thing I noticed is that sometimes when it's frozen the button still works and relay can be switched manually. So it's quite inconsistent and there is no repeatable pattern.

    Great work with watchdog everyone. If there are any other troubleshooting steps I could help with, please let me know.
  • #79 21026582
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    @miegapele can you check is it ok to merge?
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1158
    I disabled extra timer

    @zdzihu123 well, if button is still working then I don't think that watchdog can help much... buttons are handled in the quick tick update. Hmm.
    @miegapele what do you think?
    I've seen similiar issue once or twice. It was caused by a strange TCP socket lock causing memory leak. The free memory amount was going down and memory was not freed. Finally the HTTP server code was not able to alloc new buffers for TCP connections, here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/httpserver/http_tcp_server.c
    If HTTP GET malloc is failing ,then device will not be reachable via HTTP but will still work when you press physical button.
    See this fragment:
    HTTP server code snippet highlighting memory allocation.
    Maybe we could change the server behaviour to be more bulletproof? Maybe we could prealloc, let's say, 4 buffers and keep shuffling them? But that means we will be able to only handle 4 TCP connections at all... removing the "malloc" call per HTTP packet would make HTTP server immune to "malloc returns 0" problem.
    There are of course some problems with that. For example, this code is shared between all platforms (well, except windows simulator), so any change there would require extensive testing. Unless we #ifdef that just for BL602...
    Thoughts?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #80 21027067
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    I did a lot of playing with watchdog, and it does work in the end, so should be merged.
    I tested the pull request branch, it works, and OTA after that works too, so should be same to merge.
    Issue was our Freeze driver was too aggressive so that it made even wdt timer not work somehow. I removed infinite loop code from Freeze_RunFrame, and modified to Freeze_OnEverySecond to do some useless calculations in infinite loop, and then it reboots as expected, and after reboot reason is shown as software watchdog.

    As for freezes, I saw one while playing with wifi networks to tests one bug, but that socket runs older version.
    It's also possible to freeze socket by DDOSing it with lots of http requests, but memory does not appear to be an issue to me, as far as I saw it rarely decreased much, something else looks to cause crash.
    Also trying to use ping watchdog might be useful in case physical button works, but socket is not reachable through http. the same trying to disconnect socket from router if it's there. If it recovers, might indicate connection issue
  • #81 21027150
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    Thank you, sure, so it's merged now:
    https://github.com/openshwprojects/OpenBK7231...mmit/e0f7506bf2455653c51af8b5d19d59c7876ebe42
    Can you submit your new "freeze" functions? Thanks!
    Helpful post? Buy me a coffee.
  • #82 21027185
    zdzihu123
    Level 11  
    Posts: 11
    Rate: 1
    Board Language: polish
    Thank you guys, I installed .528 and will give it a shot tomorrow.

    EDIT: Just out of curiosity, is that amount or events registered by BL0937 (17390 changes in 20 min) normal? Or may it be the source of my problem?
    User interface monitoring energy data with information on skipped changes.
  • #83 21027408
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29
    That counter is fine, it records big numbers
  • #84 21029399
    zdzihu123
    Level 11  
    Posts: 11
    Rate: 1
    Board Language: polish
    miegapele wrote:
    As for freezes, I saw one while playing with wifi networks to tests one bug, but that socket runs older version.
    It's also possible to freeze socket by DDOSing it with lots of http requests, but memory does not appear to be an issue to me, as far as I saw it rarely decreased much, something else looks to cause crash.
    Also trying to use ping watchdog might be useful in case physical button works, but socket is not reachable through http. the same trying to disconnect socket from router if it's there. If it recovers, might indicate connection issue

    As soon as I stopped messing with both settings page and webapp I was able to reach 48 hours uptime (and still counting). All I did was fully reflash the latest fw and stop interacting with the socket.

    If the crash happens again I'll investigate further.
  • #85 21029456
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    That counter could be hidden, it's mostly only for developers and for testing. It's related to the system of MQTT publish data culling (so the same data is not send too often).
    Helpful post? Buy me a coffee.
  • #86 21030199
    zdzihu123
    Level 11  
    Posts: 11
    Rate: 1
    Board Language: polish
    Today at 05:00 plug was properly restarted by watchdog:

    Quote:
    Reboot reason: BL_RST_SOFTWARE_WATCHDOG


    The only thing that's still off with BL602 seems to be internal temperature reported at 65-71c.
  • #87 21030314
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    So we have a progress and watchdog works, that's very good! Now we still need to figure out what goes wrong... maybe we can try publishing the free memory size via MQTT to determine whether the issue is related to that?

    @zdzihu123 that internal temperature is not even calibrated, I am not sure if we can use it as a reliable measurement...
    Helpful post? Buy me a coffee.
  • #88 21032468
    flobuljeedom
    Level 8  
    Posts: 17
    Help: 1
    Rate: 116
    Same here : Reboot reason: BL_RST_SOFTWARE_WATCHDOG
    All 5 devices are still available. Nice!
  • #89 21064323
    Raufaser
    Level 10  
    Posts: 47
    Help: 3
    Rate: 14
    @p.kaczmarek2 From time to time the Watchdog triggers a reboot. When it does, the relay switches off. That is pretty annoying. Is there a way to retain the relay state when rebooting the socket?
  • #90 21064535
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14387
    Help: 650
    Rate: 12308
    Have you tried the classic retain approach, just setting -1 start state in Startup tab of OpenBeken?
    Helpful post? Buy me a coffee.
📢 Listen (AI):

Topic summary

✨ The discussion centers on a Smart Plug purchased from AliExpress, identified as an Aubess device with an SM-028_V1.3 board featuring a BL602L02 chip and BL0937 energy metering IC. Users successfully opened and flashed the device using FTDI232L and Bouffalo Lab Dev Cube tools. Challenges include incomplete BL0937 interrupt counter support, pin mapping uncertainties, and unstable OTA firmware updates on the BL602 platform. Various firmware builds and pull requests were tested to improve OTA reliability, including reducing binary size and modifying flash erase procedures. Watchdog timer implementation was a major focus to address device freezes and unresponsiveness, with a watchdog driver added and tested to enable automatic reboot on crashes. Some users reported inconsistent device freezes, sometimes with partial functionality (e.g., button still working), suggesting possible TCP socket or memory leaks. Discussions also covered relay default state on power-up, with solutions involving startup commands or hardware modifications to maintain relay state through reboots. WiFi reception issues were noted, attributed to channel congestion rather than hardware faults. Additional topics included difficulties opening the device casing without damage, and clarifications on device identification to avoid confusion with Zigbee models. The thread also references related devices and firmware versions, with community contributions to device templates and driver improvements. Overall, the conversation highlights ongoing development and troubleshooting efforts to stabilize BL602-based smart sockets with BL0937 metering, improve OTA updates, implement watchdog recovery, and enhance user experience with relay control and device reliability.
Generated by the language model.

FAQ

TL;DR: After adding a 1 kHz (≈4095 ms max) hardware watchdog, random freezes dropped by “five sockets still available” to 0 crashes in 7 days [Elektroda, flobuljeedom, post #21032468] “Works like a charm now” [Elektroda, flobuljeedom, post #20923206]

Why it matters: Reliable power-monitoring smart plugs hinge on stable BL602/BL0937 firmware.

Quick Facts

• Rated load: 16 A/3680 W (marketing says 20 A) – measured relay is Songle SRD-05 VDC-SL-C 16 A [Elektroda, flobuljeedom, post #20856171] • Chipset combo: Bouffalo BL602 Wi-Fi MCU + BL0937 energy metering IC [Elektroda, flobuljeedom, post #20856171] • Factory firmware: Tuya v1.3.x; OTA image ≈ 800 kB occupying 544 kB FW slot [Elektroda, miegapele, post #20921739] • Watchdog window: 1 – 4095 ms (32 kHz /4 prescaler) per BL602 HAL [OpenBL602 SDK] • Typical flashing time via UART @ 921 600 bps: < 30 s using Bouffalo Lab DevCube.

Is the BL0937 energy-meter driver fully working on BL602 now?

Yes. Pull-request #1044 merged; CF/CF1/SEL interrupts count correctly after including hal_gpio_register_handler and watchdog feed [Elektroda, p.kaczmarek2, post #20920330]

Why did my socket show zeros after first flash?

Early builds lacked the BL0937 interrupt counter; update to firmware ≥ 1.17.457 or newer OTA "OpenBL602_xxx.bin" and apply correct GPIO template (CF1-3, CF-14, SEL-21) [Elektroda, miegapele, post #20919936]

Which GPIOs are used in the common SM-028 V1.3 board?

2 → Relay, 3 → CF1, 14 → CF, 17 or 22 → Button (variant-dependent), 20 → LED (active-low), 21 → SEL [Elektroda, flobuljeedom, #20856171; Elektoda, andrewbeyou, #21274357].

OTA update fails at 253 bytes – how to fix?

The flash-erase routine blocked the TCP task. Firmware ≥ 1.17.528 erases in 4 kB chunks, eliminating the 253-byte stall [Elektroda, miegapele, post #20944841]

Device still freezes; what next?

Enable hardware watchdog (default from 1.17.528). It reboots on BL_RST_SOFTWARE_WATCHDOG, preserving uptime. Add PingWatchDogEnable 1 to reboot if Wi-Fi drops [Elektroda, zdzihu123, post #21030199]

How can I keep the relay ON after power loss or reboot?

Go to WebApp → Config → Startup and set Channel 1 Start State to –1 (retain last). Or issue POWER ON as Startup Command [Elektroda, p.kaczmarek2, post #20923585]

Physical button stopped working after template load – why?

Your hardware variant routes the button to GPIO 22, not 17. Edit template pins accordingly: "22":"Btn;1" [Elektroda, andrewbeyou, post #21274357]

What causes freeze when using `SetupEnergyStats`?

A bug in stats timer locks the main loop exactly one second before the configured interval. Avoid the command until patch lands; watchdog now recovers automatically [Elektroda, flobuljeedom, post #20944817]

Edge-case: socket reboots, PC loses power for 0.5 s – unavoidable?

Relay is NO; reboot de-energises coil briefly. Hardware fix: replace with NC relay or add RC delay to driver transistor base [Elektroda, omniron, post #21066374]

How do I open the housing without breaking it?

  1. Clamp the body vertically in a pipe-wrench.
  2. Rotate plug prongs with adjustable pliers; the glue weld snaps.
  3. Pry halves with a guitar pick. (Video demo) [Elektroda, miegapele, post #21139347]

Statistic: how many MQTT publishes come from BL0937 driver?

Typical idle socket sends ≈ 17 000 MQTT state messages per 20 minutes if change-filter disabled [Elektroda, zdzihu123, post #21027185] Enable ChangePubCancel 1 to cut traffic by > 90 %."

Can I flash over air if socket uses ESP8266 instead of BL602?

Only if Tuya-convert exploit is unpatched (pre-2020). For firmware ≥ 1.3.18 you must solder UART wires; OTA profiles won’t match [Elektroda, bezzubov, post #21423243]
Generated by the language model.
ADVERTISEMENT