首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >读取smartphone和arduino之间的ndef消息

读取smartphone和arduino之间的ndef消息
EN

Stack Overflow用户
提问于 2021-01-21 20:43:41
回答 1查看 243关注 0票数 2

我正在创建一个NFC移动应用(React-Native),用于在连接到Arduino Uno的rc532和智能手机之间接收和发送Ndef消息。

为了将数据从智能手机发送到Arduino,我使用了Android光束通信模式。我在接收数据,或者更确切地说,从智能手机上读取数据时遇到了问题。

在Arduino I模拟卡上,移动应用程序读取标签而不是内容,即Ndef消息,将其作为"undefine“或"null”返回给我。

我使用的库如下:https://github.com/whitedogg13/react-native-nfc-manager

这是我的数据读取代码:

代码语言:javascript
复制
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);
      });
        
    }

它返回的是:

代码语言:javascript
复制
[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"

有没有人对我的问题有任何想法或解决方案?

EN

回答 1

Stack Overflow用户

发布于 2021-01-21 23:39:57

阅读并理解错误非常重要,如下所示

清华Jan 21 2021 13:46:15.200 WARN可能未处理的承诺拒绝(id: 0):“没有可用的技术请求”

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

the example中,我可以理解您缺少NFC配置,也许您的代码需要

在您的情况下,y9ou可以在方法componentDidMount中启动NFC,例如

代码语言:javascript
复制
componentDidMount() {
  NfcManager.start();
}

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

代码语言:javascript
复制
  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);
      });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65827700

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档