Raspberry Pi + BLEã§ãkonashi/SBBLEãåããã¦ã¿ãã®ã§ãã®æé ãç´¹ä»ãã¾ãã
使ç¨ãããã®ï¼
ã»Raspberry Pi B
ã»USB Bluetoothãã³ã°ã«ï¼I-O DATA Bluetooth4.0+EDR/LEæºæ USBã¢ããã¿ã¼ USB-BT40LEï¼
ã»SBBLE
æé ï¼ï¼
ãããåèã«node.js ãã¤ã³ã¹ãã¼ã«ãããv0.10.24ã使ç¨ããã
ã»Raspberry Piã«nodejsãã¤ã³ã¹ãã¼ã« - fukajun - DeepValley -
æåã«nodebrewãã¤ã³ã¹ãã¼ã«ããã¨ãPATHã追å ããã¨ããã¡ãã»ã¼ã¸ãåºãã®ã§”.bashrc”ã«è¿½å ãã¦ããã
æé ï¼ï¼
ãããåèã«BlueZ 4.101 㨠nobleãã¤ã³ã¹ãã¼ã«ãããbluez-5.4ã§ã¯NGã ã£ãã
ã»Getting started · sandeepmistry-noble Wiki · GitHub
æé ï¼ï¼
ããã®ã”2. ç°å¢å¤æ°ãå¼ãç¶ãå ´å”ãåèã«ãvisudo ã³ãã³ã使ç¨ãã¦sudoã«ç°å¢å¤æ°ãå¼ãç¶ãããã« sudoers ãè¨å®ããã
ã»sudoãã³ãã³ããè¦ã¤ããã¾ãããPATHãåæåããã¦ããã¨ãã®å¯¾å¦æ³ - ã·ã³ã°ã¹ããã°
nobleãã¤ã³ã¹ãã¼ã«ããã¨ã«ã¬ã³ããã£ã¬ã¯ããªã«node_modules/nobleã¨ãããã£ã¬ã¯ããªä½ãããã
ããã«nobleã®ãµã³ãã«çãæãã®ã§åä½ç¢ºèªã«ä½¿ããã
åããªãæã¯ã”sudo hciconfig hci0 up” ãå®è¡ãã¦ã¿ãã
æé ï¼ï¼
node_modules/nobleã«ãããã®ããã°ã©ã ãé©å½ãªååãä»ãã¦ä¿åãã(ä¾ãã°kn.js)ã
ã»14/11/12: Node.js+nobleã§konashiãã¤ã¤ã
å®è¡ã¯ sudo node kn.jsã
ãã¾ãããã°ãkonashi/SBBLEã®PIO0-PIO7ã«ã¤ãªãã LEDãç¹ç¯ããã¯ããï¼SBBLEã§åä½ç¢ºèªãããï¼
UUIDãå¤æ´ããã°koshianã§ãåãããkoshianã®UUIDã¯ãããè¦ãã°ãããã
koshianã®UUIDã¯ãã¤ãã³ç¡ãã®ï¼ï¼é²å°æåã§æå®ããã
koshianã¯ã·ãªã¢ã«åä¿¡ã®Notifyãããã©ã«ãã§ONã«ãªã£ã¦ããããã§ã´ããåä¿¡ããããã ã(2014.11.30æç¹ã§ã®ãã¡ã¼ã )
PIO0ã®Lãã«ã¨AIO0ãªã¼ãã®ä¾ï¼
//------------------------------------------------------------------------------
var noble = require('./index');
noble.on('stateChange', function(state) {
if (state === 'poweredOn') noble.startScanning();
else noble.stopScanning();
});
noble.on('discover', function(peripheral) {
noble.stopScanning();
console.log('peripheral with UUID ' + peripheral.uuid + ' found');
var advertisement = peripheral.advertisement;
var localName = advertisement.localName;
if (localName) {
console.log('Local Name = ' + localName);
}
peripheral.connect(function(error){
if(error) console.log('connect error: ' + error);
console.log('connected to ' + peripheral.uuid);
peripheral.discoverServices(['ff00'], function (error, services){ // 0xff00=KONASHI_SERVICE_UUID
if(error) console.log('discoverServices error: ' + error);
console.log('services.length: ' + services.length);
var konashiService = services[0];
konashiService.discoverCharacteristics(['3000','3002','3008'], function(error, characteristics){
if(error) console.log('discoverCharacteristics error: ' + error);
console.log('characteristics.length: ' + characteristics.length);
characteristics[0].write(new Buffer([1]), true); // 0x3000=KONASHI_PIO_SETTING_UUID
var toggle = false;
setInterval(function(){
characteristics[2].read(function(error, data) { //0x3008=KONASHI_ANALOG_READ_0_UUID
if (data) {
console.log( 'value:' + (data[1] + data[0]*256)/1000 );
}
});
if(toggle){
// LED ON
characteristics[1].write(new Buffer([1]), true); // 0x3002=KONASHI_PIO_OUTPUT_UUID
} else {
// LED OFF
characteristics[1].write(new Buffer([0]), true); // 0x3002=KONASHI_PIO_OUTPUT_UUID
}
toggle = !toggle;
}, 1000);
});
});
});
});
//------------------------------------------------------------------------------
è£è¶³ï¼
konashi/SBBLEãåããã¨ãã¯ãã£ã©ã¯ã¿ãªã¹ãã£ãã¯ã¹ã«ã©ãããå¤ãèªã¿æ¸ãããã°è¯ããç¥ãå¿ è¦ãããã
ãã®æã¯ã©ã³ãã³ã°ã¨ã¬ã¯ãããã¯ã¹ãããå ¬éãã¦ä¸ãã£ã¦ããSBBLEã®ã½ã¼ã¹ãåèã«ãªãã
ã»SBDBTã·ãªã¼ãºãµãã¼ããã¼ã¸
ã¼ä»¥ä¸ã¼
åèãªã³ã¯
ã»14/11/12: Node.js+nobleã§konashiãã¤ã¤ã
ã»Getting started · sandeepmistry-noble
ã»konashi
ã»SBBLE
ã»SBDBTã·ãªã¼ãºãµãã¼ããã¼ã¸
ã»Bluetoothãè¼ã£ã¦ãArduinoæ´¾çãã¼ããBlendMicroãã¨Node.jsã§BLEãã