logo elektroda
logo elektroda
X
logo elektroda

OpenLN882H upgrade from 1.17.506 to 1.17.515 makes LSPA9 Smart Plug unresponsive

silvestro_gatto 6141 66
Best answers

Why does upgrading OpenLN882H from 1.17.506 to 1.17.515 make my LSPA9 smart plug become unresponsive, and how can I fix it?

The freeze is caused by the NTP/time conversion code on LN882H, not by the plug template or the LED drivers: starting NTP on affected builds leads to bad `gmtime()` usage with a `g_ntpTime` value that is the wrong type/size for platforms where `time_t` is 64-bit, which can make the device behave erratically or hang [#21018282] [#21019583] A temporary workaround was to cast through a real `time_t` variable before calling `gmtime()`, and that immediately stopped the freeze in testing [#21018282] The proper fix was then merged by changing the NTP time handling to use `time_t` consistently, including related NTP event and JSON/httpserver paths [#21020171] After that fix, the reporter confirmed OpenLN882H_1.17.521 was stable again and settings were preserved [#21020355]
Generated by the language model.
ADVERTISEMENT
  • #31 21018300
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    That's interesting, can you open a pull request with your changes?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #32 21018347
    max4elektroda
    Level 24  
    Posts: 754
    Help: 48
    Rate: 187
    I feared that question, I never managed to get further with git than doing a git clone and work on this copy.

    Hope I did it right: #1141
  • ADVERTISEMENT
  • #33 21018361
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    Pull requests are easy with Github GUI. You did well.
    I've accepted the run, binaries should be available soon...
    Helpful post? Buy me a coffee.
  • #34 21018404
    Raufaser
    Level 10  
    Posts: 47
    Help: 3
    Rate: 16
    What I can see in the PR, the build seems to have been successfull. But were is the release?

    Added after 6 [minutes]:

    Hey, that fix seems to help :)

    Info:NTP:NTP driver initialized with server=217.147.223.78, offset=0
    Info:MAIN:Started NTP.
    Info:CMD:[WebApp Cmd 'startDriver NTP' Result] OK
    Info:MAIN:Time 55, idle 0/s, free 99832, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:NTP:Seconds since Jan 1 1900 = 3920307516
    Info:NTP:Unix time  : 1711318716
    Info:NTP:Local Time : 2024/03/24 22:18:36
    Info:MQTT:Publishing val 0.000 to smartsocket003/current/get retain=0
    Info:MQTT:Publishing val 0.00 to smartsocket003/power_apparent/get retain=0
    Info:MQTT:Publishing val 0.00 to smartsocket003/power_reactive/get retain=0
    Info:MQTT:Publishing val 1.00 to smartsocket003/power_factor/get retain=0
    Info:MAIN:Time 56, idle 0/s, free 97096, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic smartsocket003/current/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic smartsocket003/power_apparent/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic smartsocket003/power_reactive/get
    Info:MQTT:MQTT client in mqtt_incoming_publish_cb topic smartsocket003/power_factor/get
    Info:MAIN:Time 57, idle 0/s, free 100064, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 58, idle 0/s, free 94728, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 59, idle 0/s, free 94728, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0 
    Info:MAIN:Time 60, idle 0/s, free 100184, MQTT 1(2), bWifi 1, secondsWithNoPing -1, socks 0/0 


    It got the right time. And it didn't freeze! Good job!
  • #35 21018432
    silvestro_gatto
    Level 7  
    Posts: 30
    Rate: 4

    >>21018361

    I tested PR OpenLN882H_1141_merge_73f141c57851 build and it is working fine with me: module does not become unresponsive and all the settings are correctly restored from previous release. Thank you @max4elektroda and @p.kaczmarek2 !!!

    @p.kaczmarek2 should I click on Button with the text Solved - close topic. to close the topic?
  • #36 21018487
    max4elektroda
    Level 24  
    Posts: 754
    Help: 48
    Rate: 187

    I think there are some other code parts with the same function, which should be addressed, too. Namely in ntp_events.c and the json code in the httpserver directory (as stated in the "issue"). I think I won't be able to look into this today cause I'm quite busy today.
    And we need to get straight, why this fails here: was the code not totally correct or is there an issue with LN882H implementation of gmtime or casting of addresses...
  • #37 21018509
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    It's not fully solved yet.

    What is the sizeof(g_ntpTime) and the sizeof(time_t)? Maybe those other platforms are using 64-bit time_t while g_ntpTime is 32-bit?
    Helpful post? Buy me a coffee.
  • #39 21019175
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    Why do you think that adding "static" changes anything?

    Adding "static" will makes this array live only in this file.
    Helpful post? Buy me a coffee.
  • #40 21019188
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29

    Fixes the time bug for me on bl602, not very familiar with c, still should be static, as others, does not used anywhere else
  • #41 21019519
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    This only hides the issue by changing the order stuff is allocated in RAM. I think the sizeof(time_t) is different than sizeof(int).

    Can anyone with BL602 or LN882H update to latest public release and run TimeSize command?
    See my results on Windows:
    Screenshot of the command line tool named WinTest_3145CAFF displaying the result of the TimeSize command.
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • #43 21019532
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    And this is the solution, just as I said. The time_t is 64 bit on that platform, so using a global integer (32 bit) pointer as time_t pointer results in using time_t with half of bits unspecified (depending on the content of RAM).

    This is not a perfect solution:
    Code comment fragment about changing the use of the time_t structure in programming.
    I need to change the type of g_ntpTime to time_t, just I hope it won't break anything else
    Helpful post? Buy me a coffee.
  • Helpful post
    #44 21019543
    divadiow
    Level 38  
    Posts: 5039
    Help: 438
    Rate: 891
    Screenshot of the OpenBK Command Tool interface.
  • ADVERTISEMENT
  • #45 21019555
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    Again 64-bit? So two platforms were affected! Good job finding that, thanks to all people who reported issues. Now, well, what does the same command say on Beken?
    Helpful post? Buy me a coffee.
  • Helpful post
    #46 21019571
    divadiow
    Level 38  
    Posts: 5039
    Help: 438
    Rate: 891
    Screenshot of the OpenBK_BK7231T_Desk_Calex_Plug tool interface. Screenshot of OpenBK tool with command timesize entered in the console.
  • #47 21019583
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    So this explain why it was working on the initial version for Beken. So, to sum up, time_t is 32-bit size on Beken but it's already 64-bit on LN882H and BL602. Futhermore, on Windows, I can control the size of time_t by using _USE_32BIT_TIME_T define.

    Here is a correct fix:
    https://github.com/openshwprojects/OpenBK7231T_App/pull/1146
    Can you check this on devices with:
    - BK7231
    - LN882H
    - BL602
    while making sure that in worst case scenario you can recover via UART?
    Still, it should be good, as I already got report from @DeDaMrAz saying that it works for him...
    Helpful post? Buy me a coffee.
  • #48 21019595
    miegapele
    Level 16  
    Posts: 173
    Help: 15
    Rate: 29

    Tested both bl602 and bk7231n, works fine with bl0937, ntp, ssdp drivers
  • #49 21019604
    DeDaMrAz
    Level 22  
    Posts: 602
    Help: 34
    Rate: 129
    Both N and BL modules OTA flashed without problems, startDriver NTP works on both, so far no hangs no errors - version fix OTA files used.
  • #50 21019619
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    So I guess this testing-only fork is also no longer needed?
    Screenshot of a GitHub pull request for an open-source project showing changes in a configuration file.
    I will close the PR above and I will merge my proposed fix tomorrow if no issues arise.
    Helpful post? Buy me a coffee.
  • #51 21019625
    max4elektroda
    Level 24  
    Posts: 754
    Help: 48
    Rate: 187

    p.kaczmarek2 wrote:

    This is not a perfect solution:

    No, it's not.

    Changing g_ntpTime to time_t is probably the best to do, for if it's 4 bytes, nothing should change, and for 8 bytes it should work now.

    On the other hand: converting a uint64_t time_t to a uint32_t shouldn't cause any problem this century, but in 2106:
    
    max@max-PC:~$ date -d "@$((0xFFFFFFFF))"
    So 7. Feb 07:28:15 CET 2106
    max@max-PC:~$ 
    

  • #52 21019631
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    I still haven't done the full migration because there are also "Get time with offset" functions which are not yet changed to time_t, but that's lower priority, we have time until like... idk, 2038?

    @ElektrodaBot when will time_t overflow? What are the time_t types?
    Helpful post? Buy me a coffee.
  • #53 21019647
    ElektrodaBot
    AI OpenAI ChatGPT4
    Posts: 8809
    Help: 357
    Rate: 936
    p.kaczmarek2 wrote:
    when will time_t overflow? What are the time_t types?
    Hello! It's a great question you've brought up, especially considering how crucial understanding the `time_t` data type is for many applications.

    ### What is `time_t`?

    `time_t` is a data type used in C and C++ programming languages to represent time. It generally counts the number of seconds elapsed since the Unix epoch, which began at 00:00:00 UTC on 1 January 1970.

    ### When will `time_t` overflow?

    The overflow issue of `time_t` depends on how it is implemented on a particular system, specifically whether it is a 32-bit or 64-bit type.

    - 32-bit `time_t`: On systems where `time_t` is a 32-bit signed integer, it can represent dates and times up to approximately 03:14:07 UTC on 19 January 2038. This is known as the Year 2038 problem or the Y2K38 problem. After this time, the representation will overflow and can wrap around, potentially causing software that is not prepared for this to fail or behave unpredictably.

    - 64-bit `time_t`: Many modern systems have moved to using a 64-bit `time_t`, which significantly pushes the overflow issue far into the future, roughly 292 billion years from now. Specifically, it will overflow around the year 292,277,026,596 CE, which is not a concern for current applications.

    ### Types of `time_t`

    Primarily, `time_t` is considered as an integer or a real-floating point type depending on the implementation, but its essence is that it represents time in seconds. The standard doesn't explicitly define `time_t` as 32-bit or 64-bit; it is up to the implementation. However, the common practice is to use:

    - 32-bit `time_t` on older or embedded systems.
    - 64-bit `time_t` on modern systems for a broader range and to avoid the Year 2038 problem.

    ### Follow-up Questions

    - Are you currently working on a project that involves handling time and dates, and are you concerned about the potential overflow?
    - Is there a specific system or environment you're working with (e.g., a particular operating system or hardware platform)? Knowing this could help provide more targeted advice.

    Understanding your context a bit more would enable me to give you the most relevant information or suggestions.
    You can call me in any topic by writing @ElektrodaBot. Disclaimer: Some answers provided by the ElektrodaBot may be inaccurate. Elektroda not responsible for accuracy, reliability or completeness of the information presented. All ElektrodaBot responses should be verified by the user. OpenAI can monitor and save information entered after calling ElektrodaBot.
  • #54 21019651
    max4elektroda
    Level 24  
    Posts: 754
    Help: 48
    Rate: 187
    We also run in the same issue in "src/httpserver/json_interface.c" (issue #1076), where it's "even worse ;-)", for there we are using no unsigned, but signed int!

    Added after 21 [minutes]:

    I like it ;-)
    Screenshot of device firmware showing version LN882H_1.17.519.
    But maybe we should drop prepending "LN882H_" like in the other versions?
    I just added it, for it was there with the "LN882H_Test", too...
  • #55 21019696
    divadiow
    Level 38  
    Posts: 5039
    Help: 438
    Rate: 891
    excellent work.
  • #56 21019723
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    Sure, here it is:
    https://github.com/openshwprojects/OpenLN882H/commit/1fade8a410cfaa6d64a0b70f2df459ba1b992a91
    Let me update the submodules of the main repo and we should get a correct version string.
    Helpful post? Buy me a coffee.
  • #57 21019882
    silvestro_gatto
    Level 7  
    Posts: 30
    Rate: 4
    >>21019583

    Tested on my LN882H bench module and OpenLN882H_1146_merge_64f6c6101544 is working fine: no more errors in serial log and module is stable and reliable with NTP driver.
  • #58 21020171
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14595
    Help: 654
    Rate: 12613
    So I decided to merge the time_t fix:
    https://github.com/openshwprojects/OpenBK7231...mmit/c07f66f3818c7067e60acbf27cb1a5d86f77e692
    Can you confirm whether the issue is solved now?
    Helpful post? Buy me a coffee.
  • #59 21020355
    silvestro_gatto
    Level 7  
    Posts: 30
    Rate: 4
    I tested OpenLN882H_1.17.521 release for a few minutes now and everything seems to be fine: no more errors in serial log, module is stable and fully functional and settings are consistent with the template previously loaded.

    Once again thank you @p.kaczmarek2 and @max4elektroda for the excellent work in solving this issue.

    I can also confirm that now the correct version is showed on the footer of each web page:

    Screenshot of an interface showing software version details.

Topic summary

✨ The discussion revolves around the Elivo LSPA9 Smart Plug, which became unresponsive after an upgrade from OpenLN882H version 1.17.506 to 1.17.515. Users reported that the device initially functioned well with energy monitoring but encountered issues post-update, including slow web interface access and eventual unresponsiveness. Serial logs indicated recurring hardware errors. Various users suggested testing intermediate firmware versions to identify the problematic update, leading to the discovery that version 1.17.513 caused the issues. A workaround was proposed by disabling certain drivers, and a fix was implemented in subsequent versions, restoring functionality and stability to the device. The final resolution involved modifying the handling of time synchronization to prevent the device from freezing.
Generated by the language model.

FAQ

TL;DR: For OpenLN882H users with LN882H/WL2S plugs, the freeze after 20–30 seconds was traced to NTP, not the plug hardware. As one developer concluded, "this is the solution": a time_t/gmtime mismatch broke LN882H and BL602 builds from 1.17.513 onward until the fix landed in 1.17.521. [#21019532]

Why it matters: This thread shows how to isolate a firmware regression quickly, avoid false leads like flash size or LED support, and restore stable NTP, web UI, and saved settings on LN882H smart plugs.

Version / build Observed result on affected LN882H plugs Notes
1.17.506–1.17.512 Stable No reported serial errors
1.17.513 First failing release Device loses settings and freezes
1.17.517 Still failing Stack-size change did not solve it
PR 1141 test build Working workaround NTP no longer froze device
1.17.521 Stable fix confirmed Settings restored, no serial errors

Key insight: The visible trigger was startDriver NTP, but the root cause was a cross-platform time bug: LN882H and BL602 used 64-bit time_t, while code treated NTP time like a 32-bit integer pointer. [#21020355]

Quick Facts

  • The affected plug used an LN882HKI on a WL2S module with a BL0937 energy-monitor chip, and its startup command was backlog startDriver NTP; ntp_setServer 216.239.35.8; ntp_timeZoneOfs 1. [#21017596]
  • Regression testing narrowed the break to OpenLN882H 1.17.513, built Mar 19 2024 09:10:15; versions 1.17.507 through 1.17.512 stayed fully functional on the same hardware. [#21017325]
  • On one failing unit, free memory dropped from about 90,912 bytes to 1,200 bytes immediately after NTP logged local time, which matched the hang window. [#21018244]
  • The thread established a platform split: BK7231 used 32-bit time_t, while LN882H and BL602 used 64-bit time_t, explaining why BK7231 kept working with the same code path. [#21019583]

Why does upgrading an Elivo LSPA9 smart plug with LN882HKI from OpenLN882H 1.17.506 to 1.17.513 or later make the device unresponsive after 20 to 30 seconds?

Because 1.17.513 exposed an NTP time-handling bug on LN882H, not a template or hardware fault. The affected plug booted, then froze after about 20–30 seconds, often after starting NTP, while 1.17.506 through 1.17.512 stayed stable on the same WL2S module. The final diagnosis was a time_t size mismatch in code that passed NTP time to gmtime, which corrupted behavior on LN882H. [#21019532]

How can I narrow down which OpenLN882H release introduced instability on a WL2S-based LN882H smart plug?

Use sequential downgrade or upgrade testing until one version fails. 1. Flash known-good firmware, such as 1.17.506 or 1.17.512. 2. Test each release in order, checking web UI, saved template, and serial log. 3. Stop at the first build that shows freezes or [WLIB_E] errors. In this case, versions 1.17.507 to 1.17.512 worked, and 1.17.513 was the first failing release. [#21017325]

What do the serial log errors "[WLIB_E]HwEr:EC = 16" and "[WLIB_E]HwEr:EC = 12" mean on OpenLN882H devices?

They indicate low-level Wi-Fi or system error conditions seen during the freeze, but the thread did not assign them a final standalone meaning. On affected LN882H builds, they appeared repeatedly with rsp wait timeout messages and loss of responsiveness. After the NTP time fix was tested, those errors disappeared on the same hardware, so they were treated as symptoms of the deeper time bug rather than the root cause. [#21018252]

How does starting the NTP driver trigger freezes on some LN882H plugs running OpenLN882H 1.17.513 to 1.17.517?

Starting NTP triggers the buggy code path that converts NTP time to local time. Users reproduced the hang with startDriver NTP, and one log showed the device becoming unresponsive right after Info:NTP:Local Time, with free memory collapsing to 1,200 bytes. The plug could still sometimes ping or print temperature logs, but the normal web interface stalled or froze. [#21018244]

Which change in OpenLN882H 1.17.513 was linked to the LSPA9 smart plug freeze: LED, WEMO, HUE, or something else?

The first suspicious change was the 1.17.513 commit that enabled LED, WEMO, and HUE support, but that was not the true root cause. Tests showed that enabling LED-related code correlated with the crash, while WEMO and HUE alone did not. Later debugging proved the real issue was time handling in NTP on 64-bit time_t platforms, so the driver change only exposed the bug. [#21018282]

What is the WL2S module in LN882H smart plugs, and how is it used for UART debugging and reflashing?

"WL2S" is a Wi-Fi module board that carries the LN882H chip, exposes serial access, and lets developers remove it from the mains plug for safer bench testing, UART logging, and reflashing. In this thread, the module was desoldered from the plug, connected to a UART-to-TTL adapter, and used to capture boot logs and test multiple firmware versions. [#21016559]

What is the BL0937 energy monitor chip, and how does OpenLN882H use it in smart plugs like the Elivo LSPA9?

"BL0937" is an energy-monitoring IC that measures mains parameters for smart plugs, using dedicated CF, CF1, and SEL signal pins so firmware can calculate values like voltage, current, and power. The shared LSPA9 template mapped BL0937 functions to pins 7, 12, and 19, and the plug reported energy data correctly on stable firmware. [#21016933]

How do I test whether NTP, SSDP, WEMO, HUE, or LED drivers are causing crashes on an LN882H device?

Disable or isolate one feature at a time and test with the same startup flow. 1. Boot with an empty StartupCommand. 2. Start one driver manually, such as startDriver NTP. 3. Compare behavior across custom builds that enable only LED, only WEMO/HUE, or none. In this thread, NTP consistently triggered the freeze, LED-related code initially looked guilty, and later testing traced the failure to time conversion, not WEMO or HUE. [#21017655]

Why did a gmtime and time_t mismatch break NTP on LN882H and BL602 while BK7231 kept working?

Because LN882H and BL602 used 64-bit time_t, but the code passed a 32-bit global integer as if it were a time_t*. That meant gmtime read extra, undefined bytes from RAM on those platforms. BK7231 kept working because its time_t was still 32-bit, so the bad cast did not immediately corrupt the value. [#21019583]

What does the TimeSize command show on LN882H, BL602, and BK7231, and how can it help diagnose time_t-related bugs?

It shows the platform-dependent size of time-related types, which helps confirm whether pointer casts are unsafe. The thread used TimeSize to verify that LN882H and BL602 had 64-bit time_t, while BK7231 had 32-bit time_t. That one command explained why the same NTP code failed on LN882H and BL602 but initially behaved on BK7231. [#21019555]

OpenLN882H on 1MB vs 2MB LN882H flash: how do flash size differences affect config storage offsets and stability?

Flash size was investigated, but this thread did not prove it caused the LSPA9 freeze. One developer noted the config offset sat above the 1 MB mark, which could break saves on true 1 MB devices, while the reported chip marking LN882HKI suggested 2 MB flash. Later tests solved the freeze with a time fix, so flash size remained a separate edge case, not the confirmed cause here. [#21017584]

How can I safely capture serial logs from a mains-powered smart plug without risking contact with live wiring?

Remove the Wi-Fi module and debug it on the bench instead of probing a live plug. One participant explicitly avoided serial investigation on a powered plug because plug ground could connect to a live wire. In this thread, the safer method was to desolder the WL2S module, connect it to a UART-to-TTL adapter, and test firmware off-board. [#21017013]

What startup command should I use to enable NTP on OpenLN882H, and how can I verify it is not causing hangs?

Use backlog startDriver NTP; ntp_setServer 216.239.35.8; ntp_timeZoneOfs 1 and then watch logs for stable time sync. A healthy run prints NTP initialization, Unix time, and a normal local date like 2024/03/24 22:18:36 without freezing. If the web UI hangs or [WLIB_E] errors appear immediately after NTP starts, your build still has the bug. [#21018404]

Why would the web interface freeze while ping and some log output still continue after starting NTP on an LN882H plug?

Because the failure did not always hard-crash the whole device. In one reproduced case, after NTP started via wget, the plug still answered ping and kept printing TEMP lines, but regular Info:MAIN logging stopped and the normal web interface became unusable. That pattern pointed to severe runtime corruption or starvation in specific code paths, not a total power loss. [#21018147]

Did anyone get OpenLN882H working reliably on a 1MB LN882H device, and what flash partition or config changes are needed?

No confirmed working 1 MB LN882H setup was documented in this thread. The discussion only raised the concern that the current config-save offset sits beyond 1 MB, which could overlap or wrap on smaller flash parts. The tested LSPA9 hardware used LN882HKI, was treated as 2 MB, and was fully stable again on 1.17.521 after the time fix. [#21020355]
Generated by the language model.
ADVERTISEMENT