question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"GATT Error Unknown"

See original GitHub issue

Hi, I’m not sure where this issue lie, but I’m running a simple peripheral with bleno which I can connect to from a web app, but as soon as I try to read from or write to my characteristic, I get:

(index):1 Uncaught (in promise) DOMException: GATT Error Unknown.

My Node code looks like this:

//// SERVICE

var BlenoPrimaryService = bleno.PrimaryService;

var RemoteCharacteristic = require('./remote-characteristic');

function RemoteService() {
  RemoteService.super_.call(this, {
    uuid: '180E',
    characteristics: [
      new RemoteCharacteristic()
    ]
  });
}

util.inherits(RemoteService, BlenoPrimaryService);

module.exports = RemoteService;

//// CHARACTERISTIC

var Descriptor = bleno.Descriptor;
var Characteristic = bleno.Characteristic;

var RemoteCharacteristic = function() {
  RemoteCharacteristic.super_.call(this, {
    uuid: '2A19',
    properties: ['read', 'write'],
    descriptors: [
      new Descriptor({
        uuid: '2901',
        value: 'Remote control'
      })
    ]
  });
};

util.inherits(RemoteCharacteristic, Characteristic);

RemoteCharacteristic.prototype.onReadRequest = function(offset, callback) {
  // return hardcoded value just for testing
  callback(this.RESULT_SUCCESS, new Buffer([98]));
};

RemoteCharacteristic.prototype.onWriteRequest = function(data, offset, withoutResponse, callback) {
  if (offset) {
    callback(this.RESULT_ATTR_NOT_LONG);
  }
  else if (data.length !== 1) {
    callback(this.RESULT_INVALID_ATTRIBUTE_LENGTH);
  }
  else {
    var button = data.getUint8(0);
    console.log('button', button);
    switch (button) {
      case 1:
        console.log('left');
        break;
      case 2:
        console.log('right');
        break;
    }
    callback(this.RESULT_SUCCESS);
  }
};

module.exports = RemoteCharacteristic;

My central code - I’m using Web Bluetooth - looks like this:

      var serviceUuid = 0x180E;
      var charUuid = 0x2A19;
      var characteristic;

      function connect() {

        navigator.bluetooth.requestDevice({
            filters: [{ services: [serviceUuid] }]
          })
          .then(function(device) {
            return device.gatt.connect();
          })
          .then(function(server) {
            return server.getPrimaryService(serviceUuid);
          })
          .then(function(service) {
            return service.getCharacteristic(charUuid);
          })
          .then(function(char) {
            characteristic = char;
          });
      }

      function write(cmd) {
        characteristic.writeValue(cmd);
      }

      function left() {
        var cmd = new Uint8Array(1);
        cmd[0] = 1;
        write(cmd);
      }

      function right() {
        var cmd = new Uint8Array(1);
        cmd[0] = 2;
        write(cmd);
      }

(I’ve tried just reading a value too but it’s the same).

(Full code: https://github.com/poshaughnessy/over-the-air-2016-hack)

(I also tried the pizza example and got another error with that: https://github.com/strangesast/bleno-web-pizza-example/issues/3)

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

0reactions
sandeepmistrycommented, Nov 29, 2016

@poshaughnessy no worries, thanks for trying my suggestion out. Yes, let’s close this for now, if there’s something wrong when bleno, please re-open again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NotSupportedError: GATT Error unknown when writing to ...
I am using Angular version 7 on windows 10 and @types/web-bluetooth package. My App was working as expected. The data was being written...
Read more >
NotSupportedError: GATT Error Unknown - Stack Overflow
I am trying to write data which is 490 in length to a device using Web Bluetooth API. When I try to write...
Read more >
bluetooth: Make "GATT Error Unknown" message more specific
1. Make sure nearby device is not paired yet. 2. Attempt to write a value to a characteristic that requires encryption. What is...
Read more >
How to fix: localhost/:1 Uncaught (in promise) DOMException
I get this error: Uncaught (in promise) DOMException: GATT Error Unknown. The code that I am writing was modified from my earlier work, ......
Read more >
Connection establishment fails with GATT ERROR 133 ...
I use BLE SDK 5.40. When I try connecting my device with nRF mobile app, it disconnects immediately throwing Error 133 - GATT...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found