Skip to content

Commit

Permalink
Distinction between retriable and non-retriable errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rbaron committed May 8, 2022
1 parent da21eeb commit 38f2309
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions esphome/components/ble_client/automation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ namespace esphome {
namespace ble_client {
static const char *const TAG = "ble_client.automation";

// Attempts to write to the configured characteristic. Returns false on retriable errors and true on success or
// non-retriable errors.
bool BLEWriterClientNode::write() {
if (this->node_state != espbt::ClientState::ESTABLISHED) {
ESP_LOGW(TAG, "Cannot write to BLE characteristic - not connected");
Expand All @@ -27,7 +29,8 @@ bool BLEWriterClientNode::write() {
ESP_LOGD(TAG, "Write type: ESP_GATT_WRITE_TYPE_NO_RSP");
} else {
ESP_LOGE(TAG, "Characteristic %s does not allow writing", this->char_uuid_.to_string().c_str());
return;
// Non-retriable error, likely due to user configuration error.
return true;
}
ESP_LOGD(TAG, "Will write %d bytes: %s", this->value_.size(), format_hex_pretty(this->value_).c_str());
esp_err_t err = esp_ble_gattc_write_char(this->parent()->gattc_if, this->parent()->conn_id, this->ble_char_handle_,
Expand All @@ -36,6 +39,8 @@ bool BLEWriterClientNode::write() {
ESP_LOGE(TAG, "Error writing to characteristic: %s!", esp_err_to_name(err));
return false;
}

ESP_LOGD(TAG, "Success writing to characteristic");
return true;
}

Expand Down Expand Up @@ -75,7 +80,6 @@ void BLEWriterClientNode::loop() {
return;
}

ESP_LOGD(TAG, "Success writing pending value.");
pending_write_ = false;

// If the BLEClient should not maintain an active connection, tell it to disconnect.
Expand Down

0 comments on commit 38f2309

Please sign in to comment.