Skip to content

CurieBLE: characteristic.writeInt(...) does not perform write request #385

@sandeepmistry

Description

@sandeepmistry

When using the [bleno echo example] on my Raspberry Pi, with the sketch below, echoCharacteristic.writeInt(i) returns true, but the write request does not succeed.

#include <CurieBLE.h>

void setup() {
  Serial.begin(9600);
  while (!Serial);

  BLE.begin();

  BLE.scan();
}

void loop() {
  // check if a peripheral has been discovered
  BLEDevice peripheral = BLE.available();

  if (peripheral) {
    // discovered a peripheral, print out address, local name, and advertised service
    Serial.print("Found ");
    Serial.print(peripheral.address());
    Serial.print(" '");
    Serial.print(peripheral.localName());
    Serial.print("' ");
    Serial.print(peripheral.advertisedServiceUuid());
    Serial.println();

    if (peripheral.address() == "00:19:0E:11:24:06") {
      BLE.stopScan();

      if (peripheral.connect()) {
        Serial.println("connected");
      }

      if (peripheral.discoverAttributes()) {
        Serial.println("attributes discovered");
      }

      BLECharacteristic echoCharacteristic = peripheral.characteristic("ec0e");

      if (echoCharacteristic.canRead()) {
        Serial.println("canRead");
      }

      if (echoCharacteristic.canWrite()) {
        Serial.println("canWrite");
      }

      if (echoCharacteristic.canSubscribe()) {
        Serial.println("canSubscribe");
      }

      if (echoCharacteristic.subscribe()) {
        Serial.println("subscribed");
      }

      int i = 0;

      while(peripheral.connected()) {
        if (echoCharacteristic.writeInt(i)) {
          Serial.println("write success");
        } else {
          Serial.println("write fail");
        }

        i++;

        delay(1000);
      }
    }
  }
}

I ran hcidump on the Raspberry Pi, and the operation is failing:

2016-12-30 15:37:21.520761 > ACL data: handle 64 flags 0x02 dlen 11
    ATT: Write cmd (0x52)
      handle 0x000c value  0x79 0x00 0x00 0x00
2016-12-30 15:37:21.521400 < ACL data: handle 64 flags 0x00 dlen 9
    ATT: Error (0x01)
      Error: Write not permitted (3)
      Write cmd (0x52) on handle 0x000c

A write request should be sent instead of a write command because the characteristic only has the "write" property on not "write without response".

If I use LightBlue on my iPhone, the write succeeds using a write request:

2016-12-30 15:39:05.160968 > ACL data: handle 64 flags 0x02 dlen 9
    ATT: Write req (0x12)
      handle 0x000c value  0xab 0xcd
2016-12-30 15:39:05.162811 < ACL data: handle 64 flags 0x00 dlen 5
    ATT: Write resp (0x13)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions