How to send TLV command through BLE in ionic app

I’m working on an app who communicate with a raspberry through BLE ( I want to send a command to the Raspberry and get the result. The only constraint is to send command with the TLV (Tag-Length-Value) format : - Tag: command identifier - Length: commande data length (0 to 18) - Value: command data

I have no idea how to do this.

Atm i have some code.

First i search all devices arround me :

this.ble.scan([], 5).subscribe(
  device => this.onDeviceDiscovered(device), 
  error => this.scanError(error)

Then i get infos from this device :

  peripheral => this.onConnected(peripheral),
  peripheral => this.onDeviceDisconnected(peripheral)

And … what now ? I’m trying to use this function : ble.write(device_id, service_uuid, characteristic_uuid, data, success, failure);

I get device_id, service_uuid, characteristics_uuid. But i don’t know how to pass data.

I’m trying something like that :

SendCommand() {
  let data: {
    RANDOM: 1,
    Lenght: 1,
    Value: 1

  let binary_string = btoa(JSON.stringify(data));
  let len = binary_string.length;
  let aBuff = new Uint8Array(len);
  for (let i = 0; i < len; i++)
    aBuff[i] = binary_string.charCodeAt(i);

  this.ble.write(,, this.peripheral.characteristic, aBuff.buffer)
    .then(res => {
    .catch(err => {

But nothing happen.

Thanks for your help :smiley: