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

writeHandle() parameters? #49

Closed
tomkubitza opened this Issue Jan 13, 2014 · 10 comments

Comments

Projects
None yet
2 participants
@tomkubitza

tomkubitza commented Jan 13, 2014

Hi,
firstly, thanks a lot for you great work!

I was wondering how a concrete writeHandle() command would look like?

After having connected I wasn't successfully with the following parameters yet:

...
peripheral.writeHandle('0017', new Buffer([0x01, 0x00, 0x00]), true, function (error) {
            console.log('BLE: Write handle Error: ' + error);
            peripheral.disconnect();
});

The following screenshot shows the characteristic I would like to write 3 Bytes into (Handle 0x0017):

blehandlewrite

How would the wright parameters look like? Whats the right format for the handle?

And here another somehow related question:
If I register for a certain notification by writing 0x010000 into the notification characteristic using a handle shortcut, how can I receive the notification events? (I don't want to go through the whole service and characteristics discovery everytime just to set the notify-listener as described in the last part of the "Getting Started Guide" at https://github.com/sandeepmistry/noble/wiki/Getting-started)

Thanks a lot!
Tom

@sandeepmistry

This comment has been minimized.

Show comment
Hide comment
@sandeepmistry

sandeepmistry Jan 14, 2014

Member

@tomkubitza for the first question, the handle needs to be a number - 0x0017:

peripheral.writeHandle(0x0017, new Buffer([0x01, 0x00, 0x00]), true, function (error) {
            console.log('BLE: Write handle Error: ' + error);
            peripheral.disconnect();
});

For the second one, you can try writing 0x0100 to the handle, but since noble has no idea what characteristic is at the notified handle, no events will bubble up. I could look into adding a raw handle notified/indicated event that would report the handle and data.

Just curious which tool is that screenshot from? Are you using noble on Linux or OS X?

Member

sandeepmistry commented Jan 14, 2014

@tomkubitza for the first question, the handle needs to be a number - 0x0017:

peripheral.writeHandle(0x0017, new Buffer([0x01, 0x00, 0x00]), true, function (error) {
            console.log('BLE: Write handle Error: ' + error);
            peripheral.disconnect();
});

For the second one, you can try writing 0x0100 to the handle, but since noble has no idea what characteristic is at the notified handle, no events will bubble up. I could look into adding a raw handle notified/indicated event that would report the handle and data.

Just curious which tool is that screenshot from? Are you using noble on Linux or OS X?

@tomkubitza

This comment has been minimized.

Show comment
Hide comment
@tomkubitza

tomkubitza Jan 14, 2014

Great, first question answered :-)

Yeah, I was also looking exactly for such an generic event handler but couldn't find it. I think this would very well go in line with the readHandle/writeHandle commands. In addition this would greatly speed up reaction time when reconnecting to a device where notfications have been presistently enabled. The event listener for a certain handler number would be then just defined before calling connect().

The screenshots are from the "Master Control Panel", a great inspection programm that commes with the Nordic nRF51822 dev kit. Not sure its free, but there definetly is a similar version for Android 4.3+
I'm using noble on a rpi with raspian and bluez 5.13.

tomkubitza commented Jan 14, 2014

Great, first question answered :-)

Yeah, I was also looking exactly for such an generic event handler but couldn't find it. I think this would very well go in line with the readHandle/writeHandle commands. In addition this would greatly speed up reaction time when reconnecting to a device where notfications have been presistently enabled. The event listener for a certain handler number would be then just defined before calling connect().

The screenshots are from the "Master Control Panel", a great inspection programm that commes with the Nordic nRF51822 dev kit. Not sure its free, but there definetly is a similar version for Android 4.3+
I'm using noble on a rpi with raspian and bluez 5.13.

@sandeepmistry

This comment has been minimized.

Show comment
Hide comment
@sandeepmistry

sandeepmistry Jan 16, 2014

Member

What do you think about an event like this?

peripheral.on('handleNotify', function(handle, value) {
  // ...
});

If that looks good to you, I'll take a look on the weekend.

Cool, the Android version is a really useful tool as well!

Member

sandeepmistry commented Jan 16, 2014

What do you think about an event like this?

peripheral.on('handleNotify', function(handle, value) {
  // ...
});

If that looks good to you, I'll take a look on the weekend.

Cool, the Android version is a really useful tool as well!

@tomkubitza

This comment has been minimized.

Show comment
Hide comment
@tomkubitza

tomkubitza Jan 16, 2014

That would be perfect! Thanks a lot! :-)

tomkubitza commented Jan 16, 2014

That would be perfect! Thanks a lot! :-)

@sandeepmistry

This comment has been minimized.

Show comment
Hide comment
@sandeepmistry

sandeepmistry Jan 19, 2014

Member

@tomkubitza try out the latest from master. I've just pushed some changes (838ba0b), to add a Linux specific handleNotify event like mentioned in my previous comment.

Let me know how it goes.

Member

sandeepmistry commented Jan 19, 2014

@tomkubitza try out the latest from master. I've just pushed some changes (838ba0b), to add a Linux specific handleNotify event like mentioned in my previous comment.

Let me know how it goes.

@tomkubitza

This comment has been minimized.

Show comment
Hide comment
@tomkubitza

tomkubitza Jan 30, 2014

@sandeepmistry, nice! thanks for your work.
Unfortunately I was too busy to test it during the last two weeks. Hope to do so in the next days.
I'll let you know!

tomkubitza commented Jan 30, 2014

@sandeepmistry, nice! thanks for your work.
Unfortunately I was too busy to test it during the last two weeks. Hope to do so in the next days.
I'll let you know!

@tomkubitza

This comment has been minimized.

Show comment
Hide comment
@tomkubitza

tomkubitza Feb 2, 2014

Alright, "handleNotify" works fine for me. Good job! :-) Are you merging it into master?

There is one more thing that is kind of related to the upper one. It would be great if one could connect directly to a peripheral by its already known uuid. Right now the API only allows to connect by using the peripheral-object provided by the discover method. This makes it really hard to connect to devices that are rarely advertising or do not advertise at all.
I've also might have overlooked something, so please correct me if I'm wrong.

tomkubitza commented Feb 2, 2014

Alright, "handleNotify" works fine for me. Good job! :-) Are you merging it into master?

There is one more thing that is kind of related to the upper one. It would be great if one could connect directly to a peripheral by its already known uuid. Right now the API only allows to connect by using the peripheral-object provided by the discover method. This makes it really hard to connect to devices that are rarely advertising or do not advertise at all.
I've also might have overlooked something, so please correct me if I'm wrong.

@sandeepmistry

This comment has been minimized.

Show comment
Hide comment
@sandeepmistry

sandeepmistry Feb 3, 2014

Member

Cool, that change is in master, but not published to npm yet.

So, far almost all the devices I've seen advertise every few seconds, on OS X you need to know the UUID to connect and blued sends it to you on discover. However on Linux, you just need to know the BT address and address type. Try changing index.js to the following`:

var Noble = require('./lib/noble');
var Peripheral = require('./lib/peripheral.js');

module.exports = new Noble();
module.exports.Peripheral = Peripheral;

then outside noble you should be able to do the following:

var noble = require('noble');
var NoblePeripheral = noble.Peripheral;

var uuid = '<BT address>';
var advertisement = {};
var rssi = 127;
var peripheral = new NoblePeripheral(noble, uuid, advertisement, rssi);

...

The only issue is specifying the address type (private or random), right now noble hides the details from you inside lib/linux/bindings.js.

If you figure things out, a pull request would be great!

Member

sandeepmistry commented Feb 3, 2014

Cool, that change is in master, but not published to npm yet.

So, far almost all the devices I've seen advertise every few seconds, on OS X you need to know the UUID to connect and blued sends it to you on discover. However on Linux, you just need to know the BT address and address type. Try changing index.js to the following`:

var Noble = require('./lib/noble');
var Peripheral = require('./lib/peripheral.js');

module.exports = new Noble();
module.exports.Peripheral = Peripheral;

then outside noble you should be able to do the following:

var noble = require('noble');
var NoblePeripheral = noble.Peripheral;

var uuid = '<BT address>';
var advertisement = {};
var rssi = 127;
var peripheral = new NoblePeripheral(noble, uuid, advertisement, rssi);

...

The only issue is specifying the address type (private or random), right now noble hides the details from you inside lib/linux/bindings.js.

If you figure things out, a pull request would be great!

@tomkubitza

This comment has been minimized.

Show comment
Hide comment
@tomkubitza

tomkubitza Feb 7, 2014

Great, I'll give it a try on the weekend!
Thanks! :-)

tomkubitza commented Feb 7, 2014

Great, I'll give it a try on the weekend!
Thanks! :-)

@sandeepmistry

This comment has been minimized.

Show comment
Hide comment
@sandeepmistry

sandeepmistry Feb 16, 2014

Member

Looks like things are good, closing.

Member

sandeepmistry commented Feb 16, 2014

Looks like things are good, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment