Peripheral instance
It is uuid as string.
console.log(attr.uuid); // => '4C84'
It contains characteristics in a service. It was discovered when connection automatically.
// Javascript Example
await obniz.ble.initWait();
var target = {
uuids: ["fff0"],
};
var peripheral = await obniz.ble.scan.startOneWait(target);
if(!peripheral) {
console.log('no such peripheral')
return;
}
try {
await peripheral.connectWait();
console.log("connected");
var service = peripheral.getService("1800")
for (var c of service.characteristics) {
console.log(c.uuid)
}
} catch(e) {
console.error(e);
}
Discover services.
If connect setting param 'autoDiscovery' is true(default), services are automatically disvocer on connection established.
// Javascript Example
await obniz.ble.initWait({});
obniz.ble.scan.onfind = function(peripheral){
if(peripheral.localName == "my peripheral"){
peripheral.onconnect = async function(){
console.log("success");
await peripheral.discoverAllServicesWait(); //manually discover
let service = peripheral.getService("1800");
await service.discoverAllCharacteristicsWait(); //manually discover
let characteristics = service.getCharacteristic("ff00")
}
peripheral.connect({autoDiscovery:false});
}
}
await obniz.ble.scan.startWait();
It returns a characteristic which having specified uuid in a service. Return value is null when not matched.
Case is ignored. So aa00 and AA00 are the same.
// Javascript Example
await obniz.ble.initWait();
var target = {
uuids: ["fff0"],
};
var peripheral = await obniz.ble.scan.startOneWait(target);
if(!peripheral) {
console.log('no such peripheral')
return;
}
try {
await peripheral.connectWait();
console.log("connected");
var service = peripheral.getService("1800")
var c = service.getCharacteristic("fff0")
console.log(c.uuid)
} catch(e) {
console.error(e);
}
Generated using TypeDoc