【问题标题】:Reading ndef message between smartphone and arduino在智能手机和arduino之间读取ndef消息
【发布时间】: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


【解决方案1】:

阅读和理解错误很重要,像这样

[Thu Jan 21 2021 13:46:15.200] WARN Possible Unhandled Promise Rejection (id: 0): "no tech request available"

这是由库 a this line 生成的异常,看起来您没有设置 NFC 技术使用的类型,并且库中有对象 techRequest 未定义。

来自the example我可以理解你缺少NFC配置,也许你的代码需要是

你的情况,你可以在componentDidMount方法里面启动NFC,可以举个例子

componentDidMount() {
  NfcManager.start();
}

此外,您需要设置 NfcTech,因为该库在后台有一个未定义的对象,您的代码可能是这样的

  readData = async () => {
    let tech = Platform.OS === 'ios' ? NfcTech.MifareIOS : NfcTech.NfcA;
    let resp = await NfcManager.requestTechnology(tech, {
      alertMessage: 'Ready to do some custom Mifare cmd!'
    });
    console.warn(resp);

    // In addition the NFC uid can be found in tag.id
    //let tag = await NfcManager.getTag();
    //console.warn(tag);
    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);
      });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    • 2013-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-21
    相关资源
    最近更新 更多