Create Characteristics
await obniz.ble.initWait();
var characteristic = new obniz.ble.characteristic({
"uuid" : "FFF1",
"properties" : ["read","write"], // read, write, notify
"data" : [0x0e, 0x00, ...], //data for dataArray or text for string
"descriptors" : [{
"uuid" : "2901", //Characteristic User Description
"text" : "hello world characteristic", //data for dataArray or text for string
}]
});
var service = new obniz.ble.service({
"uuid" : "fff0",
"characteristics" : [ characteristic ]
});
obniz.ble.peripheral.addService(service);
This is a callback function used when characteristic is read by an external device.
characteristic.onreadfromremote = function(address){
console.log("remote address :",address);
}
This is a callback function used when characteristic is read by an external device.
characteristic.onwritefromremote = function(address, newvalue){
console.log("remote address :",address);
console.log("remote data :",newvalue);
}
Service instance
It is uuid as string.
console.log(attr.uuid); // => '4C84'
Get descriptor array
Add new descriptor
Add property
Get descriptor
This sends notify to the connected central.
var characteristic = new obniz.ble.characteristic({
uuid: 'FFF1',
data: [0x0e, 0x00],
properties : ["read","write","notify"], // add notify properties
});
var service = new obniz.ble.service({
uuid: 'FFF0',
characteristics: [characteristic],
});
obniz.ble.peripheral.addService(service);
// after central connected
characteristic.notify();
It reads data.
Even you wrote string or number, it returns binary array. It throws an error when failed.
// Javascript Example
let data = await attr.readWait()
console.log("data: " , data );
Remove property
This writes dataArray. It throws an error when failed.
// Javascript Example
await attr.writeWait([0xf0,0x27]);
console.log("write success");
Generated using TypeDoc