×

如何使用WisBlock和RUI3构建NFC阅读器

消耗积分:0 | 格式:zip | 大小:1.10 MB | 2023-02-06

王彬

分享资料个

描述

介绍

目前市场上常见的NFC无线读卡器都是基于WiFi或蓝牙的,功耗大,无线传输距离有限。LoRaWAN®具有传输距离远、接收灵敏度低、功耗低等特点。

因此,使用LoRaWAN®可以弥补以上两种无线设备的不足。NFC的数据传输量也比较小,非常适合LoRaWAN®传输方式。采用 LoRaWAN® 无线传输的读卡器易于安装和部署。它是电池供电的,可以使用半年以上。

该项目的主要思想是通过 WisBlock 构建一个支持 LoRaWAN® 的无线读卡器。当读卡器读取电子标签数据时,电子标签信息会自动上传到RAK7268 WisGate Edge Lite 2内置的LoRaWAN®服务器。

使用的硬件

本项目的主要硬件使用了 WisBlock 套件。MCU选用RAK4631 WisBlock Core模块,采用Nordic nRF52840 MCU,支持蓝牙5.0(蓝牙低功耗)和Semtech公司最新的LoRa®收发器SX1262 它支持 LoRa® 和蓝牙通信模式。

image_75bj2KU8xa.png?auto=compress%2Cformat&w=740&h=555&fit=max
RAK4631
 

NFC选用WisBlock E生态的RAK13600 NFC读卡模块采用PN532芯片,支持ISO/ICE 14443A/B卡类型的读写。

 

image_OL2eZkzLF9.png?auto=compress%2Cformat&w=740&h=555&fit=max
RAK13600
 

它还配备了蜂鸣器模块RAK18001,在NFC刷卡有效时提供蜂鸣器提醒。

buzz_mLDVgV6Rlv.png?auto=compress%2Cformat&w=740&h=555&fit=max
 

本项目软件采用RUI3开发平台。RUI3为WisBlock提供了很多API接口函数,包括传感器驱动接口和无线传输接口。只需要编写少量的应用代码就可以完成这个产品的开发。

Step 1 - 硬件电路搭建

硬件准备:

  • 用于带有 LoRa SX1262 的 LoRaWAN 的 Nordic nRF52840 BLE 核心模块 | RAK4631 / RAK4631-R
  • WisBlock 底板 | RAK5005-O
  • NFC RFID NXP PN532 | RAK13600
  • 蜂鸣器模块江苏MLT-5020 | RAK18001
  • 两个 ISO/ICE 14443A/B 卡
  • 统一外壳 IP65 100x75x38mm
  • 3dBi SubG 天线 | (LoRa® 天线)
  • 5 颗 M2.5x4 螺丝和 8 颗 M1.2x3 螺丝
07d8357e-96f3-4c16-8202-1f4dd5a65b7c_eAXtnSOWCo.png?auto=compress%2Cformat&w=740&h=555&fit=max
 

五金组装:

RAK4631模块固定在CPU SLOT位置,RAK13600固定在IO SLOT位置,RAK18001固定在SLOT A(或SLOT B)上,用固定螺丝固定模块。

连接 NFC 天线、LoRa® 天线、蓝牙天线,并将它们安装到外壳中。

image_EJsyUB7XqS.png?auto=compress%2Cformat&w=740&h=555&fit=max
 

这是在组装过程中指导您的示意图

squematic_NFONAonJEl.png?auto=compress%2Cformat&w=740&h=555&fit=max
 

Step 2 - 软件环境搭建

在Arduino IDE中添加RAK4631-R开发板:

  • 打开 Arduino IDE 并转到File > Preferences
image_LMgR2GCO4i.png?auto=compress%2Cformat&w=740&h=555&fit=max
Arduino 偏好
 
  • 要将 RAK4631-R WisBlock Core 添加到您的 Arduino 板列表,您需要编辑附加板管理器 URL。单击该图标。
image_ufJNPtchyU.png?auto=compress%2Cformat&w=740&h=555&fit=max
修改其他 Board Manager URL
 
  • 复制 URLhttps://raw.githubusercontent.com/RAKWireless/RAKwireless-Arduino-BSP-Index/main/package_rakwireless.com_rui_index.json并将其粘贴到字段中。如果已经有其他 URL,只需将它们添加到下一行即可。添加 URL 后,单击确定。
image_OE8JexynOA.png?auto=compress%2Cformat&w=740&h=555&fit=max
添加其他 Board Manager URL
 
  • 重新启动 Arduino IDE。
  • 从工具菜单打开板管理器。
image_9mHIXMdRhj.png?auto=compress%2Cformat&w=740&h=555&fit=max
打开 Arduino 开发板管理器
 
  • RAK在搜索栏中。这将显示可用的 RAKwireless WisBlock 核心板,您可以将它们添加到 Arduino 板列表中。选择并安装RAKwireless RUI nRF 板
image_2axZvmbDIm.png?auto=compress%2Cformat&w=740&h=555&fit=max
安装 RAKwireless RUI nRF 板
 
  • 安装 BSP 后,选择Tools > Boards Manager > RAKWireless RUI nRF Modules > WisBlock Core RAK4631 Board
image_VDroskBMSy.png?auto=compress%2Cformat&w=740&h=555&fit=max
选择 RAKwireless WisBlock 模块
 

安装库

安装RAK13600-PN532库和Adafruit总线库:

image_I6UUUCg60D.png?auto=compress%2Cformat&w=740&h=555&fit=max
 
image_sqy1bSYf5P.png?auto=compress%2Cformat&w=740&h=555&fit=max
 

第 3 步 - 软件开发

LoRaWAN® 部分的初始化。该函数初始化协议栈的所有参数。网络接入方式为OTAA。用户需要根据自己的频段和网络接入参数修改这个宏定义。代码中使用的频段为AS923。NFC芯片初始化代码采用IIC通信协议。初始化完成后,即可使用NFC的刷卡功能。

/*************************************

   LoRaWAN band setting:
     RAK_REGION_EU433
     RAK_REGION_CN470
     RAK_REGION_RU864
     RAK_REGION_IN865
     RAK_REGION_EU868
     RAK_REGION_US915
     RAK_REGION_AU915
     RAK_REGION_KR920
     RAK_REGION_AS923

 *************************************/
#define OTAA_BAND     (RAK_REGION_AS923) 
#define OTAA_DEVEUI   {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}
#define OTAA_APPEUI   {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}
#define OTAA_APPKEY   {0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88}

void lora_init()

蜂鸣器由 PWM 控制。蜂鸣器不用时,需要关闭输出。

pinMode(BUZZER_CONTROL,OUTPUT);
 noTone(BUZZER_CONTROL);

NFC芯片初始化代码采用IIC通信协议。初始化完成后,即可使用NFC的刷卡功能。

nfc.begin();
  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata >> 24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata >> 16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata >> 8) & 0xFF, DEC);
  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  nfc.setPassiveActivationRetries(0xFF);

  //configure board to read RFID tags
  nfc.SAMConfig();
  
  Serial.println("Waiting for an ISO14443A card");

每1s循环读取是否有NFC卡。如果 ID 读取成功,蜂鸣器响 150ms,然后将卡 ID 发送到 LoRaWAN® 服务器。

void loop(void) {
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };	// Buffer to store the returned UID
  uint8_t uidLength;				// Length of the UID (4 or 7 bytes dep        ending on ISO14443A card type)

  // Wait for an ISO14443B type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success) {
    tone(BUZZER_CONTROL,4000);
    delay(150);
    noTone(BUZZER_CONTROL);
    Serial.println("Found a card!");
    Serial.print("UID Length: "); Serial.print(uidLength, DEC); Serial.println(" byte       s");
    Serial.print("UID Value: ");
    for (uint8_t i = 0; i < uidLength; i++)
    {
      Serial.print(" 0x"); Serial.print(uid[i], HEX);
    }
    Serial.println("");

   digitalWrite(ledPin1, HIGH); // LED turn on when input pin value is HIGH
   delay(150);
   digitalWrite(ledPin1, LOW); // 

  /** Send the data package */
  if (api.lorawan.send(uidLength, (uint8_t *) & uid, 2, true, 1)) 
  {
    Serial.println("Sending is requested");
  } 
  else 
  {
    Serial.println("Sending failed");
  }
    
    // Wait 1 second before continuing
    delay(1000);
  }
  else
  {
    // PN532 probably timed out waiting for a card
    Serial.println("Timed out waiting for a card");
  }
}

使用 WisToolBox 和 WisGate Edge Lite 2 进行数据记录

通过WisToolBox查看实时串口日志

image_7BulyJVMwp.png?auto=compress%2Cformat&w=740&h=555&fit=max
通过wistoolbox查看实时串口日志
 

RAK7268 内置 LoRaWAN®,如果您需要确认数据是否已成功发送,还有一个服务器日志。

image_pasted_at_2022-8-11_16-42_oB4XTPKXg0.png?auto=compress%2Cformat&w=740&h=555&fit=max
查看服务器上的日志
 

结论

在成功构建具有 LoRaWAN 连接的 NFC 读卡器后,您有多种选择可以在多种场景中实施它,例如通过标签进行商品控制、用户进入控制、构建安全控制等许多事情,并记住我们总是说#IoTMadeEasy。

此外,请关注我们的Hackster Hub 并成为我们社区的一员,以了解更多 DIY IoT 项目和新闻。

如果您想购买我们的产品,请访问我们的商店

欢迎与我们分享,写下你的疑惑,在评论区与我们互动。


声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

评论(0)
发评论

下载排行榜

全部0条评论

快来发表一下你的评论吧 !

'+ '

'+ '

'+ ''+ '
'+ ''+ ''+ '
'+ ''+ '' ); $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code ==5){ $(pop_this).attr('href',"/login/index.html"); return false } if(data.code == 2){ //跳转到VIP升级页面 window.location.href="//m.jibsdb.com/vip/index?aid=" + webid return false } //是会员 if (data.code > 0) { $('body').append(htmlSetNormalDownload); var getWidth=$("#poplayer").width(); $("#poplayer").css("margin-left","-"+getWidth/2+"px"); $('#tips').html(data.msg) $('.download_confirm').click(function(){ $('#dialog').remove(); }) } else { var down_url = $('#vipdownload').attr('data-url'); isBindAnalysisForm(pop_this, down_url, 1) } }); }); //是否开通VIP $.get('/article/vipdownload/aid/'+webid,function(data){ if(data.code == 2 || data.code ==5){ //跳转到VIP升级页面 $('#vipdownload>span').text("开通VIP 免费下载") return false }else{ // 待续费 if(data.code == 3) { vipExpiredInfo.ifVipExpired = true vipExpiredInfo.vipExpiredDate = data.data.endoftime } $('#vipdownload .icon-vip-tips').remove() $('#vipdownload>span').text("VIP免积分下载") } }); }).on("click",".download_cancel",function(){ $('#dialog').remove(); }) var setWeixinShare={};//定义默认的微信分享信息,页面如果要自定义分享,直接更改此变量即可 if(window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == 'micromessenger'){ var d={ title:'如何使用WisBlock和RUI3构建NFC阅读器',//标题 desc:$('[name=description]').attr("content"), //描述 imgUrl:'https://'+location.host+'/static/images/ele-logo.png',// 分享图标,默认是logo link:'',//链接 type:'',// 分享类型,music、video或link,不填默认为link dataUrl:'',//如果type是music或video,则要提供数据链接,默认为空 success:'', // 用户确认分享后执行的回调函数 cancel:''// 用户取消分享后执行的回调函数 } setWeixinShare=$.extend(d,setWeixinShare); $.ajax({ url:"https://www.elecfans.com/app/wechat/index.php?s=Home/ShareConfig/index", data:"share_url="+encodeURIComponent(location.href)+"&format=jsonp&domain=m", type:'get', dataType:'jsonp', success:function(res){ if(res.status!="successed"){ return false; } $.getScript('https://res.wx.qq.com/open/js/jweixin-1.0.0.js',function(result,status){ if(status!="success"){ return false; } var getWxCfg=res.data; wx.config({ //debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId:getWxCfg.appId, // 必填,公众号的唯一标识 timestamp:getWxCfg.timestamp, // 必填,生成签名的时间戳 nonceStr:getWxCfg.nonceStr, // 必填,生成签名的随机串 signature:getWxCfg.signature,// 必填,签名,见附录1 jsApiList:['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 }); wx.ready(function(){ //获取“分享到朋友圈”按钮点击状态及自定义分享内容接口 wx.onMenuShareTimeline({ title: setWeixinShare.title, // 分享标题 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享给朋友”按钮点击状态及自定义分享内容接口 wx.onMenuShareAppMessage({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 type: setWeixinShare.type, // 分享类型,music、video或link,不填默认为link dataUrl: setWeixinShare.dataUrl, // 如果type是music或video,则要提供数据链接,默认为空 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ”按钮点击状态及自定义分享内容接口 wx.onMenuShareQQ({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口 wx.onMenuShareWeibo({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口 wx.onMenuShareQZone({ title: setWeixinShare.title, // 分享标题 desc: setWeixinShare.desc, // 分享描述 link: setWeixinShare.link, // 分享链接 imgUrl: setWeixinShare.imgUrl, // 分享图标 success: function () { setWeixinShare.success; // 用户确认分享后执行的回调函数 }, cancel: function () { setWeixinShare.cancel; // 用户取消分享后执行的回调函数 } }); }); }); } }); } function openX_ad(posterid, htmlid, width, height) { if ($(htmlid).length > 0) { var randomnumber = Math.random(); var now_url = encodeURIComponent(window.location.href); var ga = document.createElement('iframe'); ga.src = 'https://www1.elecfans.com/www/delivery/myafr.php?target=_blank&cb=' + randomnumber + '&zoneid=' + posterid+'&prefer='+now_url; ga.width = width; ga.height = height; ga.frameBorder = 0; ga.scrolling = 'no'; var s = $(htmlid).append(ga); } } openX_ad(828, '#berry-300', 300, 250);