DOMException: GATT operation not permitted.

Hi!

I used the next code from ready JS example from Chrome WEB bluetooth API to send bytes to BLE app UART example.

Connection is established ok.

But I can't send data from function due to error: DOMException: GATT operation not permitted.

Please tell me how can I fix it? Thank you!

  var myCharacteristic;

  var deviceName;
  
  function connect() {

     let serviceUuid = "6e400001-b5a3-f393-e0a9-e50e24dcca9e";
	 let characteristicUuid = "6e400003-b5a3-f393-e0a9-e50e24dcca9e";
	 let characteristicRx = "6e400002-b5a3-f393-e0a9-e50e24dcca9e";


    navigator.bluetooth.requestDevice({filters: [{services: [serviceUuid]}]})
    .then(device => {
      log('Connecting...');
      deviceName = device.name;
      return device.gatt.connect();
    })
    .then(server => {
      console.log('Getting Service...');
      return server.getPrimaryService(serviceUuid);
    })
    .then(service => {
      console.log('Getting Characteristic...');
      return service.getCharacteristic(characteristicUuid);
    })
    .then(characteristic => {
      myCharacteristic = characteristic;
      return myCharacteristic.startNotifications().then(_ => {
        console.log('> Notifications started');
        log("Connected to: " + deviceName);
        myCharacteristic.addEventListener('characteristicvaluechanged',
            handleNotifications);
      });
    })
    .catch(error => {
      console.log('Argh! ' + error);
    });
  }

  function disconnect() {
    if (myCharacteristic) {
      myCharacteristic.stopNotifications()
      .then(_ => {
        console.log('> Notifications stopped');
        log("Disconnected")
        myCharacteristic.removeEventListener('characteristicvaluechanged',
            handleNotifications);
      })
      .catch(error => {
        console.log('Argh! ' + error);
      });
    }
  }

  function handleNotifications(event) {
    let value = event.target.value;
    log(deviceName + "> " + new TextDecoder().decode(value));
    console.log('> Received: ' + new TextDecoder().decode(value));
  }

  function send() {
    var data = document.getElementById("input").value;
    log("You> " + data);
    myCharacteristic.writeValue(str2ab(data+"\n"))
    document.getElementById("input").value = "";
  }

Parents Reply Children
No Data
Related