logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 42483 297
ADVERTISEMENT
  • #241 21086034
    Piorun2002
    Level 15  
    max4elektroda wrote:
    I would vote for the reset be possible in default (so on/off depends on if it's "enable possible config reset" or "disable possible config reset").

    My proposal was:
    Web authentication interface with options to enable authentication and disable password reset.

    so you can disable recovery when you enable password (normally recovery is possible)
  • ADVERTISEMENT
  • ADVERTISEMENT
  • #243 21086964
    max4elektroda
    Level 20  
    I implemented a flag to disable the new feature:
    Screenshot of a configuration interface with network authentication options and admin password field.
    @p.kaczmarek2: I hope, I made no mistake regarding the flags.
    While at it, I fixed a minor "bug" in the code (every time you saved the WiFi page with password enabled it would state "Web password has been changed.", regardless, if you actually changed it)
  • #245 21201121
    grzegorzpilu
    Level 2  
    thank you for making interesting things... I brought my four switches back to life with LN882
    Thank you!!
    I can only tell you that not every USB-TTL works, as I almost gave up trying to change the adapter to the one described in the description.
    not only do I know how I got back to editing, because after setting the wifi and confirming, it automatically resets to make the change, which I turn off and on about 5 times and I can re-enter the settings :))
  • #246 21286288
    schaloule
    Level 1  
    >>20958308
    Also had the download error on my CH340 adapter and reducing the download speed to 115200 worked for me.
  • #247 21287693
    divadiow
    Level 34  
    fun fact: all the Tuya LN882H factory firmwares we have at the moment were built with TuyaOS SDK version 3.5.4

    List of Tuya LN882H firmware files.
  • #248 21288584
    piotrz191919
    Level 5  
    Please help. I'm trying to flash the LN882 module, and I'm already on my third programmer. I finally managed to download it using the command python LN882H_Flash_Dumper.py COM5 flashdump. However, during programming, an error appears: Python 3.13>LN882H_CMD_Tool.exe COM5 download flash 115200 0x0 flashimage.bin
    WARNING: CPU random generator seems to be failing, disabling hardware random number generation
    WARNING: RDRND generated: 0xffffffff 0xffffffff 0xffffffff 0xffffffff
    Fail. Error downloading file.
    I’m trying to load it; the LEDs start flashing, but after 3-4 seconds, this error appears.
  • #250 21289208
    max4elektroda
    Level 20  
    And another possible source for flashing problems can be the power supply.
    Especially the output of USB UARTS with a power output are often causing problems. @piotrz191919 how do you power the module?
  • #251 21290010
    piotrz191919
    Level 5  
    >>21288594 Yes, an external power supply, but it worked out thanks to the help. Now I'm struggling with the MQTT configuration

    Dodano po 1 [minuty]:

    >>21289208 Yes, an external power supply, but it worked out thanks to the help
  • #252 21298571
    arturiluk1
    Level 1  
    >>20958664
    It works on LN-02 (only with 115200 speed) in cozylife smart switch (clone?) from aliexpress
  • #253 21311742
    Tilator
    Level 10  
    I have not been able to flash it. It's WL2S. I have taken it off the board.

    Error is "Fail. Could not go in download mode."

    A9 gpio is soldered to ground.

    Two questions:

    1. if A9 should be low all the time, is it OK solder it to ground?
    2. Should I connect it to power first and then to uart? Or uart first and then power?

    B.T.W It goes in some bind of boot load mode because if I connect it to power without A9 low, it makes AP, but keeping A9 down prevents it making it.

    Added after 3 [hours] 44 [minutes]:

    Got it flashed. Now it does not update itself by OTA.
  • #254 21312091
    max4elektroda
    Level 20  
    Tilator wrote:
    Now it does not update itself by OTA.

    It will not update automatically, but you need to start an update from the Web Application.
    If you meant an update from the Web App failed, you can try another browser. At least I sometimes had trouble to update with Firefox, but it was successful with Chrome(ium) browser.
  • ADVERTISEMENT
  • #255 21312203
    p.kaczmarek2
    Moderator Smart Home
    @max4elektroda maybe we could do something about this OTA? I saw somewhere that one browser was sending OTA file in too large chunks. What if we've created a simple C# app that does OTA in a more reliable way? Use the same end points as Web App, so the firmware code does not have to be modified
    Helpful post? Buy me a coffee.
  • #256 21312284
    Tilator
    Level 10  
    max4elektroda wrote:
    At least I sometimes had trouble to update with Firefox, but it was successful with Chrome(ium) browser.


    That's it. Thanks.

    Maybe there should be a warning on OTA page? Just in case.
  • #257 21312606
    p.kaczmarek2
    Moderator Smart Home
    Ok guys, @divadiow @max4elektroda can you try different browsers and give me some feedback on what kind of warning shall I place on the Web App?
    Helpful post? Buy me a coffee.
  • #258 21312889
    max4elektroda
    Level 20  
    I'll do some tests tomorrow with different browsers.
  • #259 21314524
    max4elektroda
    Level 20  
    After some test, I only could see that OTA from Web App very often fails when done with with firefox.
    I never had an issue when using Chrome, Chromium, Edge ...

    I really tried to find an issue, but I didn't.
    The log is always something like:

    Debug:OTA:Writelen 1460 at 123759
    Debug:OTA:write at flash: 0x00151000
    Debug:OTA:Writelen 4380 at 125219
    Debug:OTA:Writelen 1460 at 129599
    Debug:OTA:write at flash: 0x00152000
    
    Firmware name: wifi_mcu_basic_example, hardware version: HW_V1.0, software version: SW_V1.0
    Fault on thread HTTP Clie
    ===== Thread stack information =====
      addr: 20033a10    data: 0001fff3
      addr: 20033a14    data: 20019274
      addr: 20033a18    data: 20034570
      addr: 20033a1c    data: fffffef1
      addr: 20033a20    data: 0000ff06


    without debug logging it's:

    Info:MAIN:Time 73, idle 0/s, freeInfo:MAIN:Time 73, idle 0/s, free 78480, MQTT 1(2), bWifi 1, secondsWithNoPing 8, socks 0/0 
    Info:MAIN:Time 74, idle 0/s, free 69968, MQTT 1(2), bWifi 1, secondsWithNoPing 9, socks 0/0 
    (HTTP Clie)StackOverFlow
    
    Firmware name: wifi_mcu_basic_example, hardware version: HW_V1.0, software version: SW_V1.0
    Fault on thread HTTP Clie
    ===== Thread stack information =====
      addr: 20033988    data: 0002ef7b
      addr: 2003398c    data: 20019274
      addr: 20033990    data: 20034980
      addr: 20033994    data: ffffff69
      addr: 20033998    data: 0000ff06
     78480, MQTT 1(2), bWifi 1, secondsWithNoPing 8, socks 0/0 
    Info:MAIN:Time 74, idle 0/s, free 69968, MQTT 1(2), bWifi 1, secondsWithNoPing 9, socks 0/0 
    (HTTP Clie)StackOverFlow
    
    Firmware name: wifi_mcu_basic_example, hardware version: HW_V1.0, software version: SW_V1.0
    Fault on thread HTTP Clie
    ===== Thread stack information =====
      addr: 20033988    data: 0002ef7b
      addr: 2003398c    data: 20019274
      addr: 20033990    data: 20034980
      addr: 20033994    data: ffffff69
      addr: 20033998    data: 0000ff06



    But I didn't find a reason yet, for the POST seems to be almost identically:

    Comparative screenshot of TCP traffic from Firefox and Chrome in Wireshark.

    You can see the "broken" download with Firefox, the data is transferred is less than the full data seen in right window.
    Content-Length is equal, only Firefox has one additional header element "Priority". But since Openbeken will probably not use it, I can't see why reading data in HTTP-Client seems to fail with Firefox...

    Maybe someone else can see a possible reason?

    For now I would suggest a warning that OTA might fail if done with Firefox browser.
  • ADVERTISEMENT
  • #261 21315281
    max4elektroda
    Level 20  
    There aren't any extensions in the browser.

    And, to be honest, I would think there's something in LN882H code causing this. A problem in SDK, especially in LWIP, a memory issue in the receiving code only firing in rare cases...
    You should not be able to crash the device when sending data a regular way. Maybe if data is interpreted, but here the packets should be simply stored, so even POST-ing wrong or corrupted data could only make problems later, e.g. if the device can't boot any more.
  • #262 21315326
    Piorun2002
    Level 15  
    >And, to be honest, I would think there's something in LN882H code causing this.
    The LN882 code is fine because it works with other browsers, but there is a lot of information that FF has had a problem with Upload for years and it has not been solved
  • #263 21316196
    max4elektroda
    Level 20  
    Sorry if I disagree, but the way you "proof" your assumption seems not a valid one to me.
    I could "proof" my guess with stating: FF is doing fine, because there is no problem uploading a firmware to a Beken device using the same browser and the same app resulting in the same POST request.

    But that's guesswork, I like to investigate and finding facts, so I did some more tests:

    I made a simple test to test your thesis.

    I hosted the app locally in a docker and changed "ota.vue" to send firmware not the the LN882H but to my PC:

    --- ota.vue   2024-11-19 13:24:54.000000000 +0100
    +++ ota_own.vue   2024-11-23 16:12:25.954693401 +0100
    @@ -297,7 +297,7 @@
                 this.bOTAstarted = true;
                 this.status += '<br/>starting OTA...';
                 console.log('start ota ');
    -            let url = window.device+'/api/ota';
    +            let url = 'http://10.42.0.1:88/api/ota';
                 if (this.otadata){
                     fetch(url, { 
                             method: 'POST',
    


    On my PC I started a simple nc listening to port 88 saving the data served to a file:

    sudo nc -l -p 88 > p88.out


    Then I started an OTA update of latest OpenLN882H release with Firefox.


    Now the request sent is in the file, and I want find the HTTP headers in the file (this one is from an incognito window):

    max@max-PC:~/LN882H/OTA_issues$ cat -n  p88.out | head -n 18
         1   POST /api/ota HTTP/1.1
         2   Host: 10.42.0.1:88
         3   User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
         4   Accept: */*
         5   Accept-Language: de,en-US;q=0.7,en;q=0.3
         6   Accept-Encoding: gzip, deflate
         7   Referer: http://10.42.0.159/
         8   Content-Length: 363813
         9   Origin: http://10.42.0.159
        10   DNT: 1
        11   Sec-GPC: 1
        12   Connection: keep-alive
        13   Priority: u=0
        14   Pragma: no-cache
        15   Cache-Control: no-cache
        16   
        17   
            �   %��������u�k��]
                                   �       �R��Z����&�
        18   ,b󕳲�́~��i�y�ɝX�OTg|s��o
    


    So I will strip the first 17 lines (up to the "\r\n\r\n" after the header) and check file sizes

    max@max-PC:~/LN882H/OTA_issues$ tail -n +17 p88.out > p88-17.out
    max@max-PC:~/LN882H/OTA_issues$ 
    max@max-PC:~/LN882H/OTA_issues$ ls -l p88-17.out 
    -rw-rw-r-- 1 max max 363813 Nov 23 16:38 p88-17.out
    max@max-PC:~/LN882H/OTA_issues$ ls -l ~/Downloads/OpenLN882H_1.17.772_OTA.bin
    -rw-rw-r-- 1 max max 363813 Nov 22 11:15 /home/max/Downloads/OpenLN882H_1.17.772_OTA.bin


    that looks promising, so check content:

    max@max-PC:~/LN882H/OTA_issues$ cmp ~/Downloads/OpenLN882H_1.17.772_OTA.bin p88-17.out
    max@max-PC:~/LN882H/OTA_issues$ md5sum ~/Downloads/OpenLN882H_1.17.772_OTA.bin
    f2d53e1f34037709196a9823828240a6  /home/max/Downloads/OpenLN882H_1.17.772_OTA.bin
    max@max-PC:~/LN882H/OTA_issues$ md5sum p88-17.out 
    f2d53e1f34037709196a9823828240a6  p88-17.out
    max@max-PC:~/LN882H/OTA_issues$ 


    The POST data sent by Firefox is identical to the firmware file.


    Same on a "regular" FF window (header is shorter here):

    max@max:~/LN882H/OTA_issues$ cat -n  temp.out | head -n 14
         1   POST /api/ota HTTP/1.1
         2   Host: 10.42.0.1:88
         3   User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:132.0) Gecko/20100101 Firefox/132.0
         4   Accept: */*
         5   Accept-Language: de,en-US;q=0.7,en;q=0.3
         6   Accept-Encoding: gzip, deflate
         7   Referer: http://10.42.0.159/
         8   Content-Length: 363813
         9   Origin: http://10.42.0.159
        10   Connection: keep-alive
        11   Priority: u=0
        12   
        13   
            �   %��������u�k��]
                                   �       �R��Z����&�
        14   ,b󕳲�́~��i�y�ɝX�OTg|s��o
    max@max:~/LN882H/OTA_issues$ tail -n +13 temp.out > temp-17.out
    max@max:~/LN882H/OTA_issues$ md5sum temp-17.out 
    f2d53e1f34037709196a9823828240a6  temp-17.out
    max@max:~/LN882H/OTA_issues$ md5sum ~/Downloads/OpenLN882H_1.17.772_OTA.bin
    f2d53e1f34037709196a9823828240a6  /home/max/Downloads/OpenLN882H_1.17.772_OTA.bin
    max@max:~/LN882H/OTA_issues$ 
    


    I repeated both tests (standard and incognito) five times each. In all ten tests the image was transferred correctly.

    So, time to replace my changed ota.vue again ...

    max@max:~/LN882H/OTA_issues$ docker cp   ota.vue $(docker ps | grep closed | sed "s/[ ]*closed.*//"):/usr/src/app/vue/ota.vue 
    Successfully copied 18.9kB to edf816d08a79:/usr/src/app/vue/ota.vue
    max@max:~/LN882H/OTA_issues$ 


    .. reload the App and try to update the LN882H again:

    Info:MAIN:Time 4420, idle 0/s, free 98296, MQTT 1(17), bWifi 1, secondsWithNoPing 4355, socks 0/0 
    Info:MAIN:Time 4421, idle 0/s, free 78376, MQTT 1(17), bWifi 1, secondsWithNoPing 4356, socks 0/0 
    
    Firmware name: wifi_mcu_basic_example, hardware version: HW_V1.0, software version: SW_V1.0
    Fault on thread HTTP Clie
    ===== Thread stack information =====
      addr: 20033a18    data: 0001ffdf
      addr: 20033a1c    data: 20019274
      addr: 20033a20    data: 200345e0
      addr: 20033a24    data: ffffff05


    So my conclusion is, that I'm pretty sure the issue is somewhere in the LN882Hs code.

    I can see one difference in the Wireshark packets:

    Firefox sends the POST header together with the start of the payload in the first packet.
    Chromium sends the header in a separate TCP packet.
    Both is totally valid TCP, but maybe somewhere the packet containing the header is "processed" differently?

    Comparison of TCP packet captures in Wireshark for Firefox and Chromium.

    But I don't yet fully understand the OTA mechanism. Especially, I don't see, how "HTTP Client" (the tread failing) gets involved ???
  • #264 21316930
    max4elektroda
    Level 20  
    So another test: Send back the file "recorded" from firefox:

    cat p88.out |  nc  10.42.0.159 80



    Spoiler:
    Info:MAIN:Time 860, idle 0/s, free 98088, MQTT 1(3), bWifi 1, secondsWithNoPing 550, socks 0/0
    Debug:API:POST to api/ota
    Debug:OTA:OTA post len 363813
    Debug:OTA:Ota start!
    Debug:OTA:Writelen 3979 at 0
    Debug:OTA:write at flash: 0x00133000
    Debug:OTA:[ota_download_precheck] same version, do not upgrade!
    Debug:OTA:Writelen 2920 at 3979
    Debug:OTA:write at flash: 0x00134000
    Debug:OTA:Writelen 1460 at 6899
    Debug:OTA:Writelen 1460 at 8359
    Debug:OTA:write at flash: 0x00135000
    Debug:OTA:Writelen 4380 at 9819
    Debug:OTA:Writelen 1460 at 14199
    Debug:OTA:write at flash: 0x00136000
    Debug:OTA:Writelen 4380 at 15659
    Debug:OTA:write at flash: 0x00137000
    Debug:OTA:Writelen 1460 at 20039
    Debug:OTA:Writelen 1460 at 21499
    Debug:OTA:write at flash: 0x00138000
    Debug:OTA:Writelen 4380 at 22959
    Debug:OTA:write at flash: 0x00139000
    Debug:OTA:Writelen 1460 at 27339
    Debug:OTA:write at flash: 0x0013a000
    Debug:OTA:Writelen 4380 at 28799
    Debug:OTA:Writelen 1460 at 33179
    Debug:OTA:write at flash: 0x0013b000
    Debug:OTA:Writelen 4380 at 34639
    Debug:OTA:Writelen 1460 at 39019
    Debug:OTA:write at flash: 0x0013c000
    Debug:OTA:Writelen 4380 at 40479
    Debug:OTA:write at flash: 0x0013d000
    Debug:OTA:Writelen 1460 at 44859
    Debug:OTA:Writelen 1460 at 46319
    Debug:OTA:write at flash: 0x0013e000
    Debug:OTA:Writelen 4380 at 47779
    Debug:OTA:write at flash: 0x0013f000
    Debug:OTA:Writelen 1460 at 52159
    Info:MAIN:Time 861, idle 0/s, free 78288, MQTT 1(3), bWifi 1, secondsWithNoPing 551, socks 0/0
    Debug:OTA:Writelen 1460 at 53619
    Debug:OTA:write at flash: 0x00140000
    Debug:OTA:Writelen 4380 at 55079
    Debug:OTA:Writelen 1460 at 59459
    Debug:OTA:write at flash: 0x00141000
    Debug:OTA:Writelen 4380 at 60919
    Debug:OTA:write at flash: 0x00142000
    Debug:OTA:Writelen 1460 at 65299
    Debug:OTA:Writelen 1460 at 66759
    Debug:OTA:write at flash: 0x00143000
    Debug:OTA:Writelen 4380 at 68219
    Debug:OTA:write at flash: 0x00144000
    Debug:OTA:Writelen 1460 at 72599
    Debug:OTA:Writelen 1460 at 74059
    Debug:OTA:write at flash: 0x00145000
    Debug:OTA:Writelen 4380 at 75519
    Debug:OTA:Writelen 1460 at 79899
    Debug:OTA:write at flash: 0x00146000
    Debug:OTA:Writelen 4380 at 81359
    Debug:OTA:write at flash: 0x00147000
    Debug:OTA:Writelen 1460 at 85739
    Debug:OTA:Writelen 1460 at 87199
    Debug:OTA:write at flash: 0x00148000
    Debug:OTA:Writelen 4380 at 88659
    Debug:OTA:write at flash: 0x00149000
    Debug:OTA:Writelen 1460 at 93039
    Debug:OTA:Writelen 1460 at 94499
    Debug:OTA:write at flash: 0x0014a000
    Debug:OTA:Writelen 4380 at 95959
    Debug:OTA:Writelen 1460 at 100339
    Debug:OTA:write at flash: 0x0014b000
    Debug:OTA:Writelen 4380 at 101799
    Debug:OTA:write at flash: 0x0014c000
    Debug:OTA:Writelen 1460 at 106179
    Debug:OTA:Writelen 1460 at 107639
    Debug:OTA:write at flash: 0x0014d000
    Debug:OTA:Writelen 4380 at 109099
    Debug:OTA:write at flash: 0x0014e000
    Debug:OTA:Writelen 1460 at 113479
    Debug:OTA:Writelen 1460 at 114939
    Debug:OTA:write at flash: 0x0014f000
    Debug:OTA:Writelen 4380 at 116399
    Debug:OTA:Writelen 1460 at 120779
    Debug:OTA:write at flash: 0x00150000
    Debug:OTA:Writelen 4380 at 122239
    Debug:OTA:write at flash: 0x00151000
    Debug:OTA:Writelen 1460 at 126619
    Debug:OTA:Writelen 1460 at 128079
    Debug:OTA:write at flash: 0x00152000
    Debug:OTA:Writelen 4380 at 129539
    Debug:OTA:write at flash: 0x00153000
    Debug:OTA:Writelen 1460 at 133919
    Debug:OTA:Writelen 1460 at 135379
    Debug:OTA:write at flash: 0x00154000
    Debug:OTA:Writelen 4380 at 136839
    Debug:OTA:Writelen 1460 at 141219
    Debug:OTA:write at flash: 0x00155000
    Debug:OTA:Writelen 4380 at 142679
    Debug:OTA:write at flash: 0x00156000
    Debug:OTA:Writelen 1460 at 147059
    Debug:OTA:Writelen 1460 at 148519
    Debug:OTA:write at flash: 0x00157000
    Debug:OTA:Writelen 4380 at 149979
    Debug:OTA:write at flash: 0x00158000
    Debug:OTA:Writelen 1460 at 154359
    Debug:OTA:Writelen 1460 at 155819
    Debug:OTA:write at flash: 0x00159000
    Debug:OTA:Writelen 4380 at 157279
    Debug:OTA:Writelen 1460 at 161659
    Debug:OTA:write at flash: 0x0015a000
    Debug:OTA:Writelen 4380 at 163119
    Debug:OTA:write at flash: 0x0015b000
    Debug:OTA:Writelen 1460 at 167499
    Debug:OTA:Writelen 1460 at 168959
    Debug:OTA:write at flash: 0x0015c000
    Debug:OTA:Writelen 4380 at 170419
    Info:MAIN:Time 862, idle 0/s, free 78288, MQTT 1(3), bWifi 1, secondsWithNoPing 552, socks 0/0
    Debug:OTA:write at flash: 0x0015d000
    Debug:OTA:Writelen 1460 at 174799
    Debug:OTA:Writelen 1460 at 176259
    Debug:OTA:write at flash: 0x0015e000
    Debug:OTA:Writelen 4380 at 177719
    Debug:OTA:Writelen 1460 at 182099
    Debug:OTA:write at flash: 0x0015f000
    Debug:OTA:Writelen 4380 at 183559
    Debug:OTA:write at flash: 0x00160000
    Debug:OTA:Writelen 1460 at 187939
    Debug:OTA:Writelen 1460 at 189399
    Debug:OTA:write at flash: 0x00161000
    Debug:OTA:Writelen 4380 at 190859
    Debug:OTA:write at flash: 0x00162000
    Debug:OTA:Writelen 1460 at 195239
    Debug:OTA:Writelen 1460 at 196699
    Debug:OTA:write at flash: 0x00163000
    Debug:OTA:Writelen 4380 at 198159
    Debug:OTA:Writelen 1460 at 202539
    Debug:OTA:write at flash: 0x00164000
    Debug:OTA:Writelen 4380 at 203999
    Debug:OTA:write at flash: 0x00165000
    Debug:OTA:Writelen 1460 at 208379
    Debug:OTA:write at flash: 0x00166000
    Debug:OTA:Writelen 4380 at 209839
    Debug:OTA:Writelen 1460 at 214219
    Debug:OTA:write at flash: 0x00167000
    Debug:OTA:Writelen 4380 at 215679
    Debug:OTA:write at flash: 0x00168000
    Debug:OTA:Writelen 1460 at 220059
    Debug:OTA:Writelen 1460 at 221519
    Debug:OTA:write at flash: 0x00169000
    Debug:OTA:Writelen 4380 at 222979
    Debug:OTA:Writelen 1460 at 227359
    Debug:OTA:write at flash: 0x0016a000
    Debug:OTA:Writelen 4380 at 228819
    Debug:OTA:write at flash: 0x0016b000
    Debug:OTA:Writelen 1460 at 233199
    Debug:OTA:Writelen 1460 at 234659
    Debug:OTA:write at flash: 0x0016c000
    Debug:OTA:Writelen 4380 at 236119
    Debug:OTA:write at flash: 0x0016d000
    Debug:OTA:Writelen 1460 at 240499
    Debug:OTA:Writelen 1460 at 241959
    Debug:OTA:write at flash: 0x0016e000
    Debug:OTA:Writelen 4380 at 243419
    Debug:OTA:Writelen 1460 at 247799
    Debug:OTA:write at flash: 0x0016f000
    Debug:OTA:Writelen 4380 at 249259
    Debug:OTA:write at flash: 0x00170000
    Debug:OTA:Writelen 1460 at 253639
    Debug:OTA:write at flash: 0x00171000
    Debug:OTA:Writelen 4380 at 255099
    Debug:OTA:Writelen 1460 at 259479
    Debug:OTA:write at flash: 0x00172000
    Debug:OTA:Writelen 4380 at 260939
    Debug:OTA:write at flash: 0x00173000
    Debug:OTA:Writelen 1460 at 265319
    Debug:OTA:Writelen 1460 at 266779
    Debug:OTA:write at flash: 0x00174000
    Debug:OTA:Writelen 4380 at 268239
    Debug:OTA:Writelen 1460 at 272619
    Debug:OTA:write at flash: 0x00175000
    Debug:OTA:Writelen 4380 at 274079
    Debug:OTA:write at flash: 0x00176000
    Debug:OTA:Writelen 1460 at 278459
    Debug:OTA:Writelen 1460 at 279919
    Debug:OTA:write at flash: 0x00177000
    Debug:OTA:Writelen 4380 at 281379
    Debug:OTA:write at flash: 0x00178000
    Debug:OTA:Writelen 1460 at 285759
    Debug:OTA:Writelen 1460 at 287219
    Debug:OTA:write at flash: 0x00179000
    Debug:OTA:Writelen 4380 at 288679
    Debug:OTA:Writelen 1460 at 293059
    Debug:OTA:write at flash: 0x0017a000
    Debug:OTA:Writelen 4380 at 294519
    Info:MAIN:Time 863, idle 0/s, free 78288, MQTT 1(3), bWifi 1, secondsWithNoPing 553, socks 0/0
    Debug:OTA:write at flash: 0x0017b000
    Debug:OTA:Writelen 1460 at 298899
    Debug:OTA:Writelen 1460 at 300359
    Debug:OTA:write at flash: 0x0017c000
    Debug:OTA:Writelen 4380 at 301819
    Debug:OTA:write at flash: 0x0017d000
    Debug:OTA:Writelen 1460 at 306199
    Debug:OTA:Writelen 1460 at 307659
    Debug:OTA:write at flash: 0x0017e000
    Debug:OTA:Writelen 4380 at 309119
    Debug:OTA:Writelen 1460 at 313499
    Debug:OTA:write at flash: 0x0017f000
    Debug:OTA:Writelen 4380 at 314959
    Debug:OTA:write at flash: 0x00180000
    Debug:OTA:Writelen 1460 at 319339
    Debug:OTA:Writelen 1460 at 320799
    Debug:OTA:write at flash: 0x00181000
    Debug:OTA:Writelen 4380 at 322259
    Debug:OTA:write at flash: 0x00182000
    TEMP: adc raw: 791, temp_IC: 33 Total:136552; Free:78288;
    Debug:OTA:Writelen 1460 at 326639
    Debug:OTA:Writelen 1460 at 328099
    Debug:OTA:write at flash: 0x00183000
    Debug:OTA:Writelen 4380 at 329559
    Debug:OTA:Writelen 1460 at 333939
    Debug:OTA:write at flash: 0x00184000
    Debug:OTA:Writelen 4380 at 335399
    Debug:OTA:write at flash: 0x00185000
    Debug:OTA:Writelen 1460 at 339779
    Debug:OTA:Writelen 1460 at 341239
    Debug:OTA:write at flash: 0x00186000
    Debug:OTA:Writelen 4380 at 342699
    Debug:OTA:write at flash: 0x00187000
    Debug:OTA:Writelen 1460 at 347079
    Debug:OTA:Writelen 1460 at 348539
    Debug:OTA:write at flash: 0x00188000
    Debug:OTA:Writelen 4380 at 349999
    Debug:OTA:Writelen 1460 at 354379
    Debug:OTA:write at flash: 0x00189000
    Debug:OTA:Writelen 4380 at 355839
    Debug:OTA:write at flash: 0x0018a000
    Debug:OTA:Writelen 1460 at 360219
    Debug:OTA:Writelen 1460 at 361679
    Debug:OTA:Writelen 674 at 363139
    Debug:OTA:write at flash: 0x0018b000
    Debug:OTA:cb info: recv 0 finished, no more data to deal with.
    Debug:OTA:http client job done, exit...
    Debug:OTA:Succeed to verify OTA image content.
    Debug:OTA:Succeed to verify OTA image content.
    Debug:OTA:363813 total bytes written
    Info:MAIN:Time 864, idle 0/s, free 89704, MQTT 1(3), bWifi 1, secondsWithNoPing 554, socks 0/0
    Info:MAIN:Time 865, idle 0/s, free 98088, MQTT 1(3), bWifi 1, secondsWithNoPing 555, socks 0/0


    That's strange, but that turned out to be one of the seldom times, it worked.

    Tested again:
    Info:MAIN:Time 112, idle 0/s, free 78496, MQTT 1(2), bWifi 1, secondsWithNoPing 47, socks 0/0 
    
    Firmware name: wifi_mcu_basic_example, hardware version: HW_V1.0, software version: SW_V1.0
    Fault on thread HTTP Clie
    ===== Thread stack information =====
      addr: 20033a28    data: 0001afdf
      addr: 20033a2c    data: 20019274
      addr: 20033a30    data: 200345f0
      addr: 20033a34    data: ffffff05
      addr: 20033a38    data: 0000ff06
      addr: 20033a3c    data: 1004221f
      addr: 20033a40    data: 200206a0
      addr: 20033a44    data: 00000014
      addr: 20033a48    data: a5a5a5a5
    


    And this is nothing but "pure HTTP", no Web App running, no Firefox and LN882H is crashing :-(.

    Added after 36 [minutes]:

    ... and my last test: Save Chromiums POST request to a file like before with a modified ota.vue ("sudo nc -l -p 88 > p88_chromium.out"):

    
    max@max:~/LN882H/OTA_issues$ head -n 12 p88_chromium.out 
    POST /api/ota HTTP/1.1
    Host: 10.42.0.1:88
    Connection: keep-alive
    Content-Length: 363813
    User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
    Accept: */*
    Origin: http://10.42.0.159
    Referer: http://10.42.0.159/
    Accept-Encoding: gzip, deflate
    Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
    
    
    �	%��������u�k��]
                           �       �R��Z����&�
    max@max:~/LN882H/OTA_issues$ 
    


    Sending the HTTP POST to the device ("cat p88_chromium.out | nc 10.42.0.159 80"):
    Spoiler:

    Info:MAIN:Time 53, idle 0/s, free 98280, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0
    Info:MAIN:Time 54, idle 0/s, free 98280, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0
    Info:MAIN:Time 55, idle 0/s, free 98280, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0
    Debug:API:POST to api/ota
    Debug:OTA:OTA post len 363813
    Debug:OTA:Ota start!
    Debug:OTA:Writelen 4014 at 0
    Debug:OTA:write at flash: 0x00133000
    Debug:OTA:[ota_download_precheck:1249] same version, do not upgrade!
    Debug:OTA:Writelen 2920 at 4014
    Debug:OTA:write at flash: 0x00134000
    Debug:OTA:Writelen 1460 at 6934
    Info:MAIN:Time 56, idle 0/s, free 78480, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0
    Debug:OTA:Writelen 1460 at 8394
    Debug:OTA:write at flash: 0x00135000
    Debug:OTA:Writelen 4380 at 9854
    Debug:OTA:Writelen 1460 at 14234
    Debug:OTA:write at flash: 0x00136000
    Debug:OTA:Writelen 4380 at 15694
    Debug:OTA:write at flash: 0x00137000
    Debug:OTA:Writelen 1460 at 20074
    Debug:OTA:Writelen 1460 at 21534
    Debug:OTA:write at flash: 0x00138000
    Debug:OTA:Writelen 4380 at 22994
    Debug:OTA:write at flash: 0x00139000
    Debug:OTA:Writelen 1460 at 27374
    Debug:OTA:write at flash: 0x0013a000
    Debug:OTA:Writelen 4380 at 28834
    Debug:OTA:Writelen 1460 at 33214
    Debug:OTA:write at flash: 0x0013b000
    Debug:OTA:Writelen 4380 at 34674
    Debug:OTA:Writelen 1460 at 39054
    Debug:OTA:write at flash: 0x0013c000
    Debug:OTA:Writelen 4380 at 40514
    Debug:OTA:write at flash: 0x0013d000
    Debug:OTA:Writelen 1460 at 44894
    Debug:OTA:write at flash: 0x0013e000
    Debug:OTA:Writelen 4380 at 46354
    Debug:OTA:Writelen 1460 at 50734
    Debug:OTA:write at flash: 0x0013f000
    Debug:OTA:Writelen 4380 at 52194
    Debug:OTA:write at flash: 0x00140000
    Debug:OTA:Writelen 1460 at 56574
    Debug:OTA:Writelen 1460 at 58034
    Debug:OTA:write at flash: 0x00141000
    Debug:OTA:Writelen 4380 at 59494
    Debug:OTA:Writelen 1460 at 63874
    Debug:OTA:write at flash: 0x00142000

    Firmware name: wifi_mcu_basic_example, hardware version: HW_V1.0, software version: SW_V1.0
    Fault on thread HTTP Clie
    ===== Thread stack information =====
    addr: 20033988 data: 0000ff36
    addr: 2003398c data: 20019274
    addr: 20033990 data: 20034980
    addr: 20033994 data: ffffffae
    addr: 20033998 data: 0000ff06
    addr: 2003399c data: 1004221f
    addr: 200339a0 data: 200202c8
    addr: 200339a4 data: 00000014
    addr: 200339a8 data: a5a5a5a5
    addr: 200339ac data: a5a5a5a5
    addr: 200339b0 data: 00a5a5a5
    addr: 200339b4 data: 2001942c
    addr: 200339b8 data: 200202cc
    addr: 200339bc data: 200202c8
    addr: 200339c0 data: 200202c8
    addr: 200339c4 data: 2001942c
    addr: 200339c8 data: 00000000
    addr: 200339cc data: 20036d96
    addr: 200339d0 data: 00000000
    addr: 200339d4 data: 000003f2
    addr: 200339d8 data: 20003330
    addr: 200339dc data: 0000ffff
    addr: 200339e0 data: 00000004
    addr: 200339e4 data: 00000001
    addr: 200339e8 data: 00000005
    addr: 200339ec data: 10090c28
    addr: 200339f0 data: 20033bb8
    addr: 200339f4 data: 1007fe7d
    addr: 200339f8 data: 200165b9
    addr: 200339fc data: 100442e3
    addr: 20033a00 data: 000003e3
    addr: 20033a04 data: ffff0208
    addr: 20033a08 data: 200165aa
    addr: 20033a0c data: 000003f2
    addr: 20033a10 data: 200202c8
    addr: 20033a14 data: 200202c8
    addr: 20033a18 data: 2001942c
    addr: 20033a1c data: 1003c6c9
    addr: 20033a20 data: 00000000
    addr: 20033a24 data: 00000006
    addr: 20033a28 data: 2001942c
    addr: 20033a2c data: 0000ffff
    addr: 20033a30 data: 00000000
    addr: 20033a34 data: 2002dec8
    addr: 20033a38 data: 00000000
    addr: 20033a3c data: 1002d075
    addr: 20033a40 data: 2002dec8
    addr: 20033a44 data: 00000000
    addr: 20033a48 data: 00000000
    addr: 20033a4c data: 1002d307
    addr: 20033a50 data: 00000000
    addr: 20033a54 data: 00000000
    addr: 20033a58 data: 00000000
    addr: 20033a5c data: 2002b100
    addr: 20033a60 data: 200169a4
    addr: 20033a64 data: 0000005d
    addr: 20033a68 data: 0000001b
    addr: 20033a6c data: 0000001b
    addr: 20033a70 data: 00000001
    addr: 20033a74 data: 00000000
    addr: 20033a78 data: 00000000
    addr: 20033a7c data: 10025d95
    addr: 20033a80 data: 0000011e
    addr: 20033a84 data: 00000000
    addr: 20033a88 data: 10047271
    addr: 20033a8c data: 20033abc
    addr: 20033a90 data: 2001fac8
    addr: 20033a94 data: 00000003
    addr: 20033a98 data: 2002ead8
    addr: 20033a9c data: ffffffe8
    addr: 20033aa0 data: 20034986
    addr: 20033aa4 data: 20033bb8
    addr: 20033aa8 data: fffffff8
    addr: 20033aac data: 2001650c
    addr: 20033ab0 data: 00000005
    addr: 20033ab4 data: 10090c28
    addr: 20033ab8 data: 20033bb8
    addr: 20033abc data: 1001fdeb
    addr: 20033ac0 data: 20033af4
    addr: 20033ac4 data: 000002e2
    addr: 20033ac8 data: 000000c1
    addr: 20033acc data: 10045e05
    addr: 20033ad0 data: 0000011e
    addr: 20033ad4 data: 10045e2f
    addr: 20033ad8 data: 20027150
    addr: 20033adc data: 10099af0
    addr: 20033ae0 data: fffffff9
    addr: 20033ae4 data: 1004609b
    addr: 20033ae8 data: 0000000d
    addr: 20033aec data: 100443d5
    addr: 20033af0 data: 00000000
    addr: 20033af4 data: 2002010c
    addr: 20033af8 data: 00000000
    addr: 20033afc data: 0000011e
    addr: 20033b00 data: 000002e2
    addr: 20033b04 data: 0000011e
    addr: 20033b08 data: 20019350
    addr: 20033b0c data: 1004656d
    addr: 20033b10 data: 00000000
    addr: 20033b14 data: 20019350
    addr: 20033b18 data: fffffff9
    addr: 20033b1c data: 10042559
    addr: 20033b20 data: a5a5a5a5
    addr: 20033b24 data: 00000000
    addr: 20033b28 data: a5a5a5a5
    addr: 20033b2c data: 00000000
    addr: 20033b30 data: a5a5a5a5
    addr: 20033b34 data: 00000400
    addr: 20033b38 data: 00000002
    addr: 20033b3c data: 00000000
    addr: 20033b40 data: 00000000
    addr: 20033b44 data: 20019350
    addr: 20033b48 data: 2003597e
    addr: 20033b4c data: a5a5a5a5
    addr: 20033b50 data: a5a5a5a5
    addr: 20033b54 data: 10042d0f
    addr: 20033b58 data: a5a5a5a5
    addr: 20033b5c data: a5a5a5a5
    addr: 20033b60 data: a5a5a5a5
    addr: 20033b64 data: a5a5a5a5
    addr: 20033b68 data: 20033bb8
    addr: 20033b6c data: 2002ead8
    addr: 20033b70 data: 20033bb8
    addr: 20033b74 data: 00000003
    addr: 20033b78 data: 2002ead8
    addr: 20033b7c data: 20033bb8
    addr: 20033b80 data: 20034986
    addr: 20033b84 data: 2001650c
    addr: 20033b88 data: 00000005
    addr: 20033b8c data: 10090c28
    addr: 20033b90 data: a5a5a5a5
    addr: 20033b94 data: 1001ec07
    addr: 20033b98 data: 00000400
    addr: 20033b9c data: 00000002
    addr: 20033ba0 data: 00000000
    addr: 20033ba4 data: 20033d48
    addr: 20033ba8 data: 20034980
    addr: 20033bac data: a5a5a5a5
    addr: 20033bb0 data: a5a5a5a5
    addr: 20033bb4 data: 1001c7c7
    addr: 20033bb8 data: 20034980
    addr: 20033bbc data: 0000111c
    addr: 20033bc0 data: 000013fe
    addr: 20033bc4 data: 00000002
    addr: 20033bc8 data: 20034986
    addr: 20033bcc data: 00000000
    addr: 20033bd0 data: 00000000
    addr: 20033bd4 data: 00000000
    addr: 20033bd8 data: 00000000
    addr: 20033bdc data: 00000000
    addr: 20033be0 data: 00000000
    addr: 20033be4 data: 00000000
    addr: 20033be8 data: 00000000
    addr: 20033bec data: 00000000
    addr: 20033bf0 data: 00000000
    addr: 20033bf4 data: 00000000
    addr: 20033bf8 data: 00000000
    addr: 20033bfc data: 00000000
    addr: 20033c00 data: 00000000
    addr: 20033c04 data: 00000000
    addr: 20033c08 data: 00000000
    addr: 20033c0c data: 00000000
    addr: 20033c10 data: 00000000
    addr: 20033c14 data: 00000000
    addr: 20033c18 data: 00000000
    addr: 20033c1c data: 00000000
    addr: 20033c20 data: 00000000
    addr: 20033c24 data: 00000000
    addr: 20033c28 data: 00000000
    addr: 20033c2c data: 00000000
    addr: 20033c30 data: 00000000
    addr: 20033c34 data: 00000000
    addr: 20033c38 data: 00000000
    addr: 20033c3c data: 00000000
    addr: 20033c40 data: 00000000
    addr: 20033c44 data: 00000000
    addr: 20033c48 data: 00000000
    addr: 20033c4c data: 00000000
    addr: 20033c50 data: 00000009
    addr: 20033c54 data: 20034998
    addr: 20033c58 data: 200349ac
    addr: 20033c5c data: 200349c4
    addr: 20033c60 data: 200349dc
    addr: 20033c64 data: 20034a4f
    addr: 20033c68 data: 20034a5c
    addr: 20033c6c data: 20034a78
    addr: 20033c70 data: 20034a96
    addr: 20033c74 data: 20034ab6
    addr: 20033c78 data: 00000000
    addr: 20033c7c data: 00000000
    addr: 20033c80 data: 00000000
    addr: 20033c84 data: 00000000
    addr: 20033c88 data: 00000000
    addr: 20033c8c data: 00000000
    addr: 20033c90 data: 00000000
    addr: 20033c94 data: 20034aee
    addr: 20033c98 data: 00000fae
    addr: 20033c9c data: 00058d25
    addr: 20033ca0 data: 000000c8
    addr: 20033ca4 data: 20033d48
    addr: 20033ca8 data: 00000000
    addr: 20033cac data: 000007ff
    addr: 20033cb0 data: 00000002
    addr: 20033cb4 data: 00000000
    addr: 20033cb8 data: a5a5a5a5
    addr: 20033cbc data: a5a5a5a5
    addr: 20033cc0 data: a5a5a5a5
    addr: 20033cc4 data: a5a5a5a5
    addr: 20033cc8 data: a5a5a5a5
    addr: 20033ccc data: 20000aed
    addr: 20033cd0 data: a5a5a5a5
    addr: 20033cd4 data: a5a5a5a5
    ====================================
    =================== Registers information ====================
    R0 : 20052006 R1 : 2004fbac R2 : fffe4d6e R3 : 00000000
    R12: 20036dda LR : 1001f0bb PC : 1007c93c PSR: a1000000
    ==============================================================
    Show more call stack info by run: arm-none-eabi-addr2line -e wifi_mcu_basic_example.elf -a -f 1007c93c 1001f0b7 1004221b 1007fe79 100442df 1003c6c5 1002d071 1002d303 10025d91 1004726d 1001fde7 10045e01 10045e2b 10046097 100443d1 10046569
    ------ Welcome to OpenBeken for the LN882H ------
    TCP/IP initialized.
    LN882H SDK Ver: 2.1_rc1 [build time:Nov 21 2024 15:23:25][0x02010001]
    Entering initLog()...


    So my actual guess now is: an HTTP POST fails very often on LN882H if the header is not in a separate TCP packet.
  • #265 21319958
    max4elektroda
    Level 20  
    I think I finally found it - see https://github.com/openshwprojects/OpenBK7231T_App/pull/1441

    OTA code is "collecting" data until a 4k buffer is filled.
    But it doesn't check, if the data provided will fill the 4k buffer twice.
    So its writing data outside the allocated memory in some cases.

    Checking the size should fix this, I could now update the firmware with Firefox and also simply writing the POST via "nc" works for me.
    The firmware would need some more testing - but just in case you should be prepared that OTA is broken and you need UART to recover...
  • #266 21320553
    max4elektroda
    Level 20  
    @p.kaczmarek2 could you please take a look at my PR?

    I need someone to proof, there really are two "bugs" in the OTA procedure, taken 1:1 from SDK examples.
    The issues I found are in the function "static int ota_persistent_write(const char *buf, const int32_t buf_len)" in rest_interface.c.

    But I think you can understand my corrections by simply trying to follow the function with an example:

    For simplification let's assume "SECTOR_SIZE_4KB=10;"

    First case: function is called e.g. with buffers of length 9

    Call will fill buffer up to 9 elements and setting temp4k_offset=9
    - this will trigger first error: because now temp4k_offset == (SECTOR_SIZE_4KB - 1)
    --> so buffer will be written, but it's missing the last (10th) entry
        --> my conclusion is, that line 1318 should read: if (temp4k_offset >= SECTOR_SIZE_4KB) {
          (in fact, it could be ==, for the offset should not be > SECTOR_SIZE_4KB, meaning we wrote outside allocated memory)

    Screenshot of code in rest_interface.c with a highlighted line of code.

    Second case (causing the issue seen with Firefox): function is called twice with buffers of length 8 and 14
    First call will fill buffer up to 8 elements and setting temp4k_offset=8
    Second call:
    - part_len now is: temp4k_offset + buf_len - SECTOR_SIZE_4KB --> 8 + 14 -10 = 12
    --> note: part_len now is > 10 !
    - will fill buffer up to 10th element, setting temp4k_offset=10 (that's o.k.)
    - temp4k_offset >= (SECTOR_SIZE_4KB - 1) and buffer will be written (that's o.k.)
    - since part_len > 0, this code is called:
    memcpy(temp4K_buf + temp4k_offset, buf + (buf_len - part_len), part_len);
    --> will try to copy 12 elements to a 10 element buffer (that's not o.k.)
    temp4k_offset += part_len;
    --> since memcpy will probably fail, it doesn't matter so much that temp4k_offset will be 12 (that's not o.k.)
        --> my conclusion: we need to do the loop repeatedly, until buf_len is < SECTOR_SIZE_4KB
  • #267 21320571
    XJ_
    Level 11  
    max4elektroda wrote:
    (in fact, it could be ==, for the offset should not be > SECTOR_SIZE_4KB, meaning we wrote outside allocated memory)

    Written is always just delta, there is no oveflow
                    part_len = temp4k_offset + buf_len - SECTOR_SIZE_4KB;
          memcpy(temp4K_buf + temp4k_offset, buf, buf_len - part_len);
    

    And to the flash is writeen always SECTOR_SIZE_4KB, there is not overflow too
    hal_flash_program(flash_ota_start_addr + flash_ota_offset, SECTOR_SIZE_4KB, (uint8_t *)temp4K_buf);



    max4elektroda wrote:
    my conclusion is, that line 1318 should read: if (temp4k_offset >= SECTOR_SIZE_4KB) {



    hal_flash_program(flash_ota_start_addr + flash_ota_offset, SECTOR_SIZE_4KB, (uint8_t *)temp4K_buf);
    I agree, the "-1" sholud not be there

    Added after 6 [minutes]:

    >>21320553
    There can be overflow, if buf_len > SECTOR_SIZE_4KB or if last part "buf_len" is bigger than rest of buffer
    Edit: but only if the buf_len twice bigger than SECTOR_SIZE_4KB

    Added after 16 [minutes]:

    max4elektroda wrote:
    called twice with buffers of length 8 and 14

    this routine should not be called with buf_len > SECTOR_SIZE_4KB (as in your example, 14>10)

    Added after 27 [minutes]:

    I wrote test program, and overflow happen always, if the buf_len is bigger than SECTOR_SIZE_4KB.
    It is happen after SECTOR_SIZE_4KB / (buf_len-SECTOR_SIZE_4KB) calls

    The procedure itself is not designed to receive more than SECTOR_SIZE_4KB bytes in one call.
  • #268 21320645
    max4elektroda
    Level 20  
    XJ_ wrote:
    Written is always just delta, there is no oveflow
                 part_len = temp4k_offset + buf_len - SECTOR_SIZE_4KB;
          memcpy(temp4K_buf + temp4k_offset, buf, buf_len - part_len);

    Not in this code, but here (line 1340 in the original code) after writing to flash, this code is called:

       if (part_len > 0) {
          memcpy(temp4K_buf + temp4k_offset, buf + (buf_len - part_len), part_len);
          temp4k_offset += part_len;
       }

    And it can be that "part_len > SECTOR_SIZE_4KB" as pointed out.

    XJ_ wrote:
    this routine should not be called with buf_len > SECTOR_SIZE_4KB (as in your example, 14>10)

    Maybe it should not (and probably is not in the original OTA code with an HTTP GET) but it did happen in the actual code.
    See this part from the log above:
    
    Debug:OTA:write at flash: 0x00135000
    Debug:OTA:Writelen 4380 at 9819
    Debug:OTA:Writelen 1460 at 14199
    Debug:OTA:write at flash: 0x00136000
    Debug:OTA:Writelen 4380 at 15659
    Debug:OTA:write at flash: 0x00137000
    

    And 4380 is bigger than 4096, so buffer is filled e.g. to 4000, the original code will write one 4k slice to flash and later try to copy the remaining 4284 bytes to the 4096 byte memory.
    So I made it work in this case, too (at least I tried).
  • #269 21320666
    XJ_
    Level 11  
    >>21320645

    call 1
    input : len=12
    memcpy buf: 0 0 10 <<first call memcpy @ line 1308
    memcpy buf: 0 10 2 <<second call memcpy @ line 1341

    call 2
    input : len=12
    memcpy buf: 2 0 8
    memcpy buf: 0 8 4

    call 3
    input : len=12
    memcpy buf: 4 0 6
    memcpy buf: 0 6 6

    call 4
    input : len=12
    memcpy buf: 6 0 4
    memcpy buf: 0 4 8

    call 5
    input : len=12
    memcpy buf: 8 0 2
    memcpy buf: 0 2 10

    call 6
    input : len=12
    memcpy buf: 10 0 0
    memcpy buf: 0 0 12 <<<error
    error

    max4elektroda wrote:
    And 4380 is bigger than 4096, so buffer is filled e.g. to 4000, the original code will write one 4k slice to flash and later try to copy the remaining 4284 bytes to the 4096 byte memory.
    So I made it work in this case, too (at least I tried).

    Then it must be splitted to smaler parts before calling ota_persistent_write
  • #270 21320676
    max4elektroda
    Level 20  
    I think it doesn't matter if we split the data before calling ota_persistent_write or "simply" change ota_persistent_write to handle input of bigger buffers, too.
    It was all there, just test in a loop, if the write-buffer can be filled completely, then write it to flash, and test again, until the write-buffer is not completely filled.

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