BLE Peripheral - Characteristic

new characteristic(json)

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); 

[await] characteristic.writeWait(data)

This writes data on characteristic.
It throws an error when failed.

await characteristic.writeWait([0xf0,0x27]);
console.log("write success");

[await] characteristic.readWait()

This reads data on characteristic.
It returns data array when it successds.
It throws an error when failed.

let data =  await characteristic.readWait()
console.log("data: " , data );

characteristic.onwritefromremote(address, newvalue)

This is a callback function used when characteristic gets changed by an external device.

property type description
address array central device address
newvalue array written data

characteristic.onwritefromremote = function(address, newvalue){
    console.log("remote address :",address);
    console.log("remote data :",newvalue);
}

characteristic.onreadfromremote(address)

This is a callback function used when characteristic is read by an external device.

property type description
address array central device address

characteristic.onreadfromremote = function(address){
    console.log("remote address :",address);    
}

characteristic.notify()

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();

You will Get in Few Days

Circuit for Starter “obniz Board” is available on Amazon and other online stores.
You can get it at below

Our products and resellers

Forum

Visit our developer’s forum to discuss and discover technologies.

Forum

Contact

Feel free to contact out support and technical team.

Contact us