-
-
Notifications
You must be signed in to change notification settings - Fork 187
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
[WORKAROUND FOUND] ESPHome 2024.5.0 Breaks Tag Reader #261
Comments
More details, and still broken as of ESPHome 2024.5.3. Here's what I get from the local USB connected logs when I scan a tag. [09:04:56] [09:04:56]Unhandled C++ exception: OOM |
Even more info, stack trace from the HA server with local ESP8266 tag reader connected via USB. [09:32:47]--------------- CUT HERE FOR EXCEPTION DECODER --------------- |
Not sure if this codebase is being maintained, but I got it to work by stripping out blocks of code that were not needed.
|
Update yaml file according to adonno#261 (comment)
@gdst4rp does your workaround still work? Is it stable? I am tempted to just install an esphome version from last year as this repository does not seem to be maintained. |
Still working for me so far. Thankfully it's a relatively easy fix, just save your original yaml file in case you want to restore. I plugged the device directly into the Pi running HA to perform the re-install of the trimmed yaml. |
@gdst4rp do you mind sharing your full YAML file here? |
Here you go. Change up the substitutions section to update the device name to what you want. I also use the separate !secrets files for SSID and SSID Password values. |
captive portal is still required for first time users, so i cannot comment it out |
From what I can tell, it's a memory overflow on the 8266 chips. Are the crash logs above helpful at all? I don't know how to parse them so I just tried to trim some functionality, which seemed to work. If it's helpful, I wonder if this is related to one of the other issues I ran into where tags over a certain byte length would cause the unit to reboot as well. This was something that popped up somewhat recently, but just got worse. Perhaps as the ESPHome codebase grows, it takes more of the available memory on the limited 8266? Here's the earlier issue I ran into with this tag reader. esphome/issues#5208 |
I wonder if i should write a light version for people facing issues.. MAybe one without the jukebox component etc. Maybe people will be willing to have less functionality for a working device. |
For me personally, all I use it for is to scan HA tags. I have a whole flow in NodeRed that parses the tags, calls the right speakers to play from and plays from the right Spotify source. I don't use the tagreader to actually write new tags, or call directly to Apple, YouTube, or Spotify, which is why I attempted to cut out all the extra code, but I'm sure I missed some things. I've already had to shorten the tag payload per that other issue since it was crashing if the payload was too big. |
@adonno Yes, please! I just want to be able to scan tags. Absolutely nothing else. I haven't been able to use the device with the current config. |
Same for me. Same behavior, can't get the tag reader working. Just need it to scan tags. |
I might be a bit off since I am using a esp32 wemos D1Mini, but after I added power_save_mode: none to the wifi of my esphome yaml, all was relatively good. I am still getting some warnings and an error but the sensor works. Im trying to get rid of the below errors and warnings [E][pn532.mifare_classic:101]: Authentication failed - Block 0x04 |
I spent some time messing around with the config today and for some reason the lambda makes the device crash 100% of the time on tag scanned. I simplified it a LOT and now it works 100% of the time. Here's my config tagreader.yaml# Insert your SSID and Your PWD after inital setup
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: ${name}
# Enable the captive portal for inital WiFi setup
captive_portal:
substitutions:
name: tagreader
friendly_name: TagReader
improv_serial:
esphome:
name: $name
platform: ESP8266
board: d1_mini
# Automatically add the mac address to the name
# so you can use a single firmware for all devices
name_add_mac_suffix: false
# This will allow for (future) project identification,
# configuration and updates.
project:
name: adonno.tag_reader
version: "1.4"
# If buzzer is enabled, notify on api connection success
on_boot:
priority: -10
then:
- wait_until:
api.connected:
- logger.log: API is connected!
- rtttl.play: "success:d=24,o=5,b=100:c,g,b"
- light.turn_on:
id: activity_led
brightness: 100%
red: 0%
green: 0%
blue: 100%
flash_length: 500ms
- switch.turn_on: buzzer_enabled
- switch.turn_on: led_enabled
# Define buttons for writing tags via HA
button:
- platform: template
name: Write Tag Random
id: write_tag_random
# Optional variables:
icon: "mdi:pencil-box"
on_press:
then:
- light.turn_on:
id: activity_led
brightness: 100%
red: 100%
green: 0%
blue: 100%
- lambda: |-
static const char alphanum[] = "0123456789abcdef";
std::string uri = "https://www.home-assistant.io/tag/";
for (int i = 0; i < 8; i++)
uri += alphanum[random_uint32() % (sizeof(alphanum) - 1)];
uri += "-";
for (int j = 0; j < 3; j++) {
for (int i = 0; i < 4; i++)
uri += alphanum[random_uint32() % (sizeof(alphanum) - 1)];
uri += "-";
}
for (int i = 0; i < 12; i++)
uri += alphanum[random_uint32() % (sizeof(alphanum) - 1)];
auto message = new nfc::NdefMessage();
message->add_uri_record(uri);
ESP_LOGD("tagreader", "Writing payload: %s", uri.c_str());
id(pn532_board).write_mode(message);
- rtttl.play: "write:d=24,o=5,b=100:b"
- wait_until:
not:
pn532.is_writing:
- light.turn_off:
id: activity_led
- rtttl.play: "write:d=24,o=5,b=100:b,b"
- platform: template
name: Clean Tag
id: clean_tag
icon: "mdi:nfc-variant-off"
on_press:
then:
- light.turn_on:
id: activity_led
brightness: 100%
red: 100%
green: 64.7%
blue: 0%
- lambda: 'id(pn532_board).clean_mode();'
- rtttl.play: "write:d=24,o=5,b=100:b"
- wait_until:
not:
pn532.is_writing:
- light.turn_off:
id: activity_led
- rtttl.play: "write:d=24,o=5,b=100:b,b"
- platform: template
name: Cancel writing
id: cancel_writing
icon: "mdi:pencil-off"
on_press:
then:
- lambda: 'id(pn532_board).read_mode();'
- light.turn_off:
id: activity_led
- rtttl.play: "write:d=24,o=5,b=100:b,b"
- platform: restart
name: "${friendly_name} Restart"
entity_category: config
# Define switches to control LED and buzzer from HA
switch:
- platform: template
name: "${friendly_name} Buzzer Enabled"
id: buzzer_enabled
icon: mdi:volume-high
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
entity_category: config
- platform: template
name: "${friendly_name} LED enabled"
id: led_enabled
icon: mdi:alarm-light-outline
optimistic: true
restore_mode: RESTORE_DEFAULT_ON
entity_category: config
# Enable logging
logger:
# level: VERY_VERBOSE
# level: VERBOSE
# Enable Home Assistant API
api:
services:
- service: rfidreader_tag_ok
then:
- rtttl.play: "beep:d=16,o=5,b=100:b"
- service: rfidreader_tag_ko
then:
- rtttl.play: "beep:d=8,o=5,b=100:b"
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play: !lambda 'return song_str;'
- service: write_tag_id
variables:
tag_id: string
then:
- light.turn_on:
id: activity_led
brightness: 100%
red: 100%
green: 0%
blue: 0%
- lambda: |-
auto message = new nfc::NdefMessage();
std::string uri = "https://www.home-assistant.io/tag/";
uri += tag_id;
message->add_uri_record(uri);
id(pn532_board).write_mode(message);
- rtttl.play: "write:d=24,o=5,b=100:b"
- wait_until:
not:
pn532.is_writing:
- light.turn_off:
id: activity_led
- rtttl.play: "write:d=24,o=5,b=100:b,b"
i2c:
scan: False
frequency: 400kHz
pn532_i2c:
id: pn532_board
on_tag:
then:
- homeassistant.tag_scanned: !lambda |
if (!tag.has_ndef_message()) {
return x;
}
auto message = tag.get_ndef_message();
auto records = message->get_records();
for (auto &record : records) {
std::string payload = record->get_payload();
size_t pos = payload.find("https://www.home-assistant.io/tag/");
if (pos != std::string::npos) {
return payload.substr(pos + 34);
}
}
return x;
- if:
condition:
switch.is_on: buzzer_enabled
then:
- rtttl.play: "success:d=24,o=5,b=100:c,g,b"
- if:
condition:
switch.is_on: led_enabled
then:
- light.turn_on:
id: activity_led
brightness: 100%
red: 0%
green: 100%
blue: 0%
flash_length: 500ms
on_tag_removed:
then:
- homeassistant.event:
event: esphome.tag_removed
# Define the buzzer output
output:
- platform: esp8266_pwm
pin: D7
id: buzzer
binary_sensor:
- platform: status
name: "${friendly_name} Status"
# Define buzzer as output for RTTTL
rtttl:
output: buzzer
text_sensor:
- platform: version
hide_timestamp: true
name: "${friendly_name} ESPHome Version"
entity_category: diagnostic
- platform: wifi_info
ip_address:
name: "${friendly_name} IP Address"
icon: mdi:wifi
entity_category: diagnostic
ssid:
name: "${friendly_name} Connected SSID"
icon: mdi:wifi-strength-2
entity_category: diagnostic
# Configure LED
light:
- platform: neopixelbus
variant: WS2812
pin: D8
num_leds: 1
flash_transition_length: 500ms
type: GRB
id: activity_led
name: "${friendly_name} LED"
restore_mode: ALWAYS_OFF
# Enable OTA upgrade
ota:
platform: esphome
|
The code above provided by @imhotep doesn't work. When a tag is scanned, it returns "Tag " + the serial number of the tag to home assistant, instead of the tag_id uri. The result of this is a new tag being registered in Home Assistant, but when I scan that same tag with my phone, the correct tag is scanned. When I scan it with the scanner, the new "Tag serial number" entity registers that it was scanned. The logs show "Found new tag 'serial number'" |
I'm still using the modified version that I posted back on June 6, and it seems to work just fine so far. See if that works for you. |
With the update to 2024.5.0 simply scanning a tag that worked just fine in earlier versions, causes the the NFC tag reader to reboot.
Initial sound is played, LED light turns on, but nothing happens and Home Assistant doesn't register the tag scan event. The device then reboots and plays the bootup sound sequence.
[10:11:34][C][improv_serial:032]: Improv Serial:
[10:11:34][C][wifi_info:011]: WifiInfo SSID 'NFC Master Bathroom Connected SSID'
[10:11:34][C][wifi_info:011]: Icon: 'mdi:wifi-strength-2'
[10:11:34][C][wifi_info:009]: WifiInfo IPAddress 'NFC Master Bathroom IP Address'
[10:11:34][C][wifi_info:009]: Icon: 'mdi:wifi'
[TAG SCANNED HERE]
WARNING nfc-master-bathroom @ 192.168.XX.XX: Connection error occurred: [Errno 104] Connection reset by peer
INFO Processing unexpected disconnect from ESPHome API for nfc-master-bathroom @ 192.168.XX.XX
WARNING Disconnected from API
INFO Successfully connected to nfc-master-bathroom @ 192.168.XX.XX in 0.006s
INFO Successful handshake with nfc-master-bathroom @ 192.168.XX.XX in 0.027s
The text was updated successfully, but these errors were encountered: