logo elektroda
logo elektroda
X
logo elektroda

[BK7231N] Tuya Generic TY63A DIN Rail Energy Meter: Can't switch it on!

dirk754 1095 9
Best answers LABEL_AI_GENERATED

Why does my BK7231N Tuya DIN rail energy meter run out of heap and lose Wi‑Fi when I switch the relay on with the TuyaMCU driver started, and what else do I need to configure?

The problem is not normal Wi‑Fi configuration; `idle 0/s` means an RTOS task is hogging the CPU, so the system can’t recover memory properly, and this looks like a TuyaMCU-side loop rather than a plain heap issue [#21944969] A working workaround was to disable prepaid on DP11 with `tuyaMcu_sendState 11 bool 0`, after which the relay could be turned on normally again [#21944974] [#21945042] For testing, you can also force the relay off with `tuyaMcu_sendState 16 bool 0` and then retest DP16 on its own [#21944974] The issue may be related to the current TuyaMCU driver behavior, so trying the `OpenBK7231N_ALT` build was also suggested [#21944969] [#21944958]
AI summary based on the discussion. May contain errors.
ADVERTISEMENT
  • TuyaMCU message flood exhausts heap on relay on

    #1 21944736
    dirk754
    Level 2  
    Posts: 4
    Hi,
    I bought this device: https://github.com/tuya-cloudcutter/tuya-cloudcutter/issues/469. ModelId is "000004pxun", and "ETU9-OUPA-WIFI-II-1-BL-NR_V1.0" is printed on the PCB.

    Flashing was really easy, and there are lots of similar devices here where I could "steal" an autoexec.bat from. But if I switch the relay on, my Wi-Fi dies. :-)
    The reason for this is "Error:MAIN:Low heap warning!". The standard log entry is 70k ("free 68312"), but when I press the on-button at the device, the MCU generates lots of messages (> 50 per second "Info:TuyaMCU:Received"), and after roughly 10-15 seconds the memory is exhausted and the device does not respond any more.
    I trimmed down my autexec.bat to one line only, and it still happens: "startDriver TuyaMCU".

    So, what am I doing wrong? Do I need to configure something else besides Wi-Fi, MQTT and autoexec.bat? I am using version 1.18.298.

    Bye Dirk.
  • ADVERTISEMENT
  • Relay and PowerSave testing suggested

    #2 21944863
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14803
    Help: 659
    Rate: 12965
    This requires futher testing. Relay should not affect the heap. So you're saying it happens when TuyaMCU is ran, but doesn't happen without it?

    What would happen if you were to run PowerSave 1 as well?

    That's a very strange problem indeed. In the past I saw it once, related to RF partition and I solved by nuking RF, but that's not recommended.... yet. Unless it's necessary.

    @divadiow @insmod ideas?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • Relay switching triggers MCU message flood and heap exhaustion

    #3 21944902
    dirk754
    Level 2  
    Posts: 4
    >>21944863
    If I comment out "startDriver" I can switch the relay without problems. But then there are no messages from MCU... So I loaded it again.

    When I switch the relay on, the MCU sends out many more messages. If it's switched off, there are gaps of 5 s between messages. "PowerSave 1" changes nothing. Here is a "grep MAIN" against my logfile. Strange, no idea why there is no entry "Time 113"... And I didn't realize until now that there are these "idle 0/s" entries. I assume the CPU is maxed out.

    Info:MAIN:Time 112, idle 63838/s, free 68936, MQTT 0(7), bWifi 1, secondsWithNoPing 39, socks 3/38 POWERSAVE
    Info:MAIN:Time 114, idle 110/s, free 68712, MQTT 0(7), bWifi 1, secondsWithNoPing 40, socks 4/38 POWERSAVE
    Info:MAIN:Time 115, idle 902/s, free 60088, MQTT 0(7), bWifi 1, secondsWithNoPing 41, socks 4/38 POWERSAVE
    Info:MAIN:Time 116, idle 0/s, free 60088, MQTT 0(7), bWifi 1, secondsWithNoPing 42, socks 4/38 POWERSAVE
    Info:MAIN:Time 117, idle 0/s, free 57000, MQTT 0(7), bWifi 1, secondsWithNoPing 43, socks 5/38 POWERSAVE
    Info:MAIN:Time 118, idle 0/s, free 48392, MQTT 0(7), bWifi 1, secondsWithNoPing 44, socks 5/38 POWERSAVE
    Info:MAIN:Time 119, idle 0/s, free 45000, MQTT 0(7), bWifi 1, secondsWithNoPing 45, socks 6/38 POWERSAVE
    Info:MAIN:Time 120, idle 0/s, free 36696, MQTT 0(7), bWifi 1, secondsWithNoPing 46, socks 6/38 POWERSAVE
    Info:MAIN:Time 121, idle 0/s, free 36696, MQTT 0(7), bWifi 1, secondsWithNoPing 47, socks 6/38 POWERSAVE
    Info:MAIN:Time 122, idle 0/s, free 36696, MQTT 0(7), bWifi 1, secondsWithNoPing 48, socks 7/38 POWERSAVE
    Info:MAIN:Time 123, idle 0/s, free 33304, MQTT 0(7), bWifi 1, secondsWithNoPing 49, socks 7/38 POWERSAVE
    Error:MAIN:Low heap warning!
    Info:MAIN:Time 124, idle 0/s, free 24696, MQTT 0(7), bWifi 1, secondsWithNoPing 50, socks 8/38 POWERSAVE
    Error:MAIN:Low heap warning!
    Info:MAIN:Time 125, idle 0/s, free 16392, MQTT 0(7), bWifi 1, secondsWithNoPing 51, socks 8/38 POWERSAVE
    Error:MAIN:Low heap warning!
    Info:MAIN:Time 126, idle 0/s, free 16392, MQTT 0(7), bWifi 1, secondsWithNoPing 52, socks 8/38 POWERSAVE
    Error:MAIN:Low heap warning!
    Info:MAIN:Time 127, idle 0/s, free 16392, MQTT 0(7), bWifi 1, secondsWithNoPing 53, socks 8/38 POWERSAVE
    Error:MAIN:Low heap warning!
    Info:MAIN:Time 128, idle 0/s, free 13304, MQTT 0(7), bWifi 1, secondsWithNoPing 54, socks 8/38 POWERSAVE

    And then it stops.... When I switch the relay off, the system reboots and I have access again.
  • #4 21944905
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14803
    Help: 659
    Rate: 12965
    Can you pick some older version, from like 3 months ago, or 6 months ago?
    Helpful post? Buy me a coffee.
  • Possible TuyaMCU v3 driver issue on BK7231N

    #5 21944958
    divadiow
    Level 38  
    Posts: 5238
    Help: 450
    Rate: 920
    maybe this relates to the TuyaMCU v3 issues the current TuyaMCU driver has, but I thought this was only being seen on BK7238 devices.

    At various points in this thread I offer different builds with tweaked TuyaMCU drivers https://www.elektroda.com/rtvforum/topic4163735-60.html

    but it's still not quite right. my next step was to setup CH342 to listen in on the TuyaMCU comms on a TH03 device I haven't even unboxed yet.

    https://github.com/divadiow/OpenBK7231T_App/tree/tuyamcu2

    in summary this might be a known issue with the current TuyaMCU driver. It'd be interesting to know if any of those builds alter the behaviour of your device.

    Or it's something else entirely :)
  • #6 21944965
    dirk754
    Level 2  
    Posts: 4
    Sorry, older version did not help. I tried 18.250, 18.150, 17.822 and 17.500: always the same behaviour. Am I correct: the real problem is not the heap, it is this "idle 0/s"? Too many messages coming from the MCU?

    I have attached a complete log excerpt for one second (with version 1.17.500).
    Attachments:
    • between.txt (12.2 KB) You must be logged in to download this attachment.
  • ADVERTISEMENT
  • #7 21944969
    insmod
    Level 31  
    Posts: 1432
    Help: 168
    Rate: 455
    Idle 0/s is the problem.
    In RTOS, that means that idle task doesn't get any CPU time, and it's the idle task that frees unused memory. Usually because some task hits an infinite loop.

    Try OpenBK7231N_ALT build, it might alleviate the problem somewhat.
  • #8 21944974
    divadiow
    Level 38  
    Posts: 5238
    Help: 450
    Rate: 920
    with these commands to turn off relay and disable prepaid

    tuyaMcu_sendState 16 bool 0

    tuyaMcu_sendState 11 bool 0


    then this to turn on relay

    tuyaMcu_sendState 16 bool 1


    does DP9 stop alternating between 0x18000 and 0 and does heap stabilise?
  • #9 21945032
    p.kaczmarek2
    Moderator Smart Home
    Posts: 14803
    Help: 659
    Rate: 12965
    insmod wrote:

    In RTOS, that means that idle task doesn't get any CPU time, and it's the idle task that frees unused memory. Usually because some task hits an infinite loop..

    But there should be no infinite loops in TuyaMCU? Unless.... we have an UART problem and receive loop has no "max loops" limit and it rolls and rolls infinitely?
    Helpful post? Buy me a coffee.
  • ADVERTISEMENT
  • Disabling DPID 11 fixes switch-on issue

    #10 21945042
    dirk754
    Level 2  
    Posts: 4
    >>21944974
    "tuyaMcu_sendState 11 bool 0" did the trick!!! I have to investigate a little further (enabling all the other stuff), but at least the obvious problem is gone. I will also try this OpenBK7231N_ALT later this day.

    Added after 4 [hours] 49 [minutes]:

    It really works now as expected. I used the autoexec.bat form here: https://www.elektroda.com/rtvforum/topic4022907.html

    Of course this time I disabled everything with Dpid 11, so I don't enable this again by accident.

    "does DP9 stop alternating between 0x18000 and 0 and does heap stabilise": yes, DP9 stays at 0.
    "OpenBK7231N_ALT": sorry, could not find an image, so I didn't try.

    Btw, with Dpid 11 off the value "idle" did increase from ca. 70k to 170k most of the time.

    Bye Dirk

    Ps: You guys are great!!! Thank you very much!

Topic summary

LABEL_AI_GENERATED
A BK7231N-based Tuya Generic TY63A DIN rail energy meter was flashed successfully with Tuya Cloudcutter, but enabling the relay causes the Wi‑Fi connection to drop and the firmware to report repeated “Low heap warning” errors. The issue appears only when the TuyaMCU driver is started; without `startDriver TuyaMCU`, the relay can be switched normally but MCU telemetry is lost. The device floods the log with frequent `Info:TuyaMCU:Received` messages when the relay is on, leading to heap exhaustion after about 10–15 seconds. PowerSave settings did not help, and a suggestion was made to test older firmware versions or investigate a possible RF/partition-related problem.
AI summary based on the discussion. May contain errors.
ADVERTISEMENT