Raspi+EXPLORE-NFC Node.js 제어를 통해 웹에 연결

EXPLORE-NFC RasPi에서 사용하는 NFC 리더입니다.

Node.js제어여기 라이브러리를 통해 제대로 작동하지 못해 내용을 만들어 보았습니다.
여기 있습니다.
node_modules/explorenfc/index.js
//省略
  read: function(cb){
    // exec: spawns a shell.
    child_process.exec(binary, function(error, stdout, stderr){
      // TODO, parse the output from the board
      // If it looks like this could be what we want
      var result = processLines(stdout);
      if(result){
        cb(result);
      }else{
        cb(stdout);
      }
    });
  },

//省略
stdout의 내용을 직접 출력합니다.
샘플 코드를 편집하여 다음과 같은 샘플을 만들었습니다.
nfc.js
'use strict'

const nfc = require("explorenfc");

nfc.init("/usr/bin/explorenfc-basic");
nfc.read((nfcEvent) => {
  if(nfcEvent){
    let tmp = nfcEvent.split('\r\n');
    let nfcdata = {};
    nfcdata.Manufacturer = tmp[2].split(':')[1];
    nfcdata.CID = tmp[3].split(':')[1];
    nfcdata.IC = tmp[4].split(':')[1];
    console.log(nfcdata);
  }else{
    console.log("no NFC Event");
  }
});

실행
$ node nfc.js
{ Manufacturer: ' \t0114',
  CID: ' \t01149615C010',
  IC: ' \t0401' }
이런 느낌으로 nfc의 정보가 들어오고 있다nfcdata.

또한 Milkcoa로 네트워크 연결


밀카오 사용법에 대해 알아봐 주세요.
nfc.js
'use strict'

const nfc = require("explorenfc");
const MilkCocoa = require('milkcocoa');
const milkcocoa = new MilkCocoa('<id>.mlkcca.com');
const ds = milkcocoa.dataStore('mydatastore');

nfc.init("/usr/bin/explorenfc-basic");
nfc.read((nfcEvent) => {
  if(nfcEvent){
    let tmp = nfcEvent.split('\r\n');
    let nfcdata = {};

    nfcdata.Manufacturer = tmp[2].split(':')[1];
    nfcdata.CID = tmp[3].split(':')[1];
    nfcdata.IC = tmp[4].split(':')[1];
    console.log(nfcdata);
    ds.push(nfcdata); //Milkcocoaに情報を保存
    ds.send({flag:1}); //Milkcocoaに情報を送信
  }else{
    console.log("no NFC Event");
  }
});

좋은 웹페이지 즐겨찾기