arduino / arduino/ArduinoCore-arc32
CurieBLE: characteristic.read() reports success when peripheral responds with error
- Dominant language
- C
- Stars
- 330
- Forks
- 281
- PR merge metrics
- No merged PRs in 30d
Description
Testing with the 2.0.1RC2.1 JSON:
Arduino sketch:
```arduino
#include
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("BLE Central - Read + Write test");
// initialize the BLE hardware
BLE.begin();
// start scanning for peripheral
BLE.scanForName("rwfail");
}
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.println(peripheral.address());
BLE.stopScan();
Serial.println("Connecting ...");
if (peripheral.connect()) {
Serial.println("Connected");
} else {
Serial.println("Failed to connect!");
while(1);
}
// discover peripheral attributes
Serial.println("Discovering attributes ...");
if (peripheral.discoverAttributes()) {
Serial.println("Attributes discovered");
} else {
Serial.println("Attribute discovery failed.");
peripheral.disconnect();
while(1);
}
BLECharacteristic c = peripheral.characteristic("fa12");
while (peripheral.connected()) {
Serial.println("reading ...");
if (c.read()) {
// should not happen
Serial.println("read success");
} else {
// expected
Serial.println("read fail");
}
Serial.println("writing ...");
if (c.writeInt(42)) {
// should not happen
Serial.println("write success");
} else {
// expected
Serial.println("write fail");
}
delay(1000);
}
BLE.scan();
}
}
```
Node.js bleno test app:
```js
var bleno = require('bleno');
var BlenoPrimaryService = bleno.PrimaryService;
var BlenoCharacteristic = bleno.Characteristic;
console.log('bleno - read + write fail');
bleno.on('stateChange', function(state) {
console.log('on -> stateChange: ' + state);
if (state === 'poweredOn') {
bleno.startAdvertising('rwfail', ['fa11']);
} else {
bleno.stopAdvertising();
}
});
bleno.on('advertisingStart', function(error) {
console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success'));
if (!error) {
bleno.setServices([
new BlenoPrimaryService({
uuid: 'fa11',
characteristics: [
new BlenoCharacteristic({
uuid: 'fa12',
properties: ['read', 'write'],
onReadRequest: function(offset, callback) {
console.log('onReadRequest');
callback(BlenoCharacteristic.RESULT_UNLIKELY_ERROR);
},
onWriteRequest: function(data, offset, withoutResponse, callback) {
console.log('onWriteRequest');
callback(BlenoCharacteristic.RESULT_UNLIKELY_ERROR);
}
})
]
})
]);
}
});
```
`characteristic.read()` is return true even though the GATT read request fails. I expect it to return false to indicate failure.
Packet Logger trace:
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the CurieBLE characteristic.read() entry point and reproduce the behavior with the Arduino sketch and Node.js bleno test app in the issue. Trace how the peripheral's GATT error is handled, then verify that the call reports failure rather than success for the supplied error response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, node.js
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100