arduino / arduino/ArduinoCore-arc32
CurieBLE: characteristic.writeInt(...) reports success when peripheral responds with error
- Dominant language
- C
- Stars
- 330
- Forks
- 281
- PR merge metrics
- No merged PRs in 30d
Description
Similar to #516, but for write requests. We should also see if the same applies to `characteristic.subscribe()`.
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.writeInt(42)` is return true even though the GATT write 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.h API entry point and trace the characteristic.writeInt(), read(), and subscribe() behavior exercised by the supplied Arduino sketch. Compare the GATT response handling with the bleno failure case; done means writeInt() reports the peripheral error correctly, subscribe() is checked for the same issue, and regression coverage is added if the repository has a suitable test location.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, javascript
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100