Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help - Subscribe to a Characteristic with indicate properties #957

Open
mathbozzi opened this issue Feb 18, 2021 · 1 comment
Open

Help - Subscribe to a Characteristic with indicate properties #957

mathbozzi opened this issue Feb 18, 2021 · 1 comment

Comments

@mathbozzi
Copy link

mathbozzi commented Feb 18, 2021

I'm trying to read from my Blood Pressure monitor. The service is 1810 and the characteristic is 2a35, but the buffer is empty. The properties is: [ 'indicate' ].

My code:

const noble = require('@abandonware/noble')

 noble.on('stateChange', async (state) => {
    if (state === 'poweredOn') {
        await noble.startScanningAsync([], false);
    }else {
        noble.stopScanningAsync();
    }
 });


noble.on('discover', async (peripheral) => {
    console.log(peripheral.id)
    if (peripheral.id === "ec21e54394ca") peripheral.connectAsync(() => {


        peripheral.discoverServices(['1810'],(e, services) => {
            const bp = services[0];
            console.log({ bp })
            bp.discoverCharacteristics(['2a35'], (e, characteristics) => {   
                const chara = characteristics[0]
                // chara.notify(true,async function(error){});
                chara.subscribeAsync();
                // chara.subscribe();
                console.log("here");
                console.log(chara);

                // chara.once('read', (data) => {
                //     console.log(data);
                // })
                chara.once('data', async function(data,isNotification){
                    console.log('hello',data, isNotification);
                })

                chara.readAsync(async (error,data)=>{
                    console.log(data);
                })

            })
        })

    })
})


out:

ec21e54394ca    
{
  bp: Service {
    _noble: Noble {
      initialized: true,
      address: '00:1a:7d:da:71:13',
      _state: 'poweredOn',
      _bindings: [NobleBindings],
      _peripherals: [Object],
      _services: [Object],
      _characteristics: [Object],
      _descriptors: [Object],
      _discoveredPeripheralUUids: [Array],
      _events: [Object: null prototype],
      _eventsCount: 4,
      _allowDuplicates: false
    },
    _peripheralId: 'ec21e54394ca',
    uuid: '1810',
    name: 'Blood Pressure',
    type: 'org.bluetooth.service.blood_pressuer',
    includedServiceUuids: null,
    characteristics: null
  }
}
here
Characteristic {
  _noble: Noble {
    initialized: true,
    address: '00:1a:7d:da:71:13',
    _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: { ec21e54394ca: [Peripheral] },
    _services: { ec21e54394ca: [Object] },
    _characteristics: { ec21e54394ca: [Object] },
    _descriptors: { ec21e54394ca: [Object] },
    _discoveredPeripheralUUids: [ 'ec21e54394ca' ],
    _events: [Object: null prototype] {
      warning: [Function (anonymous)],
      newListener: [Function (anonymous)],
      stateChange: [AsyncFunction (anonymous)],
      discover: [AsyncFunction (anonymous)]
    },
    _eventsCount: 4,
    _allowDuplicates: false
  },
  _peripheralId: 'ec21e54394ca',
  _serviceUuid: '1810',
  uuid: '2a35',
  name: 'Blood Pressure Measurement',
  type: 'org.bluetooth.characteristic.blood_pressure_measurement',
  properties: [ 'indicate' ],                 /////////// INDICATE
  descriptors: null,
  _events: [Object: null prototype] {
    notify: [Function: bound onceWrapper] { listener: [Function (anonymous)] }
  },
  _eventsCount: 1
}
hello <Buffer > false                       /////////////BUFFER EMPTY
<Buffer >                                        //////////// BUFFER EMPTY

Buffer is empty, means that i'm not subscribed? ..

@mathbozzi mathbozzi reopened this Feb 18, 2021
@rzr
Copy link

rzr commented Mar 30, 2021

Please also check with:

https://www.npmjs.com/package/@abandonware/noble/v/1.9.2-13

Relate-to: #926

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants