Trying to control playback folder with a tag's NDEF text field

This commit is contained in:
Daniele Verducci
2025-12-11 00:56:56 +01:00
parent 348a6f2c9f
commit ea8c69e0aa
2 changed files with 22 additions and 2 deletions

6
README.md Normal file
View File

@@ -0,0 +1,6 @@
# Fabula
## NFC Tag format
I used Mifare ultralight tags.
A valid tag should contain a single text field containing the name of the directory to play (a number between 01 and 99).

View File

@@ -35,10 +35,24 @@ pn532_i2c:
update_interval: 1s update_interval: 1s
on_tag: on_tag:
then: then:
- logger.log: "NFC Tag found" # - logger.log:
# format: "NFC Tag found: %s"
# args: [ 'tag.get_ndef_message()->get_records()[0]->get_payload().c_str()' ]
- dfplayer.play_folder: - dfplayer.play_folder:
folder: !lambda 'return 1;'
loop: True loop: True
# Crashes somewhere here in the lambda
folder: !lambda |-
if (!tag.has_ndef_message()) {
return 0; // Plays "No tag found" audio
}
auto message = tag.get_ndef_message();
auto records = message->get_records();
for (auto &record : records) {
std::string payload = record->get_payload();
ESP_LOGD("Fabula", "NFC NDEF record type %s - value %s - int value %d", record->get_type().c_str(), record->get_payload().c_str(), stoi(payload));
return stoi(payload);
}
return 0;
on_tag_removed: on_tag_removed:
then: then:
- logger.log: "NFC Tag removed" - logger.log: "NFC Tag removed"