Skip to content
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

Clear UART read buffer before sending next command #6200

Merged
merged 3 commits into from Feb 20, 2024

Conversation

fototakas
Copy link
Contributor

Clear UART read buffer before sending next command, this fixes issue when all fingers became authorized after first AuraLed command is used on some sensors.
Discussions about this issue can be found here: esphome/issues#2542

What does this implement/fix?

Types of changes

  • [ x] 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)
  • Other

Related issue or feature (if applicable): fixes esphome/issues#2542

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

Test Environment

  • [ x] ESP32
  • [ x] ESP32 IDF
  • [ x] ESP8266
  • RP2040
  • BK72xx
  • RTL87xx

Checklist:

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

Clear UART read buffer before sending next command, this fixes issue  when all fingers became authorized after first AuraLed command is used on some sensors.
@probot-esphome
Copy link

probot-esphome bot commented Feb 7, 2024

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

@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (3eaf59c) 0.00% compared to head (c97d3ae) 53.71%.

Additional details and impacted files
@@           Coverage Diff            @@
##           dev    #6200       +/-   ##
========================================
+ Coverage     0   53.71%   +53.71%     
========================================
  Files        0       50       +50     
  Lines        0     9404     +9404     
  Branches     0     1653     +1653     
========================================
+ Hits         0     5051     +5051     
- Misses       0     4055     +4055     
- Partials     0      298      +298     

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

@jesserockz jesserockz added this to the 2024.2.0b3 milestone Feb 20, 2024
@jesserockz jesserockz merged commit 1f432ec into esphome:dev Feb 20, 2024
55 checks passed
@jesserockz jesserockz mentioned this pull request Feb 20, 2024
@jesserockz jesserockz mentioned this pull request Feb 20, 2024
@paolo1983
Copy link

paolo1983 commented Feb 21, 2024

I updated to last esphome (02.2024) and now my fingerprint sensor doesnt work.
I came back to 12.2023 and It gets work again.
If i show logs, in 12.2023 i see a loop of "Scan and match --- Getting image 1--- No finger" and If i put my finger It works. With 02.2024 the logs Is empity: It seems that the fingerprint sensor Is not waiting for finger
Any idea? I have to manage my code by adding some strings or Is It a bug?

@fototakas
Copy link
Contributor Author

@paolo1983 could you please provide more information what exactly sensor you are using, what ESP board you are using, how sensor is connected to the ESP. Are you using WAKEUP (pin5) Finger Detection Signal in your setup?
There was another change in this release #6003
It changed a bit of the logic how finger is detected.

@paolo1983
Copy link

paolo1983 commented Feb 21, 2024

@fototakas thanks for the reply. I'm using a R503 on a wemos D1 mini. I dont remember exactly how i wired the sensor to ESP but this Is my code, i'm using a sensing_pin (D2) so i suppose that i wired the wakeup (pin5) to D2. It worked for a year and now, by downgrading to 12.2023 It Is working...

esphome:
  name: impronte3

esp8266:
  board: d1_mini

wifi:
  ssid: "WcNet"
  password: "xxx"


  ap:
    ssid: "Finger Reader Fallback"
    password: "xxx"

captive_portal:

logger:
  baud_rate: 0
ota:
  password: "xxx"

uart:
  rx_pin: D6
  tx_pin: D5
  baud_rate: 57600

fingerprint_grow:
  sensing_pin: D2
  on_finger_scan_matched:
    - text_sensor.template.publish:
        id: fingerprint_state
        state: "Impronta autorizzata"
    - fingerprint_grow.aura_led_control:
        state: BREATHING
        speed: 200
        color: BLUE
        count: 1
    - delay: 3000ms
    - text_sensor.template.publish:
        id: fingerprint_state
        state: "Attesa"
  on_finger_scan_unmatched:
    - text_sensor.template.publish:
        id: fingerprint_state
        state: "Impronta non autorizzata"
    - fingerprint_grow.aura_led_control:
        state: FLASHING
        speed: 25
        color: RED
        count: 4
    - delay: 500ms
    - text_sensor.template.publish:
        id: fingerprint_state
        state: "Attesa"
  on_enrollment_scan:
    - text_sensor.template.publish:
        id: fingerprint_state
        state: "Impronta acquisita"
    - fingerprint_grow.aura_led_control:
        state: FLASHING
        speed: 25
        color: BLUE
        count: 2
    - fingerprint_grow.aura_led_control:
        state: ALWAYS_ON
        speed: 0
        color: PURPLE
        count: 0
  on_enrollment_done:
    - fingerprint_grow.aura_led_control:
        state: FLASHING
        speed: 25
        color: PURPLE
        count: 4
  on_enrollment_failed:
    - text_sensor.template.publish:
        id: fingerprint_state
        state: "Acquisizione impronta fallita"
    - fingerprint_grow.aura_led_control:
        state: FLASHING
        speed: 25
        color: RED
        count: 4

api:
  encryption:
    key: "xxx"
  services:
  - service: enroll
    variables:
      finger_id: int
      num_scans: int
    then:
      - fingerprint_grow.enroll:
          finger_id: !lambda 'return finger_id;'
          num_scans: !lambda 'return num_scans;'
  - service: cancel_enroll
    then:
      - fingerprint_grow.cancel_enroll:
  - service: delete
    variables:
      finger_id: int
    then:
      - fingerprint_grow.delete:
          finger_id: !lambda 'return finger_id;'
  - service: delete_all
    then:
      - fingerprint_grow.delete_all:

text_sensor:
  - platform: template
    id: fingerprint_state
    name: "Stato impronta"

binary_sensor:
  - platform: fingerprint_grow
    id: fingerprint_enrolling
    name: "Acquisendo impronta"

sensor:
  - platform: fingerprint_grow
    fingerprint_count:
      name: "Conta impronte"
    last_finger_id:
      name: "Ultimo ID impronta"
    last_confidence:
      name: "Affidabilità ultima impronta"
    status:
      name: "Stato impronta"
    capacity:
      name: "Capacità impronta"
    security_level:
      name: "Livello di sicurezza"
  - platform: wifi_signal
    name: Lettore impronte Wi-Fi Signal
    update_interval: 120s

switch:
  - platform: restart

@fototakas
Copy link
Contributor Author

@paolo1983 I see that D2 is defined as touch sensing pin in your configuration. Please check that D2 pin from wemos is securely connected to R503 pin 5.
Also for testing purposes, you can try to remove " sensing_pin: D2" line from config, recompile and test what log output you will get then.
I will be able to test something only in the evening.

@paolo1983
Copy link

@paolo1983 I see that D2 is defined as touch sensing pin in your configuration. Please check that D2 pin from wemos is securely connected to R503 pin 5. Also for testing purposes, you can try to remove " sensing_pin: D2" line from config, recompile and test what log output you will get then. I will be able to test something only in the evening.

@fototakas thanks for the reply. I confirm that r503 pin5 Is connected to d2 PIN on wemos

@fototakas
Copy link
Contributor Author

fototakas commented Feb 21, 2024

@paolo1983 I have a R503S sensor and are ussing it with ESP32-C3, but as before making this PR I tested it and with 8266 (nodemcu) Surpraisingly to me, my sensor works correctly with ESPhome 2024.2.0 - with UART buffer clearing enabled, and it works without this fix, but after first auraled light-up all fingers are authorised :(

Now to ruleout if my fix broken your sensors setup, could you please add this to your ESPhome configuration, recompile and upload it to the wemos board. This is the link to my github fork, I disabled this fix.

external_components:
  - source: github://fototakas/esphome@dev
    refresh: 0s
    components: [ fingerprint_grow ]

@paolo1983
Copy link

@fototakas It works!
In the logs i see no more the loop of "Scan and match --- Getting image 1--- No finger" but if i put my finger the Door opens!!!!

@paolo1983
Copy link

@fototakas
My wiring are: PIN 1 and PIN 6 to 3,3V. PIN 2 to gnd, PIN 3 (TX) to D6 on wemos (settings as RX). PIN 4 (RX) to D5 on wemos (settings as TX). PIN 5 to D2 setting as sensing PIN.
I confirm that whit your external_components It works again like a charm. Without It doesnt work
If you Need other testing i'm here!

@fototakas
Copy link
Contributor Author

@paolo1983 OK, thanks for testing, It looks we found the culprit :), fix for somebody - troubles for others. Again sorry for issues. Actually I'm a bit confused now, it would be nice to know if my fix also couse issues and on ESP32 or it is only for ESP8266 with software UART.

@jesserockz I think we need to rollback this commit. For those who might get such a buggy sensor, I will leave custom component on my github.

@paolo1983
Copy link

@fototakas thanks! So i have to keep your external_components?

@fototakas
Copy link
Contributor Author

@paolo1983 If you want to stay on 2024.2.0, you should keep external component. Or you can revert to 2023.12.

@jesserockz #6271 created, please add it to next bug fix release (2024.2.1)

And gain sorry for troubles!

@paolo1983
Copy link

@fototakas ok, at the moment i keep the external component.
I have to report that Is important wired the PIN 6 of fingerprint sensor (touch induction Power supply?) to 3.3V. without, with 02.2024 It doesnt work. I tested It Yesterday. So at the moment It works like a charm with your external component and PIN 6 Wired to PIN 1 (3.3V)

@fototakas
Copy link
Contributor Author

@paolo1983 Ok, good finding. Did you found this after modified yaml with my custom component or before?
If you find out this after the yaml edit, maybe you could test again with removed custom component, just to be sure that my addition to the code is the real problem.

@paolo1983
Copy link

@fototakas i already tried without your external component and with pin6 Wired but It did not work .
With your external component and with pin6 Wired to 3.3 It works like a charm

@alexborro
Copy link
Contributor

alexborro commented Feb 22, 2024

Hi @paolo1983 , next time you have an issue, open an issue report, do not comment in a PR otherwise it is hard for us to track and fix.
We already have an issue open for it: esphome/issues#5502
Cheers.
Alex.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with Grow Fingerprint and Wemos D1 Mini when using aurora_led_control
5 participants