From 6b9e47a0aaa448c94663a4df8eccad64b084d299 Mon Sep 17 00:00:00 2001 From: gohai Date: Wed, 27 Jun 2018 11:58:40 -0700 Subject: [PATCH] BluetoothSerial: check return value and return number of bytes written --- .../BluetoothSerial/src/BluetoothSerial.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libraries/BluetoothSerial/src/BluetoothSerial.cpp b/libraries/BluetoothSerial/src/BluetoothSerial.cpp index 9a0fe455506..c0b4d5e61d9 100644 --- a/libraries/BluetoothSerial/src/BluetoothSerial.cpp +++ b/libraries/BluetoothSerial/src/BluetoothSerial.cpp @@ -220,21 +220,24 @@ int BluetoothSerial::read(void) size_t BluetoothSerial::write(uint8_t c) { - if (_spp_client){ - uint8_t buffer[1]; - buffer[0] = c; - esp_spp_write(_spp_client, 1, buffer); - return 1; + if (!_spp_client){ + return 0; } - return -1; + + uint8_t buffer[1]; + buffer[0] = c; + esp_err_t err = esp_spp_write(_spp_client, 1, buffer); + return (err == ESP_OK) ? 1 : 0; } size_t BluetoothSerial::write(const uint8_t *buffer, size_t size) { - if (_spp_client){ - esp_spp_write(_spp_client, size, (uint8_t *)buffer); + if (!_spp_client){ + return 0; } - return size; + + esp_err_t err = esp_spp_write(_spp_client, size, (uint8_t *)buffer); + return (err == ESP_OK) ? size : 0; } void BluetoothSerial::flush()