8000 [esp32_can] Configurable enqueue timeout by patagonaa · Pull Request #8453 · esphome/esphome · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[esp32_can] Configurable enqueue timeout #8453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 26, 2025

Conversation

patagonaa
Copy link
Contributor
@patagonaa patagonaa commented Mar 23, 2025

What does this implement/fix?

This reduces the CAN TX queueing timeout from 1000ms to 10ms to avoid blocking very long when trying to send messages to an unresponsive device / disconnected bus (causing a "Component xxx took a long time for an operation (1000ms)" message and possibly triggering the loop watchdog).

This also adds a warning message when a CAN message couldn't be queued.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Code quality improvements to existing code or addition of tests
  • Other

Related issue or feature (if applicable):

Pull request in esphome-docs with documentation (if applicable):

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Example entry for config.yaml:

# Example config.yaml
canbus:
  - platform: esp32_can
    id: can
    tx_pin: GPIO27
    rx_pin: GPIO26
    use_extended_id: true
    can_id: 0x100
    bit_rate: 125kbps

interval:
  - interval: 2s
    then: 
      - canbus.send:
          data: [ 0x11, 0x22, 0x33 ]

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

@probot-esphome
Copy link

Hey there @danielschramm, @mvturnho, mind taking a look at this pull request as it has been labeled with an integration (canbus) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@probot-esphome
Copy link

Hey there @Sympatron, mind taking a look at this pull request as it has been labeled with an integration (esp32_can) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@codecov-commenter
8000
Copy link
codecov-commenter commented Mar 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 54.92%. Comparing base (4d8b5ed) to head (6881613).
Report is 2243 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #8453      +/-   ##
==========================================
+ Coverage   53.70%   54.92%   +1.21%     
==========================================
  Files          50       50              
  Lines        9408     9910     +502     
  Branches     1654     1353     -301     
==========================================
+ Hits         5053     5443     +390     
- Misses       4056     4124      +68     
- Partials      299      343      +44     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor
@danielschramm danielschramm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I vote for merging.

Copy link
Member
@DjordjeMandic DjordjeMandic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@probot-esphome probot-esphome bot removed the small-pr label Mar 25, 2025
@patagonaa
Copy link
Contributor Author

As discussed, I added a config option for the enqueue timeout.
By default, the timeout is set to the length of 10 messages (based on the configured baud rate), which should be enough to free a spot in the queue, even on a pretty congested bus with a bunch of collisions.

Naming-wise, I went with tx_enqueue_timeout because it's a little clearer because from the user perspective, it does make a difference imo:
For tx_queue_timeout, as a user I would expect the queued messages to disappear from the queue if the timeout elapses (which they don't) and wonder why old messages are sent once the bus is reattached.
Also, I would wonder why it takes tx_queue_length * tx_queue_timeout messages until one times out.

@esphome
Copy link
esphome bot commented Mar 25, 2025

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@esphome esphome bot marked this pull request as draft March 25, 2025 21:04
@patagonaa patagonaa marked this pull request as ready for review March 25, 2025 21:32
@esphome esphome bot requested a review from clydebarrow March 25, 2025 21:32
@probot-esphome
Copy link

Hey there @Sympatron, mind taking a look at this pull request as it has been labeled with an integration (esp32_can) you are listed as a code owner for? Thanks!
Hey there @danielschramm, @mvturnho, mind taking a look at this pull request as it has been labeled with an integration (canbus) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@clydebarrow
Copy link
Contributor

Ok, just need a docs update now.

@clydebarrow clydebarrow added this to the 2025.4.0b1 milestone Mar 25, 2025
@patagonaa
Copy link
Contributor Author

Ok, just need a docs update now.

already on it 😄

@clydebarrow clydebarrow changed the title Make CAN bus transmit fail instead of blocking for a long time [esp32_can] Configurable enqueue timeout Mar 25, 2025
8000 patagonaa added a commit to patagonaa/esphome-docs that referenced this pull request Mar 25, 2025
@patagonaa
Copy link
Contributor Author

(done, btw)

@clydebarrow clydebarrow enabled auto-merge (squash) March 26, 2025 03:38
@clydebarrow clydebarrow merged commit 4bb59ce into esphome:dev Mar 26, 2025
26 checks passed
@jesserockz jesserockz mentioned this pull request Apr 9, 2025
shibida pushed a commit to shibida/esphome that referenced this pull request Apr 15, 2025
herruzo99 pushed a commit to herruzo99/esphome that referenced this pull request Apr 16, 2025
@jesserockz jesserockz mentioned this pull request Apr 16, 2025
patagonaa added a commit to patagonaa/esphome-huawei-r4850 that referenced this pull request May 3, 2025
sa-crespo pushed a commit to sa-crespo/esphome that referenced this pull request May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CAN Bus triggers watchdog reboot when nothing responds - no ACK
5 participants
0