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

gatttool is deprecated / removed #2

Open
yourealwaysbe opened this issue Mar 10, 2017 · 0 comments
Open

gatttool is deprecated / removed #2

yourealwaysbe opened this issue Mar 10, 2017 · 0 comments

Comments

@yourealwaysbe
Copy link

yourealwaysbe commented Mar 10, 2017

Most of the scripts no longer work directly because gatttool has been removed from bluez-utils. Potential replacements for

gatttool -d <mac> -a 0x0012 -n <data e.g. e3bf>

are (the somewhat hacky):

(sleep 10; echo "write-value 0x0012 <data e.g. 0xe3 0xbf>"; sleep 1) | btgatt-client -d <mac>

or the python gattlib library, which has a nice interface via the write_by_handle method, but unfortunately segfaults on my machine.

req = GATTRequester("00:11:22:33:44:55")
req.write_by_handle(0x0012, str(bytearray([14, 4, 56])))

I got something working with node's noble library, though it's a bit more involved to use. You need to call the writeHandle method, but need to go through power, scanning, and connecting to get a peripheral you can call this method on. Roughly:

mac_addr = "xx:xx:xx:xx:xx:xx"
data = [0x12, 0xef, ... ]

noble.on('discover', function handler(peripheral) {
    if (peripheral.address.toUpperCase() === mac_addr.toUpperCase()) {
        noble.stopScanning()
        noble.removeListener('discover', handler)

        peripheral.connect(function(err) {
            peripheral.writeHandle(0x0012,
                                   Buffer.from(data),
                                   false, // wait for response
                                   function (err) { process.exit(0) })
        })
    }
})

noble.on('stateChange', function(state) {
    if (state === 'poweredOn') {
        noble.startScanning()
    }
})
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

1 participant