function start() { var nrf = NRF24.connect(options.spiDev, options.cePin, options.irqPin); //nrf._debug = true; nrf.channel( options.channel ) .transmitPower( options.transmitPower ) .dataRate( options.dataRate ) .crcBytes( options.crcBytes ) .autoRetransmit({count:15, delay:4000}) .begin(function () { var rx = nrf.openPipe('rx', options.pipes[0]); var tx = nrf.openPipe('tx', options.pipes[1]); var tap = new TAP(); rx.on('data', function (d) { d.reverse(); var data = tap.parse( d ); console.log("Got data %j", data); values.push(tap.value()); while(values.length > 20) values.shift() }); tx.on('error', function (e) { console.warn("Error sending.", e); }); tx.on('ready', function() { console.log("TX Ready"); setInterval(function() { var buf = Buffer("Ich bin"); console.log("Sending %s", buf); tx.write(buf.reverse()); }, 5000); }); }); }
}); // when using node-nrf, the struct members come in oposite order than sent // this took me some tome to figure out var RawPacket = _.struct([ _.float32("value"), // the actual value of the measurement being transmitted _.uint8("sensorId"), // sensor id (unique within a client node) _.uint8("nodeId"), // client node id (unique within one RF24Star network)); _.uint8("reserved"), // not used _.uint8("packetType") // 0=reserved, 1=publish, 2=puback, 3=request, 4=response ]); // nRF24l01 general initialization var radio = nrf.connect(argv.spi, argv.ce, argv.irq); radio.channel(0x4c).dataRate(argv.rate).crcBytes(2).autoRetransmit({ count: 15, delay: 500 }); var listeningPipe; var replyPipes = []; //Initiates radio var checkTimer; var initRadio = function() { var listeningPipe = radio.openPipe('rx', 0xF0F0F0F000, { size: RawPacket.size, autoAck: true
var config = require("./config"); var NRF24 = require("nrf"), spiDev = "/dev/spidev0.1", cePin = 24, irqPin = 17, pipes = config.pipes; var connected=0, sleep=0, security=0, pir=0, temp = 1, hum=1, light = 1, lightover=0, fanover=0, lightset=1, fanset=0; //var setdat = {"sleep":sleep, "fanover":fanover, "lightover":lightover, "lightset": lightset, "fanset": fanset}; //var statusdat = {"connected":connected, "pir": pir, "temp":temp, "light":light}; var nrf = NRF24.connect(spiDev, cePin, irqPin); var express = require('express'), app = express(); var path = require('path'), cors = require('cors'), bodyParser = require('body-parser'), buff = require('bufferpack'), mongo = require('mongojs'); var dbenable = 1; if(dbenable==1){ var mongouri = config.mongouri; var collection = mongo.connect(mongouri, [config.collection]); } app.use(express.static(process.cwd() + '/public')); app.use(cors()); app.use(bodyParser.urlencoded({extended: false})); var tx, rx1, rx2; var sock; setInterval(function(){lightover=0;radioSend();meterUpdate();butUpdate();},2700000); //nrf._debug = true; nrf.channel(0x4c).transmitPower('PA_HIGH').dataRate('1Mbps').crcBytes(2).autoRetransmit({count:15, delay:4000}).begin(function () { nrf.printDetails(); tx = nrf.openPipe('tx', pipes[0], {autoAck: false}); rx1 = nrf.openPipe('rx', pipes[1], {autoAck: false}); rx2 = nrf.openPipe('rx', pipes[2]); rx1.on('data', function(d){recvDat(d)}); rx2.on('data', function(d){recvDat(d)});
var nrf = require('nrf') var radio = nrf.connect("/dev/spidev0.0", 18,17) var mqtt = require('mqtt'); var mqclient = mqtt.connect(); var redis = require("redis"), redisclient = redis.createClient(); require('buffertools').extend(); radio.channel(0,function(err){ if(err)console.log(err) }) radio.dataRate('250kbps') radio.autoRetransmit({count:0}) radio.crcBytes(1) radio.begin(function () { console.log("radio ready, begin receiwing") var rx = radio.openPipe('rx',0x6161616161,{size:5,autoAck:false}) rx.on('data', function(chunk) { chunk.reverse() //console.log(chunk) var asHex = chunk.toString('hex') redisclient.publish('radiodata',asHex) mqclient.publish('radio/data',asHex) console.log(asHex+":"+new Date()) }); }); /* setInterval(function(){ radio.printDetails();