BLE on Raspberry Pi using nodeJS

0

I'm trying use noble (https://github.com/abandonware/noble) on a raspberry pi 3B in order to communicate with a BLE enabled device.

I'm able to read characteristics but look like notify dosen't trigger any callback :

const { characteristics } = await peripheral.discoverSomeServicesAndCharacteristicsAsync([protocols.service], [protocols.read, protocols.notify, protocols.write]);

const write = characteristics[0];
const notify = characteristics[1];
const read = characteristics[2];

await read.readAsync(async (error, data) => {
  console.log('Read: ' + data.toString('utf8'));

  notify.on('data', (data, isNotification) => {
    console.log('Notify: ', data);
  });

  notify.notify(true, (error) => {
    console.log(error);
    console.log('Notify on');
  });
});

Notify characteristic

Characteristic {
  _noble: Noble {
    initialized: true,
    address: 'b8:27:eb:08:5f:f0',
    _state: 'poweredOn',
    _bindings: NobleBindings {
      _state: 'poweredOn',
      _addresses: [Object],
      _addresseTypes: [Object],
      _connectable: [Object],
      _pendingConnectionUuid: null,
      _connectionQueue: [],
      _handles: [Object],
      _gatts: [Object],
      _aclStreams: [Object],
      _signalings: [Object],
      _hci: [Hci],
      _gap: [Gap],
      _events: [Object: null prototype],
      _eventsCount: 24,
      onSigIntBinded: [Function: bound ],
      _scanServiceUuids: []
    },
    _peripherals: { f333ebf0c81b: [Peripheral], '04ee03b147df': [Peripheral] },
    _services: { f333ebf0c81b: {}, '04ee03b147df': [Object] },
    _characteristics: { f333ebf0c81b: {}, '04ee03b147df': [Object] },
    _descriptors: { f333ebf0c81b: {}, '04ee03b147df': [Object] },
    _discoveredPeripheralUUids: [ 'f333ebf0c81b', '04ee03b147df' ],
    _events: [Object: null prototype] {
      warning: [Array],
      newListener: [Function],
      stateChange: [Function],
      discover: [Function]
    },
    _eventsCount: 4,
    _allowDuplicates: undefined
  },
  _peripheralId: '04ee03b147df',
  _serviceUuid: '98bd00010b0e421a84e5ddbf75dc6de4',
  uuid: '98bd00030b0e421a84e5ddbf75dc6de4',
  name: null,
  type: null,
  properties: [ 'read', 'notify' ],
  descriptors: null
}

Raspbian hcidump

pi@raspberrypi:~ $ sudo hcidump -t -x
HCI sniffer - Bluetooth packet analyzer ver 5.50
device: hci0 snap_len: 1500 filter: 0xffffffff
2020-06-01 13:47:28.425834 < HCI Command: Set Event Mask (0x03|0x0001) plen 8
    Mask: 0xfffffbff07f8bf3d
2020-06-01 13:47:28.426495 > HCI Event: Command Complete (0x0e) plen 4
    Set Event Mask (0x03|0x0001) ncmd 1
    status 0x00
2020-06-01 13:47:28.426537 < HCI Command: LE Set Event Mask (0x08|0x0001) plen 8
    mask 0x1f00000000000000 (Reserved)
2020-06-01 13:47:28.426997 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Event Mask (0x08|0x0001) ncmd 1
    status 0x00
2020-06-01 13:47:28.427029 < HCI Command: Read Local Version Information (0x04|0x0001) plen 0
2020-06-01 13:47:28.427524 > HCI Event: Command Complete (0x0e) plen 12
    Read Local Version Information (0x04|0x0001) ncmd 1
    status 0x00
    HCI Version: 4.1 (0x7) HCI Revision: 0x1ed
    LMP Version: 4.1 (0x7) LMP Subversion: 0x2209
    Manufacturer: Broadcom Corporation (15)
2020-06-01 13:47:28.427561 < HCI Command: Write LE Host Supported (0x03|0x006d) plen 2
  01 00 
2020-06-01 13:47:28.428007 > HCI Event: Command Complete (0x0e) plen 4
    Write LE Host Supported (0x03|0x006d) ncmd 1
    00 
2020-06-01 13:47:28.428041 < HCI Command: Read LE Host Supported (0x03|0x006c) plen 0
2020-06-01 13:47:28.428467 > HCI Event: Command Complete (0x0e) plen 6
    Read LE Host Supported (0x03|0x006c) ncmd 1
    00 01 00 
2020-06-01 13:47:28.428499 < HCI Command: Read BD ADDR (0x04|0x0009) plen 0
2020-06-01 13:47:28.428923 > HCI Event: Command Complete (0x0e) plen 10
    Read BD ADDR (0x04|0x0009) ncmd 1
    status 0x00 bdaddr B8:27:EB:08:5F:F0
2020-06-01 13:47:28.435856 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
2020-06-01 13:47:28.436319 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-06-01 13:47:28.436375 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x01 (active)
    interval 10.000ms window 10.000ms
    own address: 0x00 (Public) policy: All
2020-06-01 13:47:28.436870 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
2020-06-01 13:47:28.450298 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
2020-06-01 13:47:28.450751 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x0c
    Error: Command Disallowed
2020-06-01 13:47:28.450812 < HCI Command: LE Set Scan Parameters (0x08|0x000b) plen 7
    type 0x01 (active)
    interval 10.000ms window 10.000ms
    own address: 0x00 (Public) policy: All
2020-06-01 13:47:28.451297 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Parameters (0x08|0x000b) ncmd 1
    status 0x00
2020-06-01 13:47:28.451350 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x01 (scanning enabled)
    filter duplicates 0x01 (enabled)
2020-06-01 13:47:28.451815 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2020-06-01 13:47:28.629389 > HCI Event: LE Meta Event (0x3e) plen 43
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr F3:33:EB:F0:C8:1B (Random)
      Flags: 0x06
      Complete service classes: 0xfe07
      Unknown type 0xff with 15 bytes data
      Unknown type 0x19 with 2 bytes data
      TX power level: 0
      RSSI: -84
2020-06-01 13:47:28.796484 > HCI Event: LE Meta Event (0x3e) plen 32
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr F3:33:EB:F0:C8:1B (Random)
      Complete local name: '846B215B5C1E33AEE9'
      RSSI: -82
2020-06-01 13:47:29.451315 > HCI Event: LE Meta Event (0x3e) plen 33
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr 04:EE:03:B1:47:DF (Public)
      Flags: 0x06
      Unknown type 0x06 with 16 bytes data
      RSSI: -34
2020-06-01 13:47:30.952864 > HCI Event: LE Meta Event (0x3e) plen 28
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr 04:EE:03:B1:47:DF (Public)
      Unknown type 0xff with 8 bytes data
      Shortened local name: '315X'
      RSSI: -52
2020-06-01 13:47:30.958663 < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    value 0x00 (scanning disabled)
    filter duplicates 0x01 (enabled)
2020-06-01 13:47:30.959329 > HCI Event: Command Complete (0x0e) plen 4
    LE Set Scan Enable (0x08|0x000c) ncmd 1
    status 0x00
2020-06-01 13:47:30.966732 < HCI Command: LE Create Connection (0x08|0x000d) plen 25
    bdaddr 04:EE:03:B1:47:DF type 0
    interval 96 window 48 initiator_filter 0
    own_bdaddr_type 0 min_interval 6 max_interval 12
    latency 0 supervision_to 200 min_ce 4 max_ce 6
2020-06-01 13:47:30.967612 > HCI Event: Command Status (0x0f) plen 4
    LE Create Connection (0x08|0x000d) status 0x00 ncmd 1
2020-06-01 13:47:32.461323 > HCI Event: LE Meta Event (0x3e) plen 19
    LE Connection Complete
      status 0x00 handle 64, role master
      bdaddr 04:EE:03:B1:47:DF (Public)
2020-06-01 13:47:32.461679 < HCI Command: LE Read Remote Used Features (0x08|0x0016) plen 2
  40 00 
2020-06-01 13:47:32.465658 > HCI Event: Command Status (0x0f) plen 4
    LE Read Remote Used Features (0x08|0x0016) status 0x00 ncmd 1
2020-06-01 13:47:32.518276 > HCI Event: LE Meta Event (0x3e) plen 12
    LE Read Remote Used Features Complete
      status 0x00 handle 64
      Features: 0x1d 0x00 0x00 0x00 0x00 0x00 0x00 0x00
2020-06-01 13:47:32.531442 < ACL data: handle 64 flags 0x00 dlen 7
    ATT: MTU req (0x02)
      client rx mtu 256
2020-06-01 13:47:32.563137 > ACL data: handle 64 flags 0x02 dlen 7
    ATT: MTU resp (0x03)
      server rx mtu 65
2020-06-01 13:47:32.570140 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Group req (0x10)
      start 0x0001, end 0xffff
      type-uuid 0x2800
2020-06-01 13:47:32.578210 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-01 13:47:32.593357 > ACL data: handle 64 flags 0x02 dlen 18
    ATT: Read By Group resp (0x11)
      attr handle 0x0001, end group handle 0x0007
      value 0x00 0x18
      attr handle 0x0008, end group handle 0x0008
      value 0x01 0x18
2020-06-01 13:47:32.595676 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Group req (0x10)
      start 0x0009, end 0xffff
      type-uuid 0x2800
2020-06-01 13:47:32.623968 > ACL data: handle 64 flags 0x02 dlen 26
    ATT: Read By Group resp (0x11)
      attr handle 0x0009, end group handle 0xffff
      value 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x01 0x00 0xbd 0x98
2020-06-01 13:47:32.628227 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Type req (0x08)
      start 0x0009, end 0xffff
      type-uuid 0x2803
2020-06-01 13:47:32.638209 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-01 13:47:32.653365 > ACL data: handle 64 flags 0x02 dlen 27
2020-06-01 13:47:32.654178 > ACL data: handle 64 flags 0x01 dlen 27
2020-06-01 13:47:32.655097 > ACL data: handle 64 flags 0x01 dlen 15
    ATT: Read By Type resp (0x09)
      length: 21
        handle 0x000a, value 0x04 0x0b 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x02 0x00 0xbd 0x98 
        handle 0x000d, value 0x12 0x0e 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x03 0x00 0xbd 0x98 
        handle 0x0011, value 0x02 0x12 0x00 0xe4 0x6d 0xdc 0x75 0xbf 0xdd 0xe5 0x84 0x1a 0x42 0x0e 0x0b 0x04 0x00 0xbd 0x98 
2020-06-01 13:47:32.657328 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Type req (0x08)
      start 0x0013, end 0xffff
      type-uuid 0x2803
2020-06-01 13:47:32.683186 > ACL data: handle 64 flags 0x02 dlen 9
    ATT: Error (0x01)
      Error: Attribute not found (10)
      Read By Type req (0x08) on handle 0x0013
2020-06-01 13:47:32.687223 < ACL data: handle 64 flags 0x00 dlen 7
    ATT: Read req (0x0a)
      handle 0x0012
2020-06-01 13:47:32.698159 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-01 13:47:32.713952 > ACL data: handle 64 flags 0x02 dlen 25
    ATT: Read resp (0x0b)
      41 75 74 6F 6D 6F 77 65 72 00 00 00 00 00 00 00 00 00 00 00 
2020-06-01 13:47:32.735016 < ACL data: handle 64 flags 0x00 dlen 11
    ATT: Read By Type req (0x08)
      start 0x000d, end 0x0010
      type-uuid 0x2902
2020-06-01 13:47:32.773189 > ACL data: handle 64 flags 0x02 dlen 9
    ATT: Error (0x01)
      Error: Insufficient encryption (15)
      Read By Type req (0x08) on handle 0x000f
2020-06-01 13:47:32.774501 < ACL data: handle 64 flags 0x00 dlen 11
    SMP: Pairing Request (0x01)
      capability 0x03 oob 0x00 auth req 0x01
      max key size 0x10 init key dist 0x00 resp key dist 0x01
      Capability: NoInputNoOutput (OOB data not present)
      Authentication: Bonding (No MITM Protection)
      Initiator Key Distribution:    
      Responder Key Distribution:  LTK  
2020-06-01 13:47:32.788189 > HCI Event: Number of Completed Packets (0x13) plen 5
    handle 64 packets 2
2020-06-01 13:47:32.803108 > ACL data: handle 64 flags 0x02 dlen 6
    SMP: Pairing Failed (0x05)
      reason 0x05
      Reason Pairing Not Supported

From what I understand this may be related to LE Encryption, which is supposed to be automatic when an encrypted characteristics is being read/written ?

node.js
raspberry-pi
bluetooth-lowenergy
asked on Stack Overflow Jun 1, 2020 by bdo334

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0