Skip to content

BluetoothSerial: check return value and return number of bytes written #1538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions libraries/BluetoothSerial/src/BluetoothSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down