This is some part of my bleno program :
bleno.on('stateChange', function(state) {
//console.log('on -> stateChange: ' + state);
if (state === 'poweredOn') {
console.log('bleno on ' + state);
//bleno.startAdvertising('project', ['ec00']);
advertisementData = new Buffer(manufacturerData, "hex");
bleno.startAdvertisingWithEIRData(advertisementData);
} else {
console.log('bleno off ' + state);
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
console.log('bleno advertisingStart ' );
if (!error) {
bleno.setServices([
new BlenoPrimaryService({
uuid: 'ec00',
characteristics: [
new Characteristic({
uuid: 'ec0e',
properties: [ 'read' ],
value: 'true',
})
]
})
]);
}
});
this is some part of my noble program :
noble.on('scanStart', function(error) {
console.log('noble scanStart ' );
setTimeout(function() {
noble.stopScanning();
}, 1500);
});
noble.on('discover', function(peripheral) {
peripheral.connect(function(err) {
peripheral.discoverServices( [id],function(err, services) {
services.forEach(function(service) {
console.log('found service: ', service.uuid);
s_id = service.uuid;
service.discoverCharacteristics([], function(err, characteristics) {
characteristics.forEach(function(characteristic) {
console.log('found characteristic: ', characteristic.uuid);
console.log('characteristic value: ', characteristic.value);
c_id = characteristic.uuid;
//console.log('serviceUuids characteristicUuid : ' + s_id + ' '+ c_id);
});
});
});
});
console.log('serviceUuids characteristicUuid : ' + s_id + ' '+ c_id);
});
console.log('peripheral discovered (' + peripheral.id +
' with address <' + peripheral.address + ', ' + peripheral.addressType + '>,' +
' connectable ' + peripheral.connectable + ',' +
' RSSI ' + peripheral.rssi + ':');
console.log('\thello my local name is:');
console.log('\t\t' + peripheral.advertisement.localName);
console.log('\tcan I interest you in any of the following advertised services:');
console.log('\t\t' + JSON.stringify(peripheral.advertisement.serviceUuids));
if (peripheral.advertisement.manufacturerData) {
console.log('\there is my manufacturer data:');
console.log('\t\t' + JSON.stringify(peripheral.advertisement.manufacturerData.toString('hex')));
}
});
I found that the program can only write a " bleno.startAdvertising " Because my program must advertise manufacturerData, so only wrote bleno.startAdvertisingWithEIRData(advertisementData); But this way I can only receive the manufacturerData, we can't find the service from bleno.
Sometimes it work, but not very often .
Why???
Please help me!!! Thx.
via Vincent Lin
No comments:
Post a Comment