コード例 #1
0
ファイル: index.js プロジェクト: 24hr-malmo/service.nfc
socket.bind(address, function(err) {

    if (err) throw err;

    console.log("NFC publishing service started");

    broadcaster.start(function() {
        console.log("Broadcasting about myself");        
    });

    n.on('uid', function(uid) {
        var uidString = uid.toString('hex');
        if (lastUid != uidString) {
            lastUid = uidString;
            socket.send("NFC " + uidString);
            clearTimeout(clearRef);
            clearRef = setTimeout(function() {
                lastUid = ""; 
            }, 1000);
        }
    });

    n.start();

});
コード例 #2
0
ファイル: app.js プロジェクト: ITJesse/rfidminer
io.sockets.on('connection', function(socket){
	console.log('OK');
	socket.on('touch', function(data){
		gameLogic.touch(socket, data);
	});
	n.on('uid', function(uid) {
		gameLogic.nfcScan(socket, uid.toString('hex'));
	});
});
コード例 #3
0
ファイル: eggs.js プロジェクト: Sensorica/urvogel
  nfcdev.on('read', function(tag) {
    //console.log(util.inspect(tag, { depth: null }));
    if ((!!tag.data) && (!!tag.offset)) {
      tlvs = nfc.parse(tag.data.slice(tag.offset))
      //console.log(util.inspect(tlvs, { depth: null }))
      if (!!tlvs && ('ndef' in tlvs[0])) {
        attachedData = tlvs[0].ndef[0].value;
        console.log("TAG: " + attachedData);

        if (attachedData == "eggs") {
          // Update contract  
          getValue(function (result) {
            curEggs = result.toNumber();
            console.log("Adding a dozen eggs")
            setValue(curEggs+12);
          });
          /*
          eggsContract.get(function(error, result){
            if (error) { throw error }
            curEggs = result.toNumber();
            console.log("Current eggs number is:\t\t\t" + result.toNumber());
            console.log("Adding a dozen eggs")
            setValue(curEggs+12);
          });
          */
        } else {
          console.log("Sorry, we don't accept " + attachedData);
        }

      }
      
      nfcdev.stop();

    } else {
      console.log("Hold tag longer on the RFID reader.")
    }

  });
コード例 #4
0
ファイル: app.js プロジェクト: ITJesse/rfidminer
/**
 * Module dependencies.
 */

var express = require('express');
var routes = require('./routes');
var user = require('./routes/user');
var http = require('http');
var path = require('path');
var nfc = require('nfc').nfc;
var gameLogic = require('./modules/gameLogic');

var n = new nfc();

var app = express();

// all environments
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));

// development only
if ('development' == app.get('env')) {
コード例 #5
0
ファイル: eggs.js プロジェクト: Sensorica/urvogel
//
// Urvogel - the eggs on the blockchain
//

// Node js native libs
var fs = require ('fs')
  , util = require('util')
  ;

// Open source libs
var erisC = require('eris-contracts')
  , ndef = require('ndef')
  , nfc  = require('nfc').nfc
  , devices = nfc.scan()
  ;

/********************************* Contracts **********************************/
var erisdbURL = "http://localhost:1337/rpc";

// get the abi and deployed data squared away
var contractData = require('./contracts/epm.json');
var eggsContractAddress = contractData["deployStorageK"];
var eggsAbi = JSON.parse(fs.readFileSync("./contracts/abi/" + eggsContractAddress));

// properly instantiate the contract objects manager using the erisdb URL
// and the account data (which is a temporary hack)
var accountData = require('./contracts/accounts.json');
var contractsManager = erisC.newContractManagerDev(erisdbURL, accountData.eggchain_full_001);

// properly instantiate the contract objects using the abi and address
var eggsContract = contractsManager.newContractFactory(eggsAbi).at(eggsContractAddress);