logo elektroda
logo elektroda
X
logo elektroda

Flashing OpenBeken Firmware on WL2S Module with Lightning LN882HK Chip for ELIVCO LSPA9

sithyoda 33822 180
ADVERTISEMENT
  • #121 20914959
    sweetlilmre
    Level 9  

    divadiow wrote:
    Somehow I messed up the wifi and it was no longer broadcasting OpenLNxxx, even after re-flashing and reboots. Flashing back to stock also made it discoverable in the Cozylife app (maybe this is just the bluetooth bit?), but it would not complete the setup on any of my 2.4Ghz networks (always with wifi setup failed type error in app). Switched firmware back and forth a few times.

    Finally fixed with an erase of flash then a fresh OpenLN flash.

    -power up with BOOT low as normal
    -switch to RAMCODE mode with
    LN882H_CMD_Tool.exe COM9 download ram 0x20000000 .ConfigLN882H_RAM_BIN.bin

    -confirm boot mode changed to ramcode mode with
    LN882H_CMD_Tool.exe COM9 mode read

    -erase all flash with
    LN882H_CMD_Tool.exe COM9 flash erase_all

    -flash OpenLN as normal with
    LN882H_CMD_Tool.exe COM9 download flash 2000000 0x0 flashimage.bin


    Added after 19 [minutes]:

    different mac address now

    Screenshot of OpenLN882H_C25E1088 interface with configuration options.


    Good work!
    The MAC addresses are generated from random data after a flash erase (1 MAC for AP, 1 for STA).

    Another way to get into RAMCODE mode is to issue a "read_with_download" command. This will load the RAMCODE for you.
    LN882H_CMD_Tool.exe COM9 flash read_with_download 0x 0x10


    STA data is stored in flash, so I guess somehow, flash got overwritten between different flashes and corrupted.
    Full erase causes a "factory reset"

    -(e)
  • ADVERTISEMENT
  • #122 20915033
    p.kaczmarek2
    Moderator Smart Home
    Maybe we need to move the location of OBK config somewhere else. It's just at 1MB offset for now, just for testing purposes.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #123 20915697
    sweetlilmre
    Level 9  

    p.kaczmarek2 wrote:
    Maybe we need to move the location of OBK config somewhere else. It's just at 1MB offset for now, just for testing purposes.


    I agree. I went down a rabbit hole with bootloader / flash / stuff last night.
    USER_SPACE_OFFSET from flash_partition_table.h would be the seemingly obvious place.

    However:
    #define BLE_QIOT_RECORD_FLASH_ADDR   (USER_SPACE_OFFSET)


    Seems to use the start of this flash (and is the only thing that does). Why, I have no idea, this is very bad practice from the SDK.
    To be completely safe we could use: USER_SPACE_OFFSET + USER_SPACE_SIZE for a custom region.

    We also need to discuss the partition map, I think we may have to change it, but we'll see when you get a chance to look into OTA.
    -(e)
  • #124 20916193
    p.kaczmarek2
    Moderator Smart Home
    OTA seems to be working. It was hard and I chose to just do our own style OTA in the Web App, so drag and drop should be working now with LN882.

    sweetlilmre wrote:

    To be completely safe we could use: USER_SPACE_OFFSET + USER_SPACE_SIZE for a custom region.

    Using this as config offset bricks the module. For now, I changed config address to USER_SPACE_OFFSET.

    sweetlilmre wrote:
    but we'll see when you get a chance to look into OTA.

    I will do few more tests on my side and push changs to Github



    To everyone reading this thread: LN882H configs from early versions without OTA will be lost once you flash new version. Make sure to write them down.
    Helpful post? Buy me a coffee.
  • #125 20916440
    divadiow
    Level 35  

    Where do we get the LN882H bin files from? Maybe I'm being simple. The releases list doesn't have it, and the link in the flashing guide doesn't have anything.
  • #126 20916455
    p.kaczmarek2
    Moderator Smart Home
    They are not public yet. I can only build on my own PC. The online building system does not have LN882H integrated. It's yet another big piece of work to do. Do anyone here knows Github builds system and wants to help?
    Helpful post? Buy me a coffee.
  • #127 20917150
    tarwirdur
    Level 4  

    It uses GNU make. See workflow.yaml#L89.

    So you need to add build instructions to Makefile and add LN882HK to matrix (L68), and list binary in uploads-artifact configuration (L95) in workflow.yaml
  • #128 20917170
    sweetlilmre
    Level 9  

    tarwirdur wrote:
    It uses GNU make. See workflow.yaml#L89.

    So you need to add build instructions to Makefile and add LN882HK to matrix (L68), and list binary in uploads-artifact configuration (L95) in workflow.yaml


    The LN882H SDK uses CMake and a script for the builds. I'm new to CMake but I think setting this up in an action might require some custom steps.

    -(e)
  • #129 20917226
    p.kaczmarek2
    Moderator Smart Home
    It seems there is some kind of CMake mechanism ready for Github:
    https://github.com/marketplace/actions/cmake-action
    Of course, to build anything, we would need to somehow check out the main parent SDK for LN882H and then put our app directory into it.
    Helpful post? Buy me a coffee.
  • #130 20917238
    tarwirdur
    Level 4  

    p.kaczmarek2, could you please post the URL with the app sources and a short build instruction? Then I can try to build it on my host and prepare the autobuild.

    It is not necessary to use cmake-action: cmake can be called from the Makefile.
  • #131 20917594
    p.kaczmarek2
    Moderator Smart Home
    Thank you! So, here is SDK:
    https://github.com/openshwprojects/OpenLN882H
    Here is App:
    https://github.com/openshwprojects/OpenBK7231T_App
    Here is flashing guide:
    https://www.elektroda.com/rtvforum/topic4028087.html
    Build guide on WSL:
    english_li...etup-1.pdf Download (1011.86 kB)
    Once you have cloned the SDK, you need to clone the App repo into a folder under ln882h/project/OpenBeken. That folder should contain the app repo and be called 'app'
    To access your local file system from wsl, you will have to
    cd /mnt/c/GIT/ln882h
    if you have it on C drive
    Then you can run, first clean:
    python start_build.py clean

    and then:
    python start_build.py build
    Helpful post? Buy me a coffee.
  • #132 20917847
    tarwirdur
    Level 4  
    It looks like the autobuild is going well.

    I've created PR: https://github.com/openshwprojects/OpenBK7231T_App/pull/1041

    But I'm not sure which .bin file is required for flashing:

    List of .bin files:

    PASS -- checking /home/user/git/app/sdk/OpenLN882H/lib/boot_ln882h.bin
    PASS -- checking /home/user/git/app/sdk/OpenLN882H/bin/OpenBeken.bin
    Succeed to build: /home/user/git/app/sdk/OpenLN882H/bin/flashimage.bin (I added this file as release assets. Is this correct?)
    Succeed to build: /home/user/git/app/sdk/OpenLN882H/bin/flashimage-ota-xz-v0.1.bin
  • #133 20917867
    p.kaczmarek2
    Moderator Smart Home
    You are very quick, thank you! I will have to look into your code to see how it was done.

    By the way, would you know how to build Simulator exe (Windows build) on Github Actions as well? I can provide necessary details if required. Simulator has also a self test system, which would be a nice addition if it were automated.

    The release assets we need are:
    
    Succeed to build: /home/user/git/app/sdk/OpenLN882H/bin/flashimage.bin (I added this file as release assets. Is this correct?)
    Succeed to build: /home/user/git/app/sdk/OpenLN882H/bin/flashimage-ota-xz-v0.1.bin
    

    First is for UART flash, second is OTA image, which is working since yesterday (I have added OTA support to OBK)

    Added after 5 [minutes]:

    I think we need to add a copy here for OTA file:
    A section of a build script in a Makefile with highlighted lines adding resources to the release.
    and it seems that final releases table is not updated yet, but it is trivial
    Helpful post? Buy me a coffee.
  • #134 20917954
    tarwirdur
    Level 4  

    Updated PR: added OTA file to assets, added changes to release table (but I didn't figure out how to start automatic publication of a release in my fork to check the change).

    Quote:
    By the way, would you know how to build Simulator exe (Windows build) on Github Actions as well? I can provide necessary details if required. Simulator also has a self-test system, which would be a nice addition if it were automated.


    I don't have much experience with GitHub workflows, but quite a lot of experience with Linux. You can show me what you want to collect, and I will tell you if I can help with it.

    __

    Note: I have not yet tested the resulting images on real hardware. (I have the module, will read the instructions and try this weekend)
  • #135 20917994
    p.kaczmarek2
    Moderator Smart Home
    The simulator code is in win_main.c and it has also a graphical option (not required for testing):
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/win_main.c
    It is not using WINAPI, for graphics SDL is used, but that's not important now. Here are self tests:
    https://github.com/openshwprojects/OpenBK7231T_App/tree/main/src/selftest
    Self tests are checking if everything is working as expected:
    C code snippet of a self-test for an MQTT LED RGB simulator.
    It would be useful to have this integrated, and there are multiple ways to do it:
    - build simulator as Windows exe with SDL and graphics and just add to artifacts the exe
    - build simulator as Windows exe, ignore SDL, just run self tests on Github and check if they are passing
    - build simulator as Linux binary with SDL and graphics and just add to artifacts the binary
    - build simulator as Linux binary, ignore SDL, just run self tests on Github and check if they are passing
    I am just thinking if you have some knowledge how to do that, I can help a lot with the code side, of course.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #136 20918777
    p.kaczmarek2
    Moderator Smart Home
    @tarwirdur I had to apply one fix for your PR to work:
    https://github.com/openshwprojects/OpenBK7231...mmit/24b24b8b73ef23addf03cf230edc25a1f2581e8f
    but it seems to publish binaries now correctly
    Helpful post? Buy me a coffee.
  • #137 20919018
    tarwirdur
    Level 4  

    I've flashed module with the image from GitHub autobuild. It works. The only problem that I have while flashing - it refused to flash with your command
    LN882H_CMD_Tool.exe COMx download flash 2000000 0x0 flashimage.bin
    . TX led blink some time then, after some seconds I got error.

    I change 2000000 -> 200000 (I don’t know what this is, I couldn’t find the documentation quickly) and received "ok".

    So it works, but the module is unexpectedly hot (about 70C). Is this normal behavior? I didn’t run it on the native firmware.
  • #138 20919034
    p.kaczmarek2
    Moderator Smart Home
    @tarwirdur , I haven't investigated LN882H getting hot issue yet, and I don't know if my one is hot or not, by from the experience I can tell that you need to enable PowerSave 1 to reduce the heating.
    We have PowerSave implemented on various platforms, see our tutorial:



    Behind the hood, it's just a single function call to SDK. See the following code:
    Code: C / C++
    Log in, to see the code

    So, maybe we need to look into the LN882H for power saving setting and support that. What do you think, @sweetlilmre ? Is your LN882H getting warm as well?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • Helpful post
    #139 20919279
    @GUTEK@
    Level 31  
    I confirm that the LN882H gets very hot. A device with the relay turned off consumes approximately 0.6W connected to WiFi.

    I uploaded today`s OpenBK build, version 1.17.419. However, I had to reduce the writing speed because there was an error:
    LN882H_CMD_Tool.exe COMx download flash 115200 0x0 flashimage.bin

    I am posting the configuration of my switch, there is no point in creating a separate topic for it.
    {
      "vendor": "CozyLife",
      "bDetailed": "0",
      "name": "CozyLife Mini Smart Switch LN882H",
      "model": "LN882H",
      "chip": "LN882H",
      "board": "LN-02",
      "flags": "1024",
      "keywords": [
        "TODO",
        "TODO",
        "TODO"
      ],
      "pins": {
        "0": "TglChanOnTgl;0",
        "1": "Rel;0",
        "19": "LED_n;0",
        "24": "Btn;0"
      },
      "command": "PowerSave 1",
      "image": "https://obrazki.elektroda.pl/8132417200_1705759867.jpg",
      "wiki": "https://www.elektroda.pl/rtvforum/viewtopic.php?p=20919279#20919279"
    }
    

    Pinout:
    A0 - S2 output (pulled up to 3.3V by a resistor)
    A1 - relay
    B3 - LED
    B8 - button

    Close-up of the CozyLife LN882H smart switch with visible user manual and packaging.
  • #140 20919313
    p.kaczmarek2
    Moderator Smart Home
    What store did you buy from that got you a Mini Relay Switch based on the LN882H?
    Helpful post? Buy me a coffee.
  • #141 20919413
    sithyoda
    Level 7  

    Great work guys! I'm really overwhelmed by how fast this new chip was implemented.
    I flashed it on one of my WL2S boards and soldered it back into the LSPA9.
    I can confirm that the relay (pin A11) and OTA work great already.

    Right now I'm playing with reading the values from BL0937.
    I followed the 3 pins (SEL, CF, CF1) to WL2S pins B3, A12, and A7. But I'm not quite sure as the label is not really visible on the board.
    Printed circuit board labeled WL2S with visible electronic components, including a chip and pins marked as EN, WDC, A10, A12.
    I configured the BL0937 pins but don't see any values on the main page.
    Pin configuration in settings panel.
    Could it be that somehow the driver does not start?
  • #142 20919421
    p.kaczmarek2
    Moderator Smart Home
    @sithyoda as far as I know, drivers system is not ported yet, and futhermore, you'd need to port the interrupt counter in drv_bl0937 as well:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/driver/drv_bl0937.c
    For example, here, you need to add platform-specific code:
    Code: C / C++
    Log in, to see the code
    Helpful post? Buy me a coffee.
  • #143 20919515
    @GUTEK@
    Level 31  
    >>20919313
    I bought it here: https://www.aliexpress.com/item/1005006087905833.html
    Promo for WiFi Smart Switch on AliExpress with reviews and app controls

    By the way, I also measured the current consumption on another switch based on BK7231N, compared to the factory software. It was 0.2W after connecting to WiFi and adding it in the Smart Life application. It would also be good to implement PowerSave in LN882 because the difference is significant.
  • #144 20919569
    gloorung
    Level 6  

    >>20919018

    Just flashed my module with the latest GitHub firmware and measured its temperature: 61°C. Don't have a reference of what would be acceptable though...
  • #145 20919575
    p.kaczmarek2
    Moderator Smart Home
    There are some power saving references in the SDK:
    https://github.com/search?q=repo%3Asweetlilmre%2Fln882h%20power%20save&type=code
    Here are app settings:
    Screenshot of code in the usr_app.c file from the OpenBeken project defining power saving modes.
    And here are possible options:
    Code: C / C++
    Log in, to see the code

    Hm, here is a function to set it:
    Code: C / C++
    Log in, to see the code

    I think I can try to plug it into OBK so our PowerSave command works, who wants to help with testing?
    Helpful post? Buy me a coffee.
  • #146 20919789
    divadiow
    Level 35  

    Meeee.

    I have an LSPA9 unopened and the 16A mini switch, not yet on OTA fw. Not sure I can objectively measure temperature though, it'd be through touch I guess.
  • #147 20920009
    tarwirdur
    Level 4  
    >>20919034

    I tried to enable powersave (Changed wifi_init_sta directly in src/hal/ln882h/hal_wifi_ln882h.c).

    68C - NO_POWERSAVE
    60C - MIN_POWERSAVE
    60C - MAX_POWERSAVE
    55C - MIN_POWERSAVE + CLK_G_BLE added to ln_pm_always_clk_disable_select in OpenBeken/usr_app.c
  • #148 20920140
    p.kaczmarek2
    Moderator Smart Home
    Temperature is not a good measurement. I'd rather suggest checking power consumption, just like we did on this video:
    https://www.youtube.com/watch?v=eupL16eB7BA
    Helpful post? Buy me a coffee.
  • #149 20920589
    @GUTEK@
    Level 31  
    I can measure the current consumption, but I would have to get the firmware with PowerSave enabled, or with its different modes.
  • #150 20921265
    divadiow
    Level 35  

    Just confirming I have happily flashed OpenLN882H_1.17.421.bin to the 16A mini switch and then OTA updated to the same version successfully

    Added after 9 [minutes]:

    >>20919279

    What is the significance of the A0 setting? I omitted it on the Elivco posting

    The image shows two devices: Elivco Cozylife 16A Mini Switch (RMW002) and CozyLife Mini Smart Switch (LN882H) with product names and images.

Topic summary

The discussion revolves around flashing OpenBeken firmware on the ELIVCO LSPA9 module, which utilizes the WL2S microcontroller and the LIGHTNING LN882HK chip. Users share their experiences with UART and JTAG flashing methods, debugging issues, and the challenges of obtaining and compiling the necessary firmware. Several users successfully managed to flash the firmware, enabling functionalities such as WiFi connectivity and relay control. The conversation also touches on power consumption, temperature management, and the implementation of power-saving features. Additionally, users discuss the integration of the BL0937 power metering chip and the development of a comprehensive template for the device.
Summary generated by the language model.
ADVERTISEMENT