logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 42645 297
ADVERTISEMENT
  • ADVERTISEMENT
  • #152 21052818
    p.kaczmarek2
    Moderator Smart Home
    So you guys are saying that DHT11 is still not working on LN882H? I need to find some time and hook up my LN882H and scope to check...
    Helpful post? Buy me a coffee.
  • #153 21052927
    max4elektroda
    Level 20  
    @divadiow : I just opened PR#1186 as a slight extension to PR#1143:

    Using "PowerSave 1" should work as in the release versions, e.g. should work with power metering using interrupt counting like BL0937.
    But if you don't need this feature you could also use "PowerSave 2" to enable sleep mode.

    BTW: When using "sleep mode" I see random WiFi "reconnects" due to errors in log:

    Info:MAIN:Time 48, idle 0/s, free 98840, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    TEMP: adc raw:  776, temp_IC:   27 Total:137112; Free:98840;
    Info:MAIN:Time 49, idle 0/s, free 98840, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    +--------------- net device info ------------+
    |netif type    : STA                         |
    |netif hostname: ln_sta                      |
    |netif ip      = 192.168.0.58                |
    |netif mask    = 255.255.255.0               |
    |netif gateway = 192.168.0.1                 |
    |netif mac     : [00:50:XX:XX:XX:XX]         |
    +--------------------------------------------+
    Info:MAIN:Time 50, idle 0/s, free 98096, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    Info:MAIN:Time 51, idle 0/s, free 98840, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    [WLIB_I]W:F13=0x00004F6E, PA=0x87024C8D, RT=0x04160241
    [WLIB_I]W:EN_BP,LLS_CNT = 12
    [WLIB_I]W:F13=0x00004F6E, PA=0x87524C8D, RT=0x04160263
    [WLIB_I]W:EN_BP,LLS_CNT = 14
    [WLIB_I]W:F13=0x00004F6F, PA=0x87524C8D, RT=0x0416028B
    [WLIB_I]W:EN_BP,LLS_CNT = 16
    [WLIB_I]W:F13=0x00004F6F, PA=0x87524C8D, RT=0x041602B1
    [WLIB_I]W:EN_BP,LLS_CNT = 18
    Info:MAIN:Time 52, idle 0/s, free 98840, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    [WLIB_I]W:F13=0x00004F74, PA=0x87524C8D, RT=0x041602D9
    [WLIB_I]W:EN_BP,LLS_CNT = 20
    [WLIB_I]W:F13=0x00004F6E, PA=0x87524C8D, RT=0x04160302
    [WLIB_I]W:EN_BP,LLS_CNT = 22
    [WLIB_I]W:F13=0x00004F6E, PA=0x87524C8D, RT=0x0416032A
    [WLIB_I]W:EN_BP,LLS_CNT = 24
    [WLIB_I]W:F13=0x00004F74, PA=0x87524C8D, RT=0x04160352
    [WLIB_I]W:EN_BP,LLS_CNT = 26
    [WLIB_I]W:F13=0x00004F74, PA=0x87524C8D, RT=0x0416037E
    [WLIB_I]W:EN_BP,LLS_CNT = 28
    Info:MAIN:Time 53, idle 0/s, free 98840, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    [WLIB_I]W:F13=0x00004F6F, PA=0x87524C8D, RT=0x041603A4
    [WLIB_I]W:EN_BP,LLS_CNT = 30
    [WLIB_I]W:F13=0x00004F70, PA=0x87524C8D, RT=0x041603CB
    [WLIB_I]W:EN_BP,LLS_CNT = 32
    [WLIB_I]W:F13=0x00004F74, PA=0x87524C8D, RT=0x041603F2
    [WLIB_I]W:EN_BP,LLS_CNT = 34
    [WLIB_I]W:F13=0x00004F74, PA=0x87524C8D, RT=0x04160416
    [WLIB_I]W:EN_BP,LLS_CNT = 36
    [WLIB_I]W:F13=0x00004F74, PA=0x87524C8D, RT=0x0416043C
    [WLIB_I]W:EN_BP,LLS_CNT = 38
    Info:MAIN:Time 54, idle 0/s, free 98840, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    [WLIB_I]W:F13=0x00004F6F, PA=0x87524C8D, RT=0x04160464
    [WLIB_I]W:EN_BP,LLS_CNT = 40
    [WLIB_E]System-Error = 0xc1
    [WLIB_I]Disconnected.
    STA disconnected to target AP!
    [WLIB_I]Disconnected.
    [WLIB_I]Status: Scan Successful. Initiating Join: 
    [WLIB_I]SSID      = MYSSID
    [WLIB_I]BSSID     = 00:11:22:33:44:55
    [WLIB_I]Channel   = 8
    [WLIB_I]RSSI      = -61
    [WLIB_I]StationID = XX:XX:XX:XX:XX:XX
    [WLIB_I]Status: Initiating Authentication.
            CH= 8,RSSI= -62,BSSID:[11:22:33:44:55:66],SSID:"MYSSID"
            CH= 8,RSSI= -63,BSSID:[22:33:44:55:66:77],SSID:"SSID1"
            CH=12,RSSI= -78,[WLIB_I]Status: Authentication Successful. Initiating Association.
    BSSID:[11:22:33:44:55:66],SSID:"MYSSID"
    [WLIB_I]Peer's HT-Capabilities:
    [WLIB_I]ht_capable             = 1
    [WLIB_I]ldpc_cod_cap           = 0
    [WLIB_I]smps_mode              = 3
    [WLIB_I]greenfield             = 0
    [WLIB_I]short_gi_20            = 1
    [WLIB_I]short_gi_40            = 0
    [WLIB_I]rx_stbc                = 0
    [WLIB_I]max_rx_ampdu_factor    = 3
    [WLIB_I]min_mpdu_start_spacing = 5
    [WLIB_I]htc_support            = 0
    [WLIB_I]sta_amsdu_maxsize      = eff
    [WLIB_I]chan_width             = 0
    [WLIB_I]dsss_cck_40mhz         = 0
    [WLIB_I]Status: Association Successful.
    [WLIB_I]Connected.
    [WLIB_I]sta_conn_step_set: CONNECTED
    STA connected to target AP!
    Info:MAIN:Main_OnWiFiStatusChange - WIFI_STA_CONNECTED - 4
    Info:MAIN:Time 55, idle 0/s, free 100464, MQTT 0(3), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    Info:MQTT:mqtt_host empty, not starting mqtt
    Info:MAIN:Time 56, idle 0/s, free 100464, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    Info:MAIN:Time 57, idle 0/s, free 100464, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    +--------------- net device info ------------+
    |netif hostname: ln_sta                      |
    |netif ip      = 192.168.0.58                |
    |netif mask    = 255.255.255.0               |
    |netif gateway = 192.168.0.1                 |
    |netif mac     : [00:50:XX:XX:XX:XX]         |
    +--------------------------------------------+
    Info:MAIN:Time 58, idle 0/s, free 100464, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    TEMP: adc raw:  787, temp_IC:   31 Total:137112; Free:100464;
    Info:MAIN:Time 59, idle 0/s, free 98096, MQTT 0(4), bWifi 1, secondsWithNoPing -1, socks 0/0 POWERSAVE
    +--------------- net device info ------------+
    
  • #154 21055168
    divadiow
    Level 34  
    max4elektroda wrote:
    I just opened PR#1186 as a slight extension to PR#1143:


    OK. so it's not a measurement of power use as such, but using this PR and "powersave 2" seems to be the only powersave mode so far that makes
    this bulb usable for me. Temperatures are 60+ and then it'll crash otherwise, all within a minute or two of lighting the bulb. This is with LED current limited to "BP5758D_Current 2 2".

    The longest this device has ever stayed online, with the lowest temps, with the bulb lit:
    Screenshot of the OpenLN882H_C25E1088 LED bulb management software interface.

    "powersave 2" loaded manually after boot as startup command set still means no device working and safe mode required to change back.

    I did add a small heatsink, but still it would get too hot with powersave 1. And it shouldn't need one.

    Close-up of the inside of an LED bulb with a small heat sink visible.
  • #155 21055190
    p.kaczmarek2
    Moderator Smart Home
    Wait a moment, by "gets too hot", do you mean that you've measured the temperature externally in some reliable way, or do you base your conclusions on the internal temperature of LN882H? I don't know how well the calibration of that internal temperature may be, so I would take care with interpreting that.
    Helpful post? Buy me a coffee.
  • #156 21055191
    Piorun2002
    Level 15  
    I have two switches (relay) on LN882 and OpenBK,
    In the off state the temperatures are as follows:
    #1 Internal temperature: 66.7°C
    #2 Internal temperature: 61.5°C

    Should it be like that?
  • #157 21055199
    divadiow
    Level 34  
    p.kaczmarek2 wrote:
    Wait a moment, by "gets too hot", do you mean that you've measured the temperature externally in some reliable way, or do you base your conclusions on the internal temperature of LN882H? I don't know how well the calibration of that internal temperature may be, so I would take care with interpreting that.


    I have not measured the external temperature, no. I only have the internal to go on. The only things that are knowns are that the temperature reading is seemingly way lower with powersave 2 and the bulb stays working.

    Added after 1 [minutes]:

    Piorun2002 wrote:
    I have two switches (relay) on LN882 and OpenBK,
    In the off state the temperatures are as follows:
    #1 Internal temperature: 66.7°C
    #2 Internal temperature: 61.5°C

    Should it be like that?


    with Build on Apr 20 2024 13:12:55 version 1186_merge_02081583662a?
  • #158 21055207
    Piorun2002
    Level 15  
    Build on Apr 15 2024 15:04:48 version 1.17.546, so I will do the upgrade

    Dodano po 35 [minuty]:

    Quote:

    Piorun2002 wrote:
    I have two switches (relay) on LN882 and OpenBK,
    In the off state the temperatures are as follows:
    #1 Internal temperature: 66.7°C
    #2 Internal temperature: 61.5°C

    Should it be like that?


    with Build on Apr 20 2024 13:12:55 version 1186_merge_02081583662a?


    Where can I download it?
    I tested these: 1.17.546 and 1.17.553
  • ADVERTISEMENT
  • #160 21055291
    max4elektroda
    Level 20  
    Piorun2002 wrote:

    Where can I download it?

    Just as an additional hint to the information from divadiow:
    You need an account and need to be logged in to git in order to see and download these files.
  • ADVERTISEMENT
  • #162 21055335
    Piorun2002
    Level 15  
    Online for 8 minutes and 21 seconds
    #1 Build on Apr 21 2024 08:20:54 version 1.17.553, Internal temperature: 65.2°C
    #2 Build on Apr 20 2024 13:12:55 version 1186_merge_02081583662a, Internal temperature: 64.8°C

    Do I need to set something in the configuration?
  • ADVERTISEMENT
  • #163 21055350
    max4elektroda
    Level 20  
    Yes, you need to set the "PowerSave" to 1 or even 2.
    In case you didn't see this an additional warning:
    Don't set "PowerSave 2" as startup command or the device won't connect to WiFi.
    You need to set it later as a command.
  • #164 21055421
    Piorun2002
    Level 15  
    Before:
    Internal temperature: 64.0°C
    Reply from 192.168.10.157: bytes=32 time=1ms TTL=255
    Reply from 192.168.10.157: bytes=32 time=4ms TTL=255

    After PowerSave 2:
    Internal temperature: 36.0°C
    Reply from 192.168.10.157: bytes=32 time=56ms TTL=255
    Reply from 192.168.10.157: bytes=32 time=73ms TTL=255

    After PowerSave 1:
    Internal temperature: 47.2°C
    Reply from 192.168.10.157: bytes=32 time=31ms TTL=255
    Reply from 192.168.10.157: bytes=32 time=63ms TTL=255
  • #165 21055655
    p.kaczmarek2
    Moderator Smart Home
    Those are a very promising results. Is the WiFi stable?


    Maybe we should do some kind of internal work-around for power save so it can stay in short startup command but is still fired after wifi connection internally?
    Helpful post? Buy me a coffee.
  • #166 21055670
    max4elektroda
    Level 20  
    That would probably be the best solution, I just didn't find the time to figure out the startup process yet and how to delay the actual setting (especially when this has to be limited to one platform).
    If you can point out where to look, I could try (but only next weekend).

    BTW: it's so annoying not to have the source of wifi library.
    I really would like to have a look there and e.g. find out, what the error/reconnect I saw in the log #153 is about...
  • #167 21055731
    Piorun2002
    Level 15  
    p.kaczmarek2 wrote:
    Those are a very promising results. Is the WiFi stable?

    good enough - HA (over MQTT) can turn on/off without delay
  • #168 21062931
    Piorun2002
    Level 15  
    After installing the switch into the installation box, the switch heats up to 70C, and in the PowerSave mode only 32C.
    From what I understand, it is not possible to execute the PowerSave 2 command with a delay in OpenBK itself.
    Could advice me how to create a script / triger in OpenHAB to enable PowerSave 2 mode after the switch sends a message to MQTT that it is online?
  • #169 21063418
    max4elektroda
    Level 20  
    You can call the command from remote, e.g. via wget or curl, like
    curl 'http://<IP.of.your.device>/cmd_tool?cmd=PowerSave+2'
  • #170 21063719
    p.kaczmarek2
    Moderator Smart Home
    I pushed an attempt to fix that, the code now sets powersave for LN882H in STA connect callback. I haven't tested it. Can anyone test?

    Full PR link:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1186
    My changes;
    https://github.com/openshwprojects/OpenBK7231...mits/68fd014f193a3e5e0ea72c203d5c74bd27a5bad8
    Helpful post? Buy me a coffee.
  • #171 21063738
    max4elektroda
    Level 20  
    Quick test:

    [EDIT:]
    Sorry, first reply (doesn't work) was too fast (somehow update didn't work and I tested an other version)

    It works as expected!
    Autostart will use PowerSave 1 or 2 and Wifi is connected!!!
  • #172 21063748
    p.kaczmarek2
    Moderator Smart Home
    Ok but what if it connects, and then you, for example, turn off the router, wait 15 minutes, and chip tries to reconnect? Is the reconnection broken then?

    Do I have to turn off the PowerSave in STA disconnect callback?
    Helpful post? Buy me a coffee.
  • #173 21063753
    max4elektroda
    Level 20  
    I will test this tomorrow with settings 1 and 2
    [Edit]
    I can say that the reconnect after the "PowerSave 2" setting and WiFi error (see above) works
  • #174 21063767
    p.kaczmarek2
    Moderator Smart Home
    Ok, maybe also @divadiow can check? I would like to merge that PR.
    Helpful post? Buy me a coffee.
  • #175 21064064
    max4elektroda
    Level 20  
    Here are my results after further testing:

    PowerSave works as a startup command as expected: After connection to WiFi the measured current drawn is reduced, in my case when measureing the 3.3V current used by a single module from approx 90 mA to 50 (PowerSave 1) or 35 mA (PowerSave 2).

    When connection to Wifi is lost (router down), it will start trying to reconnect without any pause between network scans for ~ 150 seconds. During this time power is even increased to near 100mA.
    After this period it will do network scans every 10 seconds or so - current at ~ 90mA (like without PowerSave).

    When router or AP is back, it will reconnect and power drops again to the expected current.

    BUT: After the reconnect (here with PowerSave 1) I couldn't effectively change PowerSave - not to 2, even not to 0. It stayed at PowerSave 1.
    At least, that's what my multimeter showed - the logs followed the command and displayed PowerSave 2 or no PowerSave - only there was no change in current drawn.

    Trying to disconnect AP again (this time it didn't cause the "intense" try for reconnect but module used the "normal" scan every 10 to 20 seconds) and after another reconnect, it stayed in "PowerSave 0" (that was the last state I configured) even if I set PowerSave to 2.

    Testing another period with no AP (this time 150 seconds of heavy scanning) - And after another reconnect, it ended up in PowerSave 2 mode

    So there is a drawback: You can't use PowerSave as a "regular user command" any more - changes are reflected in logs, but current won't change.
    So it looks like changing this is ONLY possible during connection of WiFi.

    What we would need would be something like: only set PowerSave while Wifi is connected, not only during completion of connection ...

    Added after 1 [hours] 41 [minutes]:

    Maybe just move this code

    #if defined(PLATFORM_LN882H)
    		// LN882H hack, maybe place somewhere else?
    		// this will be applied after WiFi connect
    		if (g_ln882h_pendingPowerSaveCommand != -1) {
    			LN882H_ApplyPowerSave(g_ln882h_pendingPowerSaveCommand);
    			g_ln882h_pendingPowerSaveCommand = -1;
    		}
    #endif


    into "void Main_OnEverySecond()"
    under the case
    if (g_bHasWiFiConnected) {
    ?

    I can't promise, but I will try to code it later today ...

    Added after 1 [hours] 16 [minutes]:

    Updated the PR accordingly and installed the generated image:

    Changes see here

    During my tests everything worked now:
    - Startup command is applied after Wifi is connected
    - every change of PowerSave in the Command Tool is applied
  • #176 21064277
    p.kaczmarek2
    Moderator Smart Home
    Sure, I can accept this change, we could maybe improve it a bit (in powersave command check whether sta is connected, if yes, do immediatelly change, otherwise delay it until connect event), but this "on every second" callback is called... well, on every second, and checking integer variable on every second is not really that costly, so I think we can go with current version.

    So, shall I merge? @divadiow ?
    Helpful post? Buy me a coffee.
  • #177 21064290
    max4elektroda
    Level 20  
    That was my idea, to. I think we could also move it to the "every ten second" part where network infos are printed.
    But if we can do the "sta connected" test during powersave command - even better.
    I would then suggest to simply ignore a command when WiFi is not connected and just print a warning message in this rare/impossible(?) case - you probably can't change this over the network if WiFi is down, only a scripted change would fail.

    So if this is possible: leave the "delayed" part as you proposed, but only delay startup command and the other changes are only done, if WiFi is connected.

    Added after 12 [minutes]:

    Thinking a second time:
    Just do your proposal: - If WiFi is disconnected, do change delayed, during WiFi connect callback as you proposed - this is the next possible point, where a change can happen.
    If WiFi is present, do the change immediately.
  • #178 21064321
    divadiow
    Level 34  
    p.kaczmarek2 wrote:
    So, shall I merge? @divadiow ?


    Hi sorry I've not had time to engage with this further yet. I can this evening if still required by then
  • #179 21064462
    max4elektroda
    Level 20  
    I hope this version is o.k. now - it works for me (and there is no need to check every second ;-)).
  • #180 21064516
    p.kaczmarek2
    Moderator Smart Home
    This is a better version, just what about AP mode? I think we can ignore it altogether?
    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