esphome / esphome/feature-requests

Reading ndef data from Yubikeys in PN532 module

Open
#2,207 16 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
450
Forks
29
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem you have/What new integration you would like**
I have a PN532 component and connected it with IIC to an ESP32 and used the [PN532 esphome component](https://esphome.io/components/binary_sensor/pn532.html). It can read the data written to NFC tags with the Homeassistant App but is not able to read the data from a Yubikey 5 NFC.

YAML code:
```yaml
text_sensor:
- platform: template
name: "NFC Tag Sensor"
id: nfc_tag_text
update_interval: 1s

i2c:
sda: GPIO17
scl: GPIO16
scan: true
id: bus_a

pn532_i2c:
update_interval: 1s
i2c_id: bus_a
on_tag:
then:
- logger.log: "NFC TAG Scanned"
- text_sensor.template.publish:
id: nfc_tag_text
state: !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);
} else if (payload.substr(0, 8) == "otpauth:") {
return payload;
}
}
return x;
```

Debug logs when scanning a NFC tag with data written to it via the Homeassistant App:
```
[17:01:14][D][pn532:283]: Mifare ultralight
[17:01:15][D][main:214]: NFC TAG Scanned
[17:01:15][D][text_sensor:067]: 'NFC Tag Sensor': Sending state 'tag_test'
[17:01:15][D][pn532:162]: Found new tag '04-BF-D9-FF-FF-FF-FF'
[17:01:15][D][pn532:166]: NDEF formatted records:
[17:01:15][D][pn532:168]: U - https://www.home-assistant.io/tag/tag_test
[17:01:15][D][pn532:168]: android.com:pkg - io.homeassistant.companion.android
[17:01:15][D][pn532:168]: android.com:pkg - io.homeassistant.companion.android.minimal
[17:01:15][D][pn532:295]: Waiting to read next tag
[17:01:15][D][text_sensor:067]: 'NFC Tag Sensor': Sending state 'tag_test'
```
Debug logs when scanning the Yubikey 5 NFC:
```
[17:01:36][D][pn532:283]: Mifare ultralight
[17:01:36][D][main:214]: NFC TAG Scanned
[17:01:36][D][text_sensor:067]: 'NFC Tag Sensor': Sending state '27-6A-FF-FF-FF-FF-FF'
[17:01:36][D][pn532:162]: Found new tag '27-6A-FF-FF-FF-FF-FF'
[17:01:36][D][pn532:295]: Waiting to read next tag
```
With the NFC reader of my Smartphone the Yubikey OTP is readable. So the feature is active on the Yubikey.

**It would be really nice if the PN532 component of ESPhome would also support reading the NDEF data of other NFC tags like the data from a Yubikey 5 NFC.**

**Please describe your use case for this integration and alternatives you've tried:**
I want to read the OTP of the Yubikey with a custom NFC reader to use it a door key. Since the OTP always changes it is more secure than using a static NFC tag that can be cloned easily.

**Additional context**
I found [this code](https://hg.sr.ht/~tkoskine/arduino-pn532/browse) where someone already build something similar but it is written in Arduino ADA language and I did not managed to translate this into a custom component.
Some info about the [yubikey ndef interface](https://support.yubico.com/hc/en-us/articles/360013710559-Understanding-the-NDEF-Interface-on-NFC-Enabled-YubiKeys)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the PN532 component and compare its existing NDEF handling with the YubiKey NDEF interface documentation and the linked Arduino PN532 implementation. Use the provided YAML and debug logs to reproduce the difference between ordinary NFC tags and a YubiKey 5 NFC. Done means the component can read and expose the YubiKey's NDEF data.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, yaml
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.