BLEでデータの取得を機器(UA-651BLE)からしようとしています。
プラグインはcordova-plugin-ble-centralを使用しています。
IDやNameの取得はでき、connectionもできました。:1kkkjj
そのあと、ble.startNotification(0x2902)でデータを取得しようとしているので、indicationの設定の仕方がわからずな状態になっています。
ble.writeで0x2902に書き込みをやってみてもNot Foundとなってしまいます。
Androidのサンプルるとか見ているとwriteDescriptorとなっており、writeとは違う?
どなたか、このあたりご教授ください。
それと、cordova-plugin-ble-centralにこだわっているわけではないのでcordova-plugin-bluetoothのほうができるとかでも結構です。
よろしくお願いします。
app.js
var event = typeof cordova === 'undefined' ? 'DOMContentLoaded' : 'deviceready'; console.log("event:" + event ); document.addEventListener(event, onDeviceReady, false); function onDeviceReady() { alert( device.cordova ); } var myApp = ons.bootstrap(); var app; var ua = navigator.userAgent; alert( "ua:" + ua ); ons.ready(function() { }); var heartRate = { service_uuid: '1810', characteristic_uuid: '2a35', // BloodPressureMeasurement cccd_uuid : '2902' // CCC Descriptor for Blood Measurement } myApp.controller('AppController', function() { this.pushes = 0; this.pops = 0; monaca.pushPage(); }); myApp.controller('MainMenuController', function( $scope ) { this.world = 'World'; var gPeripheral; //---- Connect関連 $scope.onConnect= function(){ function fncConnect( peripheral ) { // データフェッチ doLog("Connected to:" + gPeripheral.id ); var data = new Uint8Array(2); data[0] = 0x02; data[1] = 0x00; // window.ble.write( gPeripheral.id, heartRate.service_uuid, heartRate.cccd_uuid, data.buffer, // function() { window.ble.startNotification( gPeripheral.id, heartRate.service_uuid, heartRate.characteristic_uuid, fncCbOnData, fncOnError); // }, // function( reason ) { // doLog( "Err CCCD:" + JSON.stringify( reason )); // }); // window.ble.read( gPeripheral.id, heartRate.service_uuid, heartRate.characteristic_uuid, // fncOnData, fncOnError); } function fncDisconnect( reason ) { doLog( 'Disconnected' ); window.ble.stopNotification( gPeripheral.id, heartRate.service_uuid, heartRate.characteristic_uuid, function() { alert( "OK stopNotification" ); }, function() { alert( "NG stopNotification" ); }); } function fncOnData( buffer ) { var data = new Uint8Array(buffer); var wStr = ''; data.forEach( function( item ) { wStr += ( item + ':' ); }); var wAb = String.fromCharCode.apply("", new Uint8Array( buffer )); var wStr1 = ''; doLog( 'Data:' + wStr ); doLog( 'Asci:' + wAb ); } function fncOnError( reason ) { console.log( JSON.stringify( reason )); doLog( "Err:" + JSON.stringify( reason )); } window.ble.connect( gPeripheral.id, fncConnect, fncDisconnect); } function fncCbOnData( buffer ) { alert( "fncCbOnData" ); } //---- Scan関連 $scope.onScan = function(){ var foundHeartRateMonitor = false; $scope.statusMsg = 'Scan Module'; window.ble.isEnabled( function() { function onScan(peripheral) { console.log("Found:" + JSON.stringify(peripheral)); doLog("Found:" + JSON.stringify(peripheral)); foundHeartRateMonitor = true; gPeripheral = peripheral; doLog( 'ID:' + gPeripheral.id ); doLog( 'NAME:' + gPeripheral.name ); } function scanFailure(reason) { alert("BLE Scan Failed:" + reason); } window.ble.scan([], 5, onScan, scanFailure); setTimeout(function() { if (!foundHeartRateMonitor) { alert( "Did not find a heart rate monitor." ); } }, 5000); }, function() { alert( "BluetoothをONにしてください" ); }) } function doLog( str ) { d_data.innerHTML = d_data.innerHTML + str + '<br />'; } });
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/18 13:26
2018/08/18 13:28
2018/08/19 05:09