TillFleisch / ESPHome-HLK-LD2450

ESPHome support for the HI-Link HLK-LD2450 millimeter wave sensor (external component) with support for custom zones using convex polygons.
MIT License
105 stars 19 forks source link

Stuck in repeated "Clearing RX buffer." #23

Closed bsell93 closed 4 months ago

bsell93 commented 4 months ago

Hey @TillFleisch ,

I've got a weird one - I keep getting the following in my logs

[LD2450:276]: Clearing RX buffer. - repeated [LD2450:258]: Sensor is not sending updates, attempting to leave config mode. - occasionally [LD2450:131]: Sending command timed out! Is the sensor connected? - occasionally

The weird thing is the sensor was working perfectly and then after a while (not being touched) it starts failing and giving all ZERO values for my sensors, which aligns with the logs.

I thought perhaps I'm running out of ram so I added this to my sensors

  - platform: debug
    free:
      name: "Heap Free"

to see if I'm running out of ram and I consistently have 10s of thousands of Bytes of ram image

Is it possible there is a memory leak somewhere that is causing LD2450 get stuck in this loop?

Things I've tried,

Things I've verified:

Here is my config: https://github.com/bsell93/esphome/blob/main/bedroom-thermostat.common.yaml

Any assistance is appreciated ๐Ÿ˜„

TillFleisch commented 4 months ago

My first guess would be a power issue. Seeing that you're using 5V for the sensor, let's assume that this is not the case.

The Clearing RX buffer. message is contained in the logs, when the RX buffer of the UART port has been filled up. For some reason, on some ESPs new data will only be put into the RX buffer once it has been emptied completely. This can lead to un-processed messages. In complex ESPHome configurations, particularly ones with (compnoents) which use delays, the buffer can be filled up while other components are being processed. Based on the length of your configuration file alone, this may be the case here.

I would try the following trouble-shooting steps in your situation:

The Sensor is not sending updates log entry could be related (caused by) to the buffer issue. If this is not the case, it's probably a power issue which could be caused by other HW components. The sensor may struggle with noisy power, like when using 3.3V.

A memory leak is possible, though I would expect some kind of slope in memory usage. Does the esp crash/reboot? Does the loop time (debug component) correlate with the log messages (this would be in-line with the buffer thing)?

I have not yet tried your configuraiton. I may update this post once I do.

bsell93 commented 4 months ago

Thanks for the quick reply!

I will try a minimal config next to see if I can isolate the issue that way

I just tried setting the rx_buffer_size to 512 - that didn't seem to make a difference.

I also noticed a warning saying that the logger was using UART and suggested to set baud_rate to 0 for the logger - which I did. That didn't seem to make a difference. So I'm trying taking out the logger altogether to see if that helps.

Does the esp crash/reboot?

No - the esp32 appears to stay online

Does the loop time (debug component) correlate with the log messages (this would be in-line with the buffer thing)?

I've not tried checking that - will check that as well

bsell93 commented 4 months ago

Removing logger made no difference

Minimizing the config to just be the LD2450 has also made no difference.

Output:

[21:48:43][W][LD2450:124]: Entering config mode failed, clearing command queue.
[21:48:43][W][LD2450:131]: Sending command timed out! Is the sensor connected?
[21:48:48][D][LD2450:258]: Sensor is not sending updates, attempting to leave config mode.
[21:48:48][I][safe_mode:041]: Boot seems successful; resetting boot loop counter
[21:48:48][D][esp32.preferences:114]: Saving 1 preferences to flash...
[21:48:48][D][esp32.preferences:143]: Saving 1 preferences to flash: 0 cached, 1 written, 0 failed
[21:48:50][W][LD2450:131]: Sending command timed out! Is the sensor connected?
[21:49:48][D][LD2450:258]: Sensor is not sending updates, attempting to leave config mode.
[21:49:49][W][LD2450:131]: Sending command timed out! Is the sensor connected?
bsell93 commented 4 months ago

I'm not ruling out the fact that it could be the power source - I'm using a AC -> DC step down converter. So I'm converting 120v AC to 5v DC. Specifically this: https://bityl.co/Qn4F (variant is 5V 700mA (3.5W))

The odd thing is it was working for days and then just randomly stopped and has not been working since.

I have two identical devices that are presenting identical behavior.

Do you have any suggestions for alternatives to power for 120v -> 5v?

bsell93 commented 4 months ago

Okay - So to verify the power source theory I plugged the esp32 into usb and the sensor is now working as expected. ๐Ÿ˜ข

So I'm guessing the step-down module is the source of the issue.

bsell93 commented 4 months ago

Going to try this power module and see if it does the trick https://amz.run/9J6v

I will close this issue since this is clearly not an issue with the codebase.

Thanks @TillFleisch for being my rubber ducky ๐Ÿฆ† ๐Ÿ˜„

ps. hopefully this thread will help someone who may run into the same issue. ๐Ÿ˜„

TillFleisch commented 4 months ago

Depending on what else is connected to the power supply, adding a couple of smoothing capacitors could help resolve the issue. (if you happened to have some laying around)

bsell93 commented 4 months ago

Thank you for the suggestions!

For the record:

I ended up trying it both ways just to be sure.

I added a 100ยตF Electrolytic Capacitor and that did the trick with the cheaper aliexpress stepdown module. (link to the capacitors I used: https://amz.run/9K2o)

I also tried using the above HLK PM01 (without capacitors) step down module in place of the aliexpress module and that did the trick as well.