logo elektroda
logo elektroda
X
logo elektroda

How to flash LN882H with open source Tasmota/Esphome style firmware - backup procedure included

p.kaczmarek2 42036 297
ADVERTISEMENT
  • #181 21064556
    max4elektroda
    Level 20  
    I didn't think about this point, but just gave it a try with delaying only if (Main_IsConnectedToWiFi() == 0) && (Main_IsOpenAccessPointMode() ==0).

    I think we can safely ignore this case ;-)
    [WLIB_E]This operation is prohibited in current WiFi mode(1)!


    Added after 2 [minutes]:

    ... and the module draws a current from almost 100 mA in AP mode
  • ADVERTISEMENT
  • #182 21064574
    p.kaczmarek2
    Moderator Smart Home
    So they didn't even bother to allow AP mode optimization, I see. Ok, so the PR is ready to merge?
    Helpful post? Buy me a coffee.
  • #183 21064629
    max4elektroda
    Level 20  
    I can't see why not.
    We should just point out, that "powerSave 2"
    - breaks power measurement with BL0937 and
    - might lead to sporadic WiFi reconnects
  • ADVERTISEMENT
  • #184 21064688
    p.kaczmarek2
    Moderator Smart Home
    Merged, thank you!
    The PowerSave actually also breaks BL0937 on other platforms, like on Beken, but in that case even PowerSave 1 breaks it. And as far as I know Tuya is also not using PowerSave on BL0937 devices. This is because BL0937 works by counting pulses with a GPIO interrupt...

    Ok, so what's next for LN882H? Hm, isn't LittleFS still missing?
    Helpful post? Buy me a coffee.
  • #185 21064811
    max4elektroda
    Level 20  
    Yes, I remember I said I will try LittleFS...
    Since I'm waiting for some tests on the clock implementation, I'll go for this next.
  • #186 21064865
    p.kaczmarek2
    Moderator Smart Home
    Before I forget, that little fix is also awaiting testing:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1189
    Regarding LittleFS, here is the same process done for BL602:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1159/files
    And here are flash routines for LN882H:
    https://github.com/openshwprojects/OpenBK7231.../main/src/hal/ln882h/hal_flashConfig_ln882h.c
    Helpful post? Buy me a coffee.
  • #188 21065231
    Piorun2002
    Level 15  
    How is the LN882H name designated for MQTT?
    In the configuration, I have entered different names than those broadcast in the 'Native', tasmota and hass modes.
    
    Config:
    ShortName 'SwitchC2A795XX'
    Full Name 'Switch C2A795XX (Test)'
    
    MQTT
    Native name 'Switch_C2A795XX' 
    Switch_C2A795XX/1/get 0
    
    Tasmota name: 'Switch_C2A795XX'
    tele/Switch_C2A795XX/STATE {":-38,"LinkCount":21,"Downtime":"0T06:13:34"}}
    
    Hass name: 'Switch_C2A795XX_(Test)'
    homeassistant/sensor/Switch_C2A795XX_(Test)_uptime/config {"dev":{"ids":["Switch C2A795XX (Test)"],"name":"SwitchC2A795XX""}
    
  • #189 21066550
    max4elektroda
    Level 20  
    p.kaczmarek2 wrote:
    Ok, so what's next for LN882H? Hm, isn't LittleFS still missing?

    I made a new PR for this (PR #1191), which will fail for LN882H, because the littleFS files are missing in OpenLN882Hs CMakeList.txt
    @p.kaczmarek2: I think I remember you mentioned, how to fix this with some git force command... Maybe you would be so nice to do this?

    What I did in my local code:
    diff --git a/project/OpenBeken/CMakeLists.txt b/project/OpenBeken/CMakeLists.txt
    index 0fd392e..8f29744 100644
    --- a/project/OpenBeken/CMakeLists.txt
    +++ b/project/OpenBeken/CMakeLists.txt
    @@ -109,9 +109,9 @@ set(PROJ_ALL_SRC
     #    app/src/i2c/drv_i2c_mcp23017.c
     #    app/src/i2c/drv_i2c_tc74.c
         app/src/jsmn/jsmn.c
    -#    app/src/littlefs/lfs_util.c
    -#    app/src/littlefs/lfs.c
    -#    app/src/littlefs/our_lfs.c
    +    app/src/littlefs/lfs_util.c
    +    app/src/littlefs/lfs.c
    +    app/src/littlefs/our_lfs.c
         app/src/logging/logging.c
     #    app/src/memory/memtest.c
    



    During my affords I struggled with some strange findings:

    Even before the compiler reached my additions to the littlefs source the compilation was aborted.
    E.g.: Simply defining LittleFS (#define ENABLE_LITTLEFS 1) for LN882H leads to a bunch of (misleading) errors, I couldn't really understand.
    Mostly some (incorrect, from my point of view) complaints about conflicting types like the first error occuring:

     27%] Building C object project/OpenBeken/CMakeFiles/OpenBeken.elf.dir/app/src/cmnds/cmd_main.obj
    cd /OpenBK7231T_App/sdk/OpenLN882H/build/project/OpenBeken && /usr/bin/arm-none-eabi-gcc -DARM_MATH_CM4 -DLN882H -DPLATFORM_LN882H=1 -DUSER_SW_VER=\"dev_20240501_101247\" -I/OpenBK7231T_App/sdk/OpenLN882H/components/kernel -I/OpenBK7231T_App/sdk/OpenLN882H/components/kernel/osal -I/OpenBK7231T_App/sdk/OpenLN882H/components/kernel/FreeRTOS_Adapter -I/OpenBK7231T_App/sdk/OpenLN882H/components/kernel/FreeRTOS/Source/include -I/OpenBK7231T_App/sdk/OpenLN882H/components/kernel/FreeRTOS/Source/portable/GCC/ARM_CM4F -I/OpenBK7231T_App/sdk/OpenLN882H/components/ln_at -I/OpenBK7231T_App/sdk/OpenLN882H/components/ln_at/adapter -I/OpenBK7231T_App/sdk/OpenLN882H/components/ln_at/cmd -I/OpenBK7231T_App/sdk/OpenLN882H/components/ln_at/parser -I/OpenBK7231T_App/sdk/OpenLN882H/components/ln_at/transfer -I/OpenBK7231T_App/sdk/OpenLN882H/components/ln_at_cmd -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/ping -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/iperf -I/OpenBK7231T_App/sdk/OpenLN882H/components/fs/kv/kv -I/OpenBK7231T_App/sdk/OpenLN882H/components/fs/kv/kv_port -I/OpenBK7231T_App/sdk/OpenLN882H/components/fs/nvds -I/OpenBK7231T_App/sdk/OpenLN882H/components/fs/partition_mgr -I/OpenBK7231T_App/sdk/OpenLN882H/components/fota/ota_agent -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils/runtime -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils/reboot_trace -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils/fifo -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils/debug -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils/debug/CmBacktrace -I/OpenBK7231T_App/sdk/OpenLN882H/components/utils/linux_compat -I/OpenBK7231T_App/sdk/OpenLN882H/components/serial -I/OpenBK7231T_App/sdk/OpenLN882H/mcu/ln882h -I/OpenBK7231T_App/sdk/OpenLN882H/mcu/CMSIS_5.3.0 -I/OpenBK7231T_App/sdk/OpenLN882H/mcu/driver_ln882h -I/OpenBK7231T_App/sdk/OpenLN882H/mcu/driver_ln882h/reg -I/OpenBK7231T_App/sdk/OpenLN882H/components/wifi/wifi_manager -I/OpenBK7231T_App/sdk/OpenLN882H/components/wifi/wifi_lib_import -I/OpenBK7231T_App/sdk/OpenLN882H/components/wifi/wifi_lib_export -I/OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app -I/OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app/include -I/OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/bsp -I/OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/cfg -I/OpenBK7231T_App/sdk/OpenLN882H/components -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include/lwip -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include/lwip/prot -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include/lwip/priv -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include/netif -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include/posix -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/include/posix/sys -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/lwip-2.1.3/src/port/ln_osal/include -I/OpenBK7231T_App/sdk/OpenLN882H/components/net/dhcpd  -mthumb  -mabi=aapcs  -mcpu=cortex-m4  -mfpu=fpv4-sp-d16  -mfloat-abi=hard        -MD -MP     -ffunction-sections -fdata-sections -fno-strict-aliasing  -O1 -DNDEBUG   -std=gnu99 -o CMakeFiles/OpenBeken.elf.dir/app/src/cmnds/cmd_main.obj   -c /OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app/src/cmnds/cmd_main.c
    /OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app/src/cmnds/cmd_main.c:47:6: error: conflicting types for 'g_powersave'
       47 | bool g_powersave;
          |      ^~~~~~~~~~~
    In file included from /OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app/src/cmnds/cmd_local.h:4,
                     from /OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app/src/cmnds/cmd_main.c:6:
    /OpenBK7231T_App/sdk/OpenLN882H/project/OpenBeken/app/src/cmnds/cmd_public.h:33:13: note: previous declaration of 'g_powersave' was here
       33 | extern bool g_powersave;
          |             ^~~~~~~~~~~
    


    In the end, I "solved" this by moving the place of import of littlefs/our_lfs.h in relation to other includes.
    #if ENABLE_LITTLEFS
    #include "../littlefs/our_lfs.h"
    #endif


    And then in src/new_cfg.c, the defines from the included files where not present (here LFS_BLOCKS_DEFAULT_LEN was indicated "undefined"), so I had to do a nasty hack here:


    uint32_t CFG_GetLFS_Size() {
    #ifndef LFS_BLOCKS_DEFAULT_LEN // nasty hack. There is something strange with the includes of littlefs in conjunction with LN882H - this define is included in our_lfs.h but not there ?!?!? 
    #define LFS_BLOCKS_DEFAULT_LEN 0x8000
    #endif


    The last thing to mention is probably a size issue: the OTA image I flashed was not applied after a reboot.
    So I reduced the size of the image by un-defining all the other drivers (but file size was way below the OTA partition size)???

    But in the end, with all these hacks, I have successfully created a file which I could access after a reboot:

    LittleFS file system interface on a webpage.
  • ADVERTISEMENT
  • #190 21067927
    max4elektroda
    Level 20  
    Thanks to git user @giedriuslt , I could resolve the strange compiler issues.
    I turned out to be different type definitions for bool, so the conflicts were real ;-)

    LFS compiles fine now, the lfs_tests1-3 succeeded and the contents of LFS where still present after several OTA updates...
  • #191 21068612
    Piorun2002
    Level 15  
    Can you provide a link to download this build?
  • #193 21068793
    p.kaczmarek2
    Moderator Smart Home
    Good job @max4elektroda, but can you submit your changes to SDK as a PR?

    max4elektroda wrote:

    I made a new PR for this (PR #1191), which will fail for LN882H, because the littleFS files are missing in OpenLN882Hs CMakeList.txt
    @p.kaczmarek2: I think I remember you mentioned, how to fix this with some git force command... Maybe you would be so nice to do this?

    What I did in my local code:
    diff --git a/project/OpenBeken/CMakeLists.txt b/project/OpenBeken/CMakeLists.txt
    index 0fd392e..8f29744 100644
    --- a/project/OpenBeken/CMakeLists.txt
    +++ b/project/OpenBeken/CMakeLists.txt
    @@ -109,9 +109,9 @@ set(PROJ_ALL_SRC
     #    app/src/i2c/drv_i2c_mcp23017.c
     #    app/src/i2c/drv_i2c_tc74.c
         app/src/jsmn/jsmn.c
    -#    app/src/littlefs/lfs_util.c
    -#    app/src/littlefs/lfs.c
    -#    app/src/littlefs/our_lfs.c
    +    app/src/littlefs/lfs_util.c
    +    app/src/littlefs/lfs.c
    +    app/src/littlefs/our_lfs.c
         app/src/logging/logging.c
     #    app/src/memory/memtest.c
    

    Or should I add it myself? Then I can update the SDK in the main repository.
    This is how I do it: https://www.theserverside.com/blog/Coffee-Tal...ies-and-Opinions/How-to-update-Git-submodules
    Helpful post? Buy me a coffee.
  • #194 21068799
    max4elektroda
    Level 20  
    Let me try it, always good to try/learn something new.
    I'll ask you to do it, if I don't manage to do it.

    Added after 1 [hours] 48 [minutes]:

    I didn't manage this with the submodules, I kept getting errors.
    So I made a PR for OpenLN882H: PR #14
  • #195 21068951
    Piorun2002
    Level 15  
    Works for me :)
    I tested auto switch off:
    --------
    // This aliased command will turn off relay on CH1 after 10 seconds
    // addRepeatingEvent [IntervalSeconds][RepeatsOr-1][CommandToRun]
    alias turn_off_after_time addRepeatingEvent 10 1 setChannel 1 0
    // this will run the turn off command every time that CH1 becomes 1
    addChangeHandler Channel1 == 1 turn_off_after_time
    ----------
  • #196 21069119
    p.kaczmarek2
    Moderator Smart Home
    @max4elektroda here is updated submodule, please merge it into your branch:
    https://github.com/openshwprojects/OpenBK7231...mmit/bbf502c39cd9bf6c3c5f11d57c200815f55c81d0
    Helpful post? Buy me a coffee.
  • #197 21069214
    max4elektroda
    Level 20  
    I don't know how, but I think I made it: All images are built ...
  • #198 21069264
    p.kaczmarek2
    Moderator Smart Home
    How much has the binary increased after adding LFS?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #199 21069454
    max4elektroda
    Level 20  
    I will do another build later, actualy I had test commands enabled, too.
    Build (including test commands) used 654KB, the actual release is 610 KB.
    So it should be ~40 KB

    Added after 8 [minutes]:

    W/o test commands size is 652KB, so LFS adds 42KB
    But, to be honest, it's more than LFS, since also all this code for scripting is enabed, if LFS is present, which is not related to LFS itself...
  • #200 21069522
    Piorun2002
    Level 15  
    Piorun2002 wrote:
    Works for me :)
    I tested auto switch off:

    Build on May 3 2024 15:57:10 version dev_20240503_155700
    Something is wrong with this build - after 1-2 hours, ping works, but web management does not (I also use PowerSave 2)
  • #201 21069620
    p.kaczmarek2
    Moderator Smart Home
    But is the problem related to LFS merge? Maybe it was present before?

    Such a problem usually indicates that there is not enough heap space to alloc buffers for HTTP server:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/httpserver/http_tcp_server.c
    Screenshot of code in http_tcp_server.c with highlighted section regarding buffer allocation.
    Helpful post? Buy me a coffee.
  • #202 21069900
    max4elektroda
    Level 20  
    max4elektroda wrote:

    W/o test commands size is 652KB, so LFS adds 42KB

    Hmm, latest build (OpenLN882H_1191_merge_0dd0446be0aa.bin) is only 638KB ??
  • #203 21069902
    p.kaczmarek2
    Moderator Smart Home
    Actually it seems that online building has broken today somehow:
    
    Error: Cannot find module 'conventional-changelog-conventionalcommits
    

    All my builds are now failing with this message...
    Helpful post? Buy me a coffee.
  • #204 21069957
    max4elektroda
    Level 20  
    Last build some minutes ago was o.k. for me (only W800 failing)
  • #205 21069963
    p.kaczmarek2
    Moderator Smart Home
    I will rerun the latest build and see:
    Dialog window with the option to rerun a job in the CI/CD workflow.
    Helpful post? Buy me a coffee.
  • #206 21070245
    max4elektroda
    Level 20  
    Piorun2002 wrote:
    Something is wrong with this build - after 1-2 hours, ping works, but web management does not (I also use PowerSave 2)

    I tried here, "PowerSave 2", even installed the autoexec.bat you used.
    Control panel screen for OpenLN882H showing status OFF with options for configuration and restart.
  • #207 21070551
    Piorun2002
    Level 15  
    I'm using it now Build on May 4 2024 15:20:53 version 1191_merge_eb591d9a473a
    I turned off some test MQTT options (hass / tele discovery) and it seems to work well

    there is 95K free space
    Info:MAIN:Time 1787, idle 0/s, free 95856, MQTT 1(2), bWifi 1, secondsWithNoPing 1, socks 0/0 POWERSAVE
    Info:MAIN:Time 1788, idle 0/s, free 95856, MQTT 1(2), bWifi 1, secondsWithNoPing 1, socks 0/0 POWERSAVE 


    --- update
    after enabling the options:
    Flag 27 - [HASS] Invoke HomeAssistant discovery on change to ip address, configuration
    Flag 30 - [MQTT] Enable Tasmota TELE etc publishes (for ioBroker etc)


    the problem started occurring again
  • #208 21072408
    p.kaczmarek2
    Moderator Smart Home
    Guys, do you have B9 gpio working on your LN882Hs? For me, it's in high state all the time and OBK can't control it.
    Helpful post? Buy me a coffee.
  • #209 21072502
    divadiow
    Level 34  
    p.kaczmarek2 wrote:
    Guys, do you have B9 gpio working on your LN882Hs? For me, it's in high state all the time and OBK can't control it.


    B9 is always high for me no matter what I set in here

    Screenshot of a software interface with P25 settings.

    Added after 15 [minutes]:

    A12, also default PU, is able to PD
  • #210 21072598
    p.kaczmarek2
    Moderator Smart Home
    Yea I just noticed that, I am making LN882H dev board out of scrap and I was suprised to see that this particular pin is always high for me.
    Circuit board from scrap with electronic components, including capacitors and a USB port.
    Close-up of an electronic board with various components and a coil of wires.
    I almost got HD2015 display working.
    Helpful post? Buy me a coffee.

Topic summary

The discussion focuses on flashing the LN882H module with open-source firmware such as Tasmota or ESPHome, detailing the necessary hardware setup, including the use of a USB to UART converter and a reliable 3.3V power supply. Users share experiences with various programming tools, troubleshooting flashing errors, and the importance of using the correct baud rate (115200) for successful firmware uploads. The conversation also touches on issues related to power consumption, the implementation of power-saving modes, and the challenges faced when trying to reset configurations or passwords in the firmware. Additionally, there are mentions of specific devices using the LN882H chip and the need for community support in resolving technical issues.
Summary generated by the language model.
ADVERTISEMENT