ble icon indicating copy to clipboard operation
ble copied to clipboard

Normal write does not require response

Open mahtaran opened this issue 4 years ago • 1 comments
trafficstars

Hi, little weird thing I am experiencing. Might just be me misunderstanding things, but I thought the difference between write and writeWithoutResponse would be that in the first case, need_rsp would be true while in the latter case it would be false. However, this appears not to be the case:

Relevant portion of the NativeScript code

} else if (result === 'write 1') {
	this._bluetooth
		.write({
			peripheralUUID: context.peripheral.UUID,
			serviceUUID: service.UUID,
			characteristicUUID: characteristic.UUID,
			value: 1
		})
		.then(
			result => {
				context.set('feedback', `value written: ${result}`);
				context.set('feedbackTimestamp', this._getTimestamp());
			},
			errorMsg => {
				context.set('feedback', errorMsg);
				context.set('feedbackTimestamp', this._getTimestamp());
			}
		);
} else if (result === 'write arraybuffer') {
	console.log('about to write ArrayBuffer');
	const bufView = new Uint8Array([97, 114, 114, 97, 121, 98, 117, 102, 102, 101, 114]); // str = arraybuffer
	this._bluetooth
		.writeWithoutResponse({
			peripheralUUID: context.peripheral.UUID,
			serviceUUID: service.UUID,
			characteristicUUID: characteristic.UUID,
			value: bufView.buffer
		})
		.then(
			() => {
				context.set('feedback', 'value written');
				context.set('feedbackTimestamp', this._getTimestamp());
			},
			errorMsg => {
				context.set('feedback', errorMsg);
				context.set('feedbackTimestamp', this._getTimestamp());
			}
		);
}

ESP-IDF (Bluetooth server) output:

I (7840866) GATTS_TABLE_DEMO: GATT_WRITE_EVT, handle = 42, value len = 1, need_rsp = false, value :
I (7840876) GATTS_TABLE_DEMO: 01 
I (7847436) GATTS_TABLE_DEMO: GATT_WRITE_EVT, handle = 42, value len = 11, need_rsp = false, value :
I (7847436) GATTS_TABLE_DEMO: 61 72 72 61 79 62 75 66 66 65 72

Is this me misunderstanding the difference between write and writeWithoutResponse, or am I otherwise doing something wrong here?

mahtaran avatar Oct 08 '21 14:10 mahtaran

I dont know about your server code nor really either about the need_rsp thing. What i can tell you is that i use both methods with different ble devices and they trigger the correct behavior on the ble device with the correct acknowledge(with write) Honestly and sadly i cant help.you with much more that that :(. You can look at the code to see if you see something weird (i am saying it works "for me")

farfromrefug avatar Oct 08 '21 17:10 farfromrefug