There was no handle_cccd property before, so I tried to set it manually via characteristic.hande_cccd = 0x1.
handle_cccd
characteristic.hande_cccd = 0x1
const BoseAR = { SERVICE_UUID: "0000fdd2-0000-1000-8000-00805f9b34fb", CHARACTERISTIC_UUIDs: { GESTURE_INFORMATION: "a0384f52-f95a-4bcd-b898-7b9ceec92dad", GESTURE_CONFIGURATION: "21e550af-f780-477b-9334-1f983296f1d7", GESTURE_DATA: "9014dd4e-79ba-4802-a275-894d3b85ac74", SENSOR_INFOMRATION: "855cb3e7-98ff-42a6-80fc-40b32a2221c1", SENSOR_CONFIGURATION: "5af38af6-000e-404b-9b46-07f77580890b", SENSOR_DATA: "56a72ab8-4988-4cc8-a752-fbd1d54a953d", }, GESTURE_IDs: { 129 : 'double tap', 130 : 'head nod', 131 : 'head shake', 192 : 'unknown gesture 192', 193 : 'unknown gesture 193', 194 : 'unknown gesture 194', }, getGestureNameByGestureId: function (GESTURE_ID) { return this.GESTURE_IDs[GESTURE_ID]; }, getGestureIdByGestureName: function(GESTURE_NAME) { return Object.keys(this.GESTURE_IDs).find(GESTURE_ID => { return this.GESTURE_IDs[GESTURE_ID] == GESTURE_NAME; }); }, _ableGesture : function(gestureName, enabled) { const _gestureId = this.getGestureIdByGestureName(gestureName); if(this.isConnected()) { return this.characteristics.GESTURE_CONFIGURATION.readValue().then(dataView => { for(let offset = 0; offset < dataView.byteLength; offset+=2) { const gestureId = dataView.getUint8(offset); if(gestureId == _gestureId) { dataView.setUint8(offset+1, enabled); } } return this.characteristics.GESTURE_CONFIGURATION.writeValue(dataView.buffer); }); } }, enableGesture : function(gestureName) { return this._ableGesture(gestureName, true); }, disableGesture : function(gestureName) { return this._ableGesture(gestureName, false); }, SENSOR_NAMEs: [ 'accelerometer', 'gyroscope', 'rotation', 'game rotation' ], SENSOR_SAMPLE_PERIODs: [ 320, 160, 80, 40, 20 ], ACCURACY_NAMEs: [ 'unreliable', 'low', 'medium', 'high' ], connect: function() { return NRF.requestDevice({ filters: [{services: [this.SERVICE_UUID]}], }).then(device => { this.device = device; return device.gatt.connect(); }).then(server => { this.server = server; return server.startBonding(); }).then(() => { return this.server.getPrimaryService(this.SERVICE_UUID); }).then(service => { this.service = service; this.characteristics = {}; return Object.keys(this.CHARACTERISTIC_UUIDs).reduce((promise, CHARACTERISTIC_NAME) => { const CHARACTERISTIC_UUID = this.CHARACTERISTIC_UUIDs[CHARACTERISTIC_NAME]; return promise.then(() => { return this.service.getCharacteristic(CHARACTERISTIC_UUID).then(characteristic => { console.log(CHARACTERISTIC_NAME); this.characteristics[CHARACTERISTIC_NAME] = characteristic; switch(CHARACTERISTIC_NAME) { case 'GESTURE_INFORMATION': break; case 'GESTURE_CONFIGURATION': break; case 'GESTURE_DATA': break; case 'SENSOR_INFOMRATION': break; case 'SENSOR_CONFIGURATION': break; case 'SENSOR_DATA': break; default: break; } if(characteristic.properties.notify) { //characteristic.handle_cccd = 0x1; characteristic.on('characteristicvaluechanged', event => { console.log(event); }); return characteristic.startNotifications(); } }); }); }, Promise.resolve([])); }).then(() => { console.log("FINISHED"); }); }, isConnected : function() { return this.device && this.device.gatt && this.device.gatt.connected; }, disconnect : function() { if(this.isConnected()) { this.device.gatt.disconnect(); } }, }; BoseAR.connect();
@Zakaton started
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
There was no
handle_cccd
property before, so I tried to set it manually viacharacteristic.hande_cccd = 0x1
.