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

Write to characteristic not working on Mac #32

Open
elafargue opened this issue Apr 7, 2019 · 3 comments
Open

Write to characteristic not working on Mac #32

elafargue opened this issue Apr 7, 2019 · 3 comments

Comments

@elafargue
Copy link

On Mojave, writing to characteristics doesn't seem to work at all - the same exact code on a Linux machine writes fine, but on the Mac it looks like event though there is no error, data doesn't make it out to the peripheral.

Has characteristic writing been tested on this new MacOS native implementation?

@geovie
Copy link
Collaborator

geovie commented Apr 7, 2019

@elafargue Worked so far for me. Can you post a snippet of your code? Are you sure that you call write with the correct arguments? Maybe have a look at #20

@elafargue
Copy link
Author

elafargue commented Apr 7, 2019

This is the write method in my program - it has been working for ages (>1 year, used on a bunch of stations connected to BLE sensors out there), but stopped for the Mac when migrating to Mojave, which led me to try this fork. Can you see something that looks incorrect there?

this.write = function (data, info, callback) {
            if (!portOpen || info == undefined || callback == undefined)
                return;
            var s = findService(info.service_uuid);
            s.discoverCharacteristics([ info.characteristic_uuid.replace(/-/gi,'') ], function(err, c) {
                if (typeof c == 'undefined' ) {
                    debug('Error: could not find a matching characteristic');
                    self.emit('status', {
                        openerror: true,
                        reason: 'Could not connect to the BLE service',
                        description: 'Did not find characteristic.'
                    });
                    self.close();
                    return;
                }

                //  Now we can write
                var dab = Buffer.from(data);
                var noresp = c[0].properties.indexOf('writeWithoutResponse') != -1;
                c[0].write(dab, noresp, function(err) {debug('writing result', err)});
            });
        };

@buttjer
Copy link

buttjer commented Apr 9, 2019

This is the write method in my program - it has been working for ages (>1 year, used on a bunch of stations connected to BLE sensors out there), but stopped for the Mac when migrating to Mojave, which led me to try this fork. Can you see something that looks incorrect there?

this.write = function (data, info, callback) {
            if (!portOpen || info == undefined || callback == undefined)
                return;
            var s = findService(info.service_uuid);
            s.discoverCharacteristics([ info.characteristic_uuid.replace(/-/gi,'') ], function(err, c) {
                if (typeof c == 'undefined' ) {
                    debug('Error: could not find a matching characteristic');
                    self.emit('status', {
                        openerror: true,
                        reason: 'Could not connect to the BLE service',
                        description: 'Did not find characteristic.'
                    });
                    self.close();
                    return;
                }

                //  Now we can write
                var dab = Buffer.from(data);
                var noresp = c[0].properties.indexOf('writeWithoutResponse') != -1;
                c[0].write(dab, noresp, function(err) {debug('writing result', err)});
            });
        };

Not sure if this helps but writeWithoutResponse is unused in noble-mac. You 'll get response bothway.

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

3 participants