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

Custom services can't be discovered on certain devices #448

Open
sammy00747 opened this issue Jan 20, 2020 · 0 comments
Open

Custom services can't be discovered on certain devices #448

sammy00747 opened this issue Jan 20, 2020 · 0 comments

Comments

@sammy00747
Copy link

@sandeepmistry first of all, great work with bleno!

I am trying to create a custom service, which has a single characteristic , to test the working of bleno:

`// Using the bleno module
var bleno = require('bleno');

// Once bleno starts, begin advertising our BLE address
bleno.on('stateChange', function(state) {
console.log('State change: ' + state);
if (state === 'poweredOn') {
bleno.startAdvertising('MyDevice',['12ab']);
} else {
bleno.stopAdvertising();
}
});

// Notify the console that we've accepted a connection
bleno.on('accept', function(clientAddress) {
console.log("Accepted connection from address: " + clientAddress);
});

// Notify the console that we have disconnected from a client
bleno.on('disconnect', function(clientAddress) {
console.log("Disconnected from address: " + clientAddress);
});

// When we begin advertising, create a new service and characteristic
bleno.on('advertisingStart', function(error) {
if (error) {
console.log("Advertising start error:" + error);
} else {
console.log("Advertising start success");
bleno.setServices([

        // Define a new service
        new bleno.PrimaryService({
            uuid : '12ab',
            characteristics : [
                
                // Define a new characteristic within that service
                new bleno.Characteristic({
                    value : null,
                    uuid : '34cd',
                    properties : ['notify', 'read', 'write'],
                    
                    // If the client subscribes, we send out a message every 1 second
                    onSubscribe : function(maxValueSize, updateValueCallback) {
                        console.log("Device subscribed");
                        this.intervalId = setInterval(function() {
                            console.log("Sending: Hi!");
                            updateValueCallback(new Buffer("Hi!"));
                        }, 1000);
                    },
                    
                    // If the client unsubscribes, we stop broadcasting the message
                    onUnsubscribe : function() {
                        console.log("Device unsubscribed");
                        clearInterval(this.intervalId);
                    },
                    
                    // Send a message back to the client with the characteristic's value
                    onReadRequest : function(offset, callback) {
                        console.log("Read request received");
                        callback(this.RESULT_SUCCESS, new Buffer("Echo: " + 
                                (this.value ? this.value.toString("utf-8") : "")));
                    },
                    
                    // Accept a new value for the characterstic's value
                    onWriteRequest : function(data, offset, withoutResponse, callback) {
                        this.value = data;
                        console.log('Write request: value = ' + this.value.toString("utf-8"));
                        callback(this.RESULT_SUCCESS);
                    }

                })
                
            ]
        })
    ]);
}

});`

While this code works just fine with Honor 9N and MI Note 5, it seems to have issues with Samsung S7 Edge - this particular device can't discover the custom service created.

Environment - ubuntu 18.04 LTS.

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