【发布时间】:2021-01-21 12:43:40
【问题描述】:
我正在创建一个 NFC 移动应用程序 (React-Native),用于在连接到 Arduino Uno 的 rc532 和智能手机之间接收和发送 Ndef 消息。
为了将数据从智能手机发送到 Arduino,我使用了 Android Beam 通信模式。我在接收数据或从智能手机读取数据时遇到问题。
在我模拟卡片的 Arduino 上,移动应用程序读取标签而不是内容,即 Ndef 消息,将其作为“未定义”或“空”返回给我。
我使用的库如下:https://github.com/whitedogg13/react-native-nfc-manager.
这是我的数据读取代码:
readData = async () => {
NfcManager.start();
NfcManager.setEventListener(NfcEvents.DiscoverTag, tag => {
console.log('tag', tag);
console.log(NfcManager.getCachedNdefMessageAndroid(tag));
console.log(this.parseText(tag));
console.log(JSON.stringify(tag.data));
//NfcManager.unregisterTagEvent().catch(() => 0);
});
}
它返回的是:
[Thu Jan 21 2021 13:46:10.960] LOG Running "projectNFC2" with {"rootTag":1} [Thu Jan 21 2021 13:46:13.182] LOG tag {"id": "0000000000000000", "techTypes": ["android.nfc.tech.NfcF"]}
[Thu Jan 21 2021 13:46:13.215] LOG {"_U": 0, "_V": 0, "_W": null, "_X": null}
[Thu Jan 21 2021 13:46:13.219] LOG null
[Thu Jan 21 2021 13:46:13.221] LOG undefined
[Thu Jan 21 2021 13:46:15.200] WARN Possible Unhandled Promise Rejection (id: 0): "no tech request available"
有人对我的问题有任何想法或解决方案吗?
【问题讨论】:
-
可能是您在您未显示的 arduino 上进行卡模拟的代码。您是否尝试过使用其他智能手机应用程序(如 NXP 的 Taginfo 应用程序或 NFC 工具应用程序)读取模拟卡?
-
它看起来像一个库使用问题,您可以发布您单击某个按钮时的操作代码吗?
-
是的,我试过了,阅读没有问题。我也尝试读取带有 Ndef 消息的物理标签,但我创建的移动应用程序总是返回相同的结果。
标签: javascript react-native arduino nfc