logo elektroda
logo elektroda
X
logo elektroda

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

flobuljeedom 13728 116
ADVERTISEMENT
  • I bought a Smart Plug from Aliexpress: https://fr.aliexpress.com/item/1005005790622741
    They are named Aubess on the website, but not on the packaging or on the socket.

    Smart plug and its packaging from AliExpress. Smart plug and its packaging on a dark surface.

    Easy to open with pliers.
    Dismantled Smart Plug with visible circuit board.

    Contains an SM-028_V1.3 with a BL602L02 chip.
    Close-up of SM-028_V1.3 circuit board in a smart plug with two metal prongs.
    And BL0937.
    Close-up of the interior of a smart plug showing the circuit board and electronic components.

    I soldered cables in the back of the SM-028_V1.3 between:
    SM-028_V1.3 RX -> FTDI232L TX
    SM-028_V1.3 TX -> FTDI232L RX
    SM-028_V1.3 3V3 -> FTDI232L VCC (on 3V3)
    SM-028_V1.3 GND -> FTDI232L GND
    SM-028_V1.3 BT -> to a 10Kohm to VCC

    And flashed it with Bouffalo Lab Dev Cube
    Firmware flashing interface of Bouffalo Lab Dev Cube software

    Then I disconnected all wires, remounted the socket, and put it on the plug.
    And TADA! I entered my SSID and password and rebooted it.

    Smart plug application interface on computer screen

    I checked the circuit wiring on the PCB between BL0937 and BL602:
    BL0937 CF1 -> BL602 GPIO3
    BL0937 CF -> BL602 GPIO14
    BL0937 SEL -> BL602 GPIO21
    LED -> BL602 GPIO20
    Relay -> BL602 GPIO2
    Button -> BL602 GPIO17

    (don't bother yet to check the LED and button) => TODO

    But once configured, nothing showed up in the Web app (all values are zero)
    Screenshot of OpenBL602 user interface displaying power data.

    Current working template :
    Code: JSON
    Log in, to see the code

    I saw some discussions about the BL0937 driver on BL602 not working because of HAL interrupt falling edge counter.
    Is it already implemented?

    Cool? Ranking DIY
    About Author
    flobuljeedom
    Level 7  
    Offline 
    flobuljeedom wrote 16 posts with rating 83, helped 1 times. Live in city Paris. Been with us since 2023 year.
  • ADVERTISEMENT
  • #2 20858308
    p.kaczmarek2
    Moderator Smart Home
    Sadly the interrupt counter for BL0937 is still missing. I think there is an unfinished version:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/862
    Btw, can you also post a template for this device from the Web App?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #3 20858324
    flobuljeedom
    Level 7  

    I just updated the post with template and finals BL602 GPIO.
  • #4 20879349
    flobuljeedom
    Level 7  
    >>20858308
    Thanks for the info.

    I tried correcting it, but I am not competent enough in C to include those changes.
  • #5 20919173
    miegapele
    Level 15  
    Got what looks like very similar socket, only button is on other pin, managed to solder and flash ( only destroyed one). Trying to add bl0937 support
  • #6 20919182
    p.kaczmarek2
    Moderator Smart Home
    I saw a PR, but is it working? I don't even have that kind of socket to check. Hmm
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #7 20919188
    miegapele
    Level 15  
    No it's not, doesn't even compile, but I got builds working on my fork, so trying to make it work
  • #8 20919278
    p.kaczmarek2
    Moderator Smart Home
    It seems you are getting errors like:
    
    /home/runner/work/OpenBK7231T_App/OpenBK7231T_App/sdk/OpenBL602/customer_app/bl602_sharedApp/bl602_sharedApp/shared/src/driver/drv_bl0937.c:155:9: error: implicit declaration of function 'hal_gpio_register_handler' [-Werror=implicit-function-declaration]
             hal_gpio_register_handler(HlwCf1Interrupt, GPIO_HLW_CF1, GPIO_INT_CONTROL_ASYNC, GPIO_INT_TRIG_NEG_LEVEL, (void*) NULL)
    

    You can search for this function name here:
    https://github.com/search?q=repo%3Aopenshwpro...enBL602%20hal_gpio_register_handler&type=code
    It seems that you need to include this header:
    
    components/hal_drv/bl602_hal/hal_gpio.h
    
    Helpful post? Buy me a coffee.
  • #9 20919393
    miegapele
    Level 15  
    Yes added that to try, but nothing happens, values always zero. No sure what else to try, could it be that some pin mapping is required like in W600?
  • #10 20919426
    p.kaczmarek2
    Moderator Smart Home
    Here is pins code for BL602:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/hal/bl602/hal_pins_bl602.c
    From what I can see, there are no pin mappings there.

    So, are you sure that those functions:
    Code: C / C++
    Log in, to see the code

    are not called?

    Here is some random code from SDK:
    Code: C / C++
    Log in, to see the code

    They are using bl_gpio_enable_input first, maybe you can try that?
    Helpful post? Buy me a coffee.
  • #11 20919448
    miegapele
    Level 15  
    bl_gpio_enable_input should already be called from the driver via HAL_PIN_Setup_Input_Pullup(GPIO_HLW_CF1);
  • #12 20919519
    p.kaczmarek2
    Moderator Smart Home
    Wait a minute. I had a report that during last few updates OTA has broken. Is BL602 OTA working for you? It would mean that we need to reduce BL602 binary again.
    Helpful post? Buy me a coffee.
  • #13 20919536
    miegapele
    Level 15  
    It is working, but seems not 100% reliably. Sometimes I got starting OTA... and nothing happened, but after few retries it worked. This is with builds from my branch.
  • #14 20919561
    p.kaczmarek2
    Moderator Smart Home
    Can you print the values of variables increased in the interrupt? Are they really not changing?

    Have you set correct GPIO for the CF and CFI pins?

    Are variables set as volatile?
    Helpful post? Buy me a coffee.
  • #15 20919632
    miegapele
    Level 15  
    Actually made some progress with latest try. Now getting some values at least :)
    [BL602/BL0937] Yet another Smart Socket 20A (but 16A)
    So hopefully it's now just wrong pins somewhere.
    Will continue tomorrow.

    But the OTA is real problem it seems with latest try, I had a lot of trouble to upload. Tried various things, tried downgrading, until finally it worked. But took like 20 tries or more
  • #16 20919656
    p.kaczmarek2
    Moderator Smart Home
    I suspect it;'s caused by too large flash binary, but I am not sure. I will try to reduce the size by stripping features that are not useful on BL602:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1044
    Can you try if binaries from my PR works better for you, once it compiles fine?
    Helpful post? Buy me a coffee.
  • #17 20919936
    miegapele
    Level 15  
    Good news, got it working. Now there is two things to solve here, I think these long sdk includes should not be here, it should be moved to HAL layer I think. However, not sure how interrupt stuff for BK0931 and W600 works, looks to be included by some magic.
    Another issue is that there is no way in sdk to proper "shutdown" pins. Interrupt can be disabled, but it will still leave handler registered, and taking memory, we could add something like hal_gpio_unregister_handler to sdk, but not sure...
    Screen displaying power data for the OpenBL602_4C44B4D5 device.

    Regarding that reduced size update, it only reduces memory by like 1kb, is that right?
    I tried, but I'm not sure how it should work, if I have reduce memory version, any other version seems to install better, but still like only half the time. If I have any other version installing reduce memory version is almost always troublesome.
  • #18 20920330
    p.kaczmarek2
    Moderator Smart Home
    That's very good news, nice job.

    miegapele wrote:

    Another issue is that there is no way in sdk to proper "shutdown" pins. Interrupt can be disabled, but it will still leave handler registered, and taking memory, we could add something like hal_gpio_unregister_handler to sdk, but not sure...

    We have source for register function, it seems to be using a linked list:
    Code: C / C++
    Log in, to see the code


    miegapele wrote:

    Regarding that reduced size update, it only reduces memory by like 1kb, is that right?[/url]

    That's for a start, I need to think about it what else can we strip, do you have any ideas?

    I have merged your PR, if you have any improvements, please open another one.
    Helpful post? Buy me a coffee.
  • #19 20920451
    miegapele
    Level 15  
    Is the binary size really the issue here, seems little bit strange, because it should never work if there is not enough space. Now it works sometimes, so maybe actual ram use is the issue?
    Also, is there flash layout described somewhere, binary looks to be 800kb, while full flash is 2mb, so should still fit.
  • #20 20920505
    p.kaczmarek2
    Moderator Smart Home
    I'm just speaking from experience. We had OTA issue back then:
    https://github.com/openshwprojects/OpenBK7231T_App/issues/745
    It was solved by reducing binary size. Do you think the cause may be different today?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #21 20920545
    miegapele
    Level 15  
    I don't know, but it's strange. Where is OTA code for BL602? I'm unable to figure out how it works.
  • #22 20920764
    p.kaczmarek2
    Moderator Smart Home
    Usually SDKs are doing OTA that requires setting up external HTTP server. It's problematic, so we decided to do it the other way, through the web browser.

    Our OTA wrapper is in the rest_interface.c file. Function is called:
    
    static int http_rest_post_flash(http_request_t* request, int startaddr, int maxaddr) {
    

    as it was used as generic flash access, but for most platforms it's OTA-only.

    There is a large #ifdef block per platform, but the concept is usually the same. OpenBeken receives a POST data (OBK is acting as HTTP server), and while receiving, the data is written to given space in flash memory.
    After the write is done, device is rebooted and the SDK code of Bouffallo labs finished the update.

    Maybe we could try to add a rtos delay here:
    
    		total += writelen;
    		startaddr += writelen;
    		towrite -= writelen;
    


    I know that OTA could be organized better, but you know, a larger change would require testing on all 5 or so supported platforms...
    Helpful post? Buy me a coffee.
  • #23 20921739
    miegapele
    Level 15  
    Tried to look at the UART log for failed flash. It seems to always end with Flash takes 253. and then nothing until connection is reset.
    Does flash support such unaligned writes?

    [FW] Timer is past due to flash operation. Try to fix is shown also for sucesful writes, so probably ok.

    [20:56:11.130] - [MTD] >>>>>> Hanlde info Dump >>>>>>
          name FW
          id 0
          offset 0x000d8000(884736)
          size 0x00088000(544Kbytes)
          xip_addr 0x00000000
    [MTD] <<<<<< Hanlde info End <<<<<<
    Starting OTA test. OTA bin addr is 0x4202ab00, incoming len 623
    [OTA] [TEST] activeID is 0
    Starting OTA test. OTA size is 557056
    [OTA] [TEST] activeIndex is 0, use OTA address=000d8000
    [OTA] [TEST] Erase flash with size 557056...update mfg table.
    ====================
    ====================
    update mfg table.
    [20:56:12.920] - 
    -------------------[FW] Timer is past due to flash operation. Try to fix
    
    -------------------[FW] Timer is past due to flash operation. Try to fix
    
    -------------------[FW] Timer is past due to flash operation. Try to fix
    
    -------------------[FW] Timer is past due to flash operation. Try to fix
    Done
    Header takes 512. Flash takes 111. Info:MAIN:Time 132, idle 0/s, free 96352, MQTT 0(8), bWifi 1, secondsWithNoPing 61, socks 4/21 
    Flash takes 1022. Flash takes 1022. Flash takes 253.
  • #24 20922048
    hojnikb
    Level 11  
    Does anyone experience poor WiFi reception on these device? Out of 4 i currently have, all seems to work really poorly, unless they're in the same room as the WiFi router.

    Is this common with bl602 devices or are just my examples that poor?
  • #25 20923206
    flobuljeedom
    Level 7  
    Nice job, @miegapele.
    Works like a charms now. Even RSSI is displayed.

    @hojnikb
    No issue so far for me.
  • #26 20923286
    p.kaczmarek2
    Moderator Smart Home
    Maybe we could reduce the stress during OTA by trimming the extensive logging of every data chunk copied
    Helpful post? Buy me a coffee.
  • #27 20923430
    miegapele
    Level 15  
    I am trying to add rtos_delay_milliseconds(10) so the ame place for BL602, to see if it helps. Logs are only to uart with print so should not matter.
  • #28 20923508
    hojnikb
    Level 11  
    flobuljeedom wrote:
    Nice job, @miegapele.
    Works like a charms now. Even RSSI is displayed.

    @hojnikb
    No issue so far for me.


    I think i might have found the issue. I had a pretty serious congestion on the channel those plugs were connecting. Other devices don't seem to care as much, but BL602 seems to be more sensitive to that. Once i've moved to a more free channel, the issue went away, hopefully for good.

    On a unrelated note;

    How to set the relay to be ON by default or at least ON when device is powerred on? On a power outage (or if you plug the thing in and out) the relay stays OFF, before you manually set it ON.
  • #29 20923585
    p.kaczmarek2
    Moderator Smart Home
    hojnikb wrote:

    How to set the relay to be ON by default or at least ON when device is powerred on? On a power outage (or if you plug the thing in and out) the relay stays OFF, before you manually set it ON.

    There are multiple ways to do it.
    1. via gui:
    Screenshot of the BK7231T_WB3S_WhiteStripWindows user interface for setting start values.
    2. via startup command - you can enter there something like:
    
    POWER ON
    

    or OBK syntax:
    
    setChannel 1 1
    

    3. via autoexec.bat scripting (similiar to startup command, but not available on BL602 yet)

    Added after 6 [minutes]:

    Btw, the same question is in our FAQ:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/faq.md

    Screenshot of OpenBK7231T project's FAQ documentation with questions and answers about device configuration.
    Helpful post? Buy me a coffee.
  • #30 20923793
    miegapele
    Level 15  
    Tried various delays, but nothing helped, still not really reliable update. However i looks like if it fails it always fails after receiving 253 bytes, writing them, and then stuck receiving more.
    What is helping somewhat seems to be:
    1. Uploading immediately after first failure (but don't try third time, that usually crashes chip, and only way to recover is to reconnect power)
    2. Stopping logs seems to help too.

    Added after 1 [hours] 35 [minutes]:

    I do see RSSI is published only once, at boot. Ideally it should be published every minute or 5.

Topic summary

The discussion revolves around the BL602/BL0937 smart socket, specifically a model identified as SM-028_V1.3. Users share experiences related to flashing firmware, troubleshooting connectivity issues, and implementing features like energy monitoring. Key challenges include OTA (Over-The-Air) update reliability, GPIO pin configuration, and device freezing after extended use. Solutions discussed include the implementation of a watchdog timer to prevent device freezes, adjustments to the BL0937 driver, and various methods to retain relay states during reboots. Users also explore the physical disassembly of the socket for flashing and the differences between Zigbee and WiFi models.
Summary generated by the language model.
ADVERTISEMENT