LD2410 connected to Esp32-C3 serial connection lost

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

LD2410 connected to Esp32-C3 serial connection lost

#1 Post by Patou » 08 Jul 2024, 22:55

Hello,
I have come across a strange behaviour:
I am using Esp32-C3 with a presence detector LD2410C-P.
Firmware on the unit is : ESP_Easy_mega_20240702_collection_G_ESP32c3_4M316k_CDC
3 devices have been defined :
- 1: LD 2410 with Presence, St_Presence, Mv_Presence, St_Energy
- 2: LD 2410 with Distance, St_Distance, Mv_Distance, Mv_Energy
- 3: Switch input with the presence output of the LD2410.
Com used : Hwserial1 with Rx gpio 20, tx gpio 21
Sensitivity setting : default
It looks like after some good working time ( 1...5 hours) the serial communication is broken.
the output of the ld 2410 still changes from 0 to 1 when presence is detected even when com is broken.
A software reboot or power disconnect does not restore the communication. Only an edit of the device even without changing data solves the problem.
The com is back and data are again available.
Is there a way to detect a broken serial com and a way to reset it ?
Could you look at the problem ?
Thanks in advance for your help
Patou

User avatar
Ath
Normal user
Posts: 3702
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LD2410 connected to Esp32-C3 serial connection lost

#2 Post by Ath » 08 Jul 2024, 23:13

Patou wrote: 08 Jul 2024, 22:55 3 devices have been defined :
- 1: LD 2410 with Presence, St_Presence, Mv_Presence, St_Energy
- 2: LD 2410 with Distance, St_Distance, Mv_Distance, Mv_Energy
- 3: Switch input with the presence output of the LD2410.
Com used : Hwserial1 with Rx gpio 20, tx gpio 21
Why do you have 2 tasks defined for a single hardware device? Both tasks are competing to get the high speed data from the device, probably causing the COM port to lock up in some way.

All sensor settings are available from a single task instance for the LD2410, simply by using the [<TaskName>#<ValueName>] format in rules or formulas, please see the Get Config Values chapter of the documentation.
/Ton (PayPal.me)

Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

Re: LD2410 connected to Esp32-C3 serial connection lost

#3 Post by Patou » 08 Jul 2024, 23:21

Hello Ath,
Thanks for your quick reaction Idid not see the possibility to get the data without a defined device.
I will kill device 2 and try again.
Patou

User avatar
Ath
Normal user
Posts: 3702
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LD2410 connected to Esp32-C3 serial connection lost

#4 Post by Ath » 08 Jul 2024, 23:33

Patou wrote: 08 Jul 2024, 23:21 ... Idid not see the possibility to get the data without a defined device.
Where do you want to send the data to, only as values on the Devices page, or also to a Controller?
/Ton (PayPal.me)

Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

Re: LD2410 connected to Esp32-C3 serial connection lost

#5 Post by Patou » 09 Jul 2024, 15:03

Hello Ath,
I have changed the devices to this :
4 devices :
- 1: LD 2410 with Presence, St_Presence, Mv_Presence
- 2:Generic dummy device with Distance, St_Distance, Mv_Distance, Mv_Energy (see rules)
- 3: Switch input with the presence output of the LD2410.
- 4: Generic dummy device counting the mqtt disconnections.
The data are transfered to home assistant by MQTT. (see rules)
I have still the problem but now better defined.
The serial com only works when Device 1 has been edited. After power off or reboot the serial com does not start.
The presence output is working.

Code: Select all

on system#boot do
 TimerSet,10,10
 TaskValueSet,Rb,Count,[Rb#Count]+1
endon

on MQTT#Connected do
 event,publish_data
endon

On ha_start do
 event,publish_data
endon

On publish_data do
 Publish,%sysname%/Pir_P,'{"presence":[Pir_P#Presence],"st_presence":[Pir_P#StatPres],"mv_presence":[Pir_P#MovPres]}'
 Publish,%sysname%/Pir_D,'{"distance":[Pir_P#Distance],"st_distance":[Pir_P#StatDist],"mv_distance":[Pir_P#MovDist]}'
 Publish,%sysname%/Pir_E,'{"st_energy":[Pir_P#st_Energy],"mv_energy":[Pir_P#MovEnergy]}' 
endon

On Pir_P#all do
event,publish_data
TaskValueSet,Pir_D,Dist,[Pir_P#Distance]
TaskValueSet,Pir_D,St_Dist,[Pir_P#StatDist]
TaskValueSet,Pir_D,Mv_Dist,[Pir_P#MovDist]
TaskValueSet,Pir_D,Mv_Energy,[Pir_P#MovEnergy]
endon 

On MQTT#Disconnected do
TimerSet,11,60
endon
On Rules#Timer=11 do
 if %ismqtt% =0
   Reboot
 endif
endon

On Rules#Timer=10 do
  Publish,%sysname%/data,'{"uptime":%uptime%,"model":"%cpu_model%","ip4":%ip4%,"sysload":%sysload%,"sysrssi":%rssi%,"sysssid":"%ssid%","mqtt_conec":%ismqtt%,"mqtt_imp":%ismqttimp%,"firmware":"%sysbuild_filename%","reboot_count":%v1%}'
 TimerSet,10,60
endon
Hope you can find the reason.
I suppose it is not possible to start serial com with an order generated in rules ??
Patou

TD-er
Core team member
Posts: 8981
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: LD2410 connected to Esp32-C3 serial connection lost

#6 Post by TD-er » 09 Jul 2024, 17:15

Maybe you can either switch the event call with the taskvalueset, like this:

Code: Select all

On Pir_P#all do
  TaskValueSet,Pir_D,Dist,%eventvalue1%
  TaskValueSet,Pir_D,St_Dist,%eventvalue2%
  TaskValueSet,Pir_D,Mv_Dist,%eventvalue3%
  TaskValueSet,Pir_D,Mv_Energy,%eventvalue4%
  event,publish_data
endon 
This because calling the event will take some time and in the mean time the taskvalues may have changed.
Just make sure the eventvalues are in the correct order.

Another option can be to not call "event" but "asyncevent"
This will add the event to the event queue and deal with it later.
This way you do not block execution of other code on the ESP for such a long time and also duplicate events which have not yet been processed will be ignored.

Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

Re: LD2410 connected to Esp32-C3 serial connection lost

#7 Post by Patou » 09 Jul 2024, 23:01

Hello
I follow your suggestion and changed the Event in AsyncEvent.
By saving the rules I also lost the serial com. Again editing the task 1 make serial com again available.
My impression is that I am doing nothing wrong but the plug-in must have a bug that cuts the communication when the process is reinitiated.
My competences are too limited to look in the code what is wrong. But I can take time to test any suggestion.
Patou

User avatar
Ath
Normal user
Posts: 3702
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LD2410 connected to Esp32-C3 serial connection lost

#8 Post by Ath » 09 Jul 2024, 23:34

Can you show the serial settings for your LD2410?
/Ton (PayPal.me)

Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

Re: LD2410 connected to Esp32-C3 serial connection lost

#9 Post by Patou » 10 Jul 2024, 10:44

Hello Ath,
Thanks for your reaction.
Here are the settings of task1 :

Code: Select all

Name: Pir_P
Remote unit : 0
Serial port : HW Serial1
Esp Rx GPIO - Tx : Gpio 21
Esp Tx GPIO - Rx : Gpio 20
Engineering mode : No
Sensitivity setting : -> default
Output configuration : Triple
Value1 : presence
Value2: Stat presence
Value3: Mov Presence
Single event with all values : yes
Interval: 0 sec
Hope you can find the problem
Have a nice day
Patou

User avatar
Ath
Normal user
Posts: 3702
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LD2410 connected to Esp32-C3 serial connection lost

#10 Post by Ath » 11 Jul 2024, 21:55

Have you disabled the Serial Log on the Tools/Advanced page? As that is also using the GPIO21/22 pins for serial log output if that option is enabled.
Instead of disabling the serial log, an alternative solution would be to use different GPIO pins for the LD2410. (ESP32 chips allow any available GPIO to be configured for serial communication, but not 2 active serial ports on the same GPIO pins :o )
/Ton (PayPal.me)

Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

Re: LD2410 connected to Esp32-C3 serial connection lost

#11 Post by Patou » 12 Jul 2024, 09:32

Ah this could be the problem !!! I test it and come back with news

Patou
Normal user
Posts: 117
Joined: 21 May 2018, 10:33

Re: LD2410 connected to Esp32-C3 serial connection lost

#12 Post by Patou » 12 Jul 2024, 15:33

Hello Ton,
This is the solution : disabled serial log. . In the future I will use Gpio 6 and 7 for the serial port for LD2410.
Reading the data of Esp32-C3 mini I did not understand that the usb serial port is attributed to Gpio20/21. Now I know.
That for your help.
If somebody is interesting in the project. Please find below the drawing and a 3D vision of the pcb. This fits in a Pir enclosure sold on Ali for about 4 €
Have a good wk
Patou
drawing_pir_p_rev1.2.png
drawing_pir_p_rev1.2.png (38.17 KiB) Viewed 600 times
PCB_Esp32C3-Ld2410-rev 1.2-3D.png
PCB_Esp32C3-Ld2410-rev 1.2-3D.png (120.29 KiB) Viewed 600 times
Attachments
Pir_Alarm_sensor.png
Pir_Alarm_sensor.png (98.21 KiB) Viewed 600 times

User avatar
Ath
Normal user
Posts: 3702
Joined: 10 Jun 2018, 12:06
Location: NL

Re: LD2410 connected to Esp32-C3 serial connection lost

#13 Post by Ath » 12 Jul 2024, 15:46

Great that we could solve it!

Thanks for sharing your project ;)
/Ton (PayPal.me)

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 10 guests