diff --git a/README.md b/README.md new file mode 100644 index 0000000..b76de9d --- /dev/null +++ b/README.md @@ -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). diff --git a/esphome/fabula.yaml b/esphome/fabula.yaml index 4a91a62..daab4ea 100644 --- a/esphome/fabula.yaml +++ b/esphome/fabula.yaml @@ -35,10 +35,24 @@ pn532_i2c: update_interval: 1s on_tag: 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: - folder: !lambda 'return 1;' 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: then: - logger.log: "NFC Tag removed"