diff --git a/.gitignore b/.gitignore index 259148f..0943452 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,4 @@ *.exe *.out *.app +.esphome diff --git a/components/neewerlight/neewer_light_output.cpp b/components/neewerlight/neewer_light_output.cpp index 0cadd8e..e3c3ce1 100644 --- a/components/neewerlight/neewer_light_output.cpp +++ b/components/neewerlight/neewer_light_output.cpp @@ -6,22 +6,25 @@ namespace esphome { namespace neewerlight { void NeewerBLEOutput::dump_config() { + char service_uuid_str[esp32_ble::UUID_STR_LEN]; + char char_uuid_str[esp32_ble::UUID_STR_LEN]; ESP_LOGCONFIG(TAG, "Neewer BLE Output:"); - ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str().c_str()); - ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_string().c_str()); - ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_string().c_str()); + ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str()); + ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_str(service_uuid_str)); + ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_str(char_uuid_str)); LOG_BINARY_OUTPUT(this); }; void NeewerBLEOutput::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) { + char char_uuid_str[esp32_ble::UUID_STR_LEN]; switch (event) { case ESP_GATTC_OPEN_EVT: this->client_state_ = espbt::ClientState::ESTABLISHED; - ESP_LOGW(TAG, "[%s] Connected successfully!", this->char_uuid_.to_string().c_str()); + ESP_LOGW(TAG, "[%s] Connected successfully!", this->char_uuid_.to_str(char_uuid_str)); break; case ESP_GATTC_DISCONNECT_EVT: - ESP_LOGW(TAG, "[%s] Disconnected", this->char_uuid_.to_string().c_str()); + ESP_LOGW(TAG, "[%s] Disconnected", this->char_uuid_.to_str(char_uuid_str)); this->client_state_ = espbt::ClientState::IDLE; break; case ESP_GATTC_WRITE_CHAR_EVT: { @@ -31,11 +34,11 @@ void NeewerBLEOutput::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_i auto *chr = this->parent()->get_characteristic(this->service_uuid_, this->char_uuid_); if (chr == nullptr) { - ESP_LOGW(TAG, "[%s] Characteristic not found.", this->char_uuid_.to_string().c_str()); + ESP_LOGW(TAG, "[%s] Characteristic not found.", this->char_uuid_.to_str(char_uuid_str)); break; } if (param->write.handle == chr->handle) { - ESP_LOGW(TAG, "[%s] Write error, status=%d", this->char_uuid_.to_string().c_str(), param->write.status); + ESP_LOGW(TAG, "[%s] Write error, status=%d", this->char_uuid_.to_str(char_uuid_str), param->write.status); } break; } @@ -45,16 +48,17 @@ void NeewerBLEOutput::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_i }; void NeewerBLEOutput::write_state(float state) { + char char_uuid_str[esp32_ble::UUID_STR_LEN]; if (this->client_state_ != espbt::ClientState::ESTABLISHED) { ESP_LOGW(TAG, "[%s] Not connected to BLE client. State update can not be written.", - this->char_uuid_.to_string().c_str()); + this->char_uuid_.to_str(char_uuid_str)); return; } auto *chr = this->parent()->get_characteristic(this->service_uuid_, this->char_uuid_); if (chr == nullptr) { ESP_LOGW(TAG, "[%s] Characteristic not found. State update can not be written.", - this->char_uuid_.to_string().c_str()); + this->char_uuid_.to_str(char_uuid_str)); return; } @@ -111,10 +115,12 @@ NeewerBLEOutput::NeewerBLEOutput() { }; void NeewerRGBCTLightOutput::dump_config() { + char service_uuid_str[esp32_ble::UUID_STR_LEN]; + char char_uuid_str[esp32_ble::UUID_STR_LEN]; ESP_LOGCONFIG(TAG, "Neewer RGBCT Light Output:"); - ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str().c_str()); - ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_string().c_str()); - ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_string().c_str()); + ESP_LOGCONFIG(TAG, " MAC address : %s", this->parent_->address_str()); + ESP_LOGCONFIG(TAG, " Service UUID : %s", this->service_uuid_.to_str(service_uuid_str)); + ESP_LOGCONFIG(TAG, " Characteristic UUID: %s", this->char_uuid_.to_str(char_uuid_str)); ESP_LOGCONFIG(TAG, " Require Response : %s", this->require_response_ ? "True" : "False"); ESP_LOGCONFIG(TAG, " Colour Temperatures: %.2f - %.2f", this->cold_white_temperature_, this->warm_white_temperature_); diff --git a/test-config.yml b/test-config.yml new file mode 100644 index 0000000..6891c93 --- /dev/null +++ b/test-config.yml @@ -0,0 +1,30 @@ +esphome: + name: esp32-1 + friendly_name: ESP32-1 + +esp32: + board: esp32dev + framework: + type: esp-idf + +# Enable logging +logger: + +# captive_portal: + +external_components: + - source: components + components: [neewerlight_ble, neewerlight] + +esp32_ble_tracker: + +ble_client: + - mac_address: DD:FF:FF:FF:FF:FF + id: test + +light: + - platform: neewerlight + name: "Test" + ble_client_id: test + gamma_correct: 1.0 + default_transition_length: 0s