Trying to control playback folder with a tag's NDEF text field
This commit is contained in:
6
README.md
Normal file
6
README.md
Normal 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).
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user