diff --git a/esphome/components/esp32_ble_server/ble_server.cpp b/esphome/components/esp32_ble_server/ble_server.cpp index 198c13596e..03ce2d38f5 100644 --- a/esphome/components/esp32_ble_server/ble_server.cpp +++ b/esphome/components/esp32_ble_server/ble_server.cpp @@ -112,7 +112,7 @@ bool BLEServer::create_device_characteristics_() { if (this->model_.has_value()) { BLECharacteristic *model = this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ); - model->set_value(ByteBuffer::wrap(this->model_.value())); + model->set_value(ByteBuffer::wrap(std::vector(this->model_.value().begin(), this->model_.value().end()))); } else { BLECharacteristic *model = this->device_information_service_->create_characteristic(MODEL_UUID, BLECharacteristic::PROPERTY_READ); @@ -125,7 +125,7 @@ bool BLEServer::create_device_characteristics_() { BLECharacteristic *manufacturer = this->device_information_service_->create_characteristic(MANUFACTURER_UUID, BLECharacteristic::PROPERTY_READ); - manufacturer->set_value(ByteBuffer::wrap(this->manufacturer_)); + manufacturer->set_value(ByteBuffer::wrap(std::vector(this->manufacturer_.begin(), this->manufacturer_.end()))); return true; } diff --git a/esphome/core/bytebuffer.cpp b/esphome/core/bytebuffer.cpp index dc6f423140..7164d62f4e 100644 --- a/esphome/core/bytebuffer.cpp +++ b/esphome/core/bytebuffer.cpp @@ -27,36 +27,42 @@ ByteBuffer ByteBuffer::wrap(std::vector data, Endian endianness) { ByteBuffer ByteBuffer::wrap(uint8_t value) { ByteBuffer buffer = ByteBuffer::create(1); buffer.put_uint8(value); + buffer.flip(); return buffer; } ByteBuffer ByteBuffer::wrap(uint16_t value, Endian endianness) { ByteBuffer buffer = ByteBuffer::create(2, endianness); buffer.put_uint16(value); + buffer.flip(); return buffer; } ByteBuffer ByteBuffer::wrap(uint32_t value, Endian endianness) { ByteBuffer buffer = ByteBuffer::create(4, endianness); buffer.put_uint32(value); + buffer.flip(); return buffer; } ByteBuffer ByteBuffer::wrap(uint64_t value, Endian endianness) { ByteBuffer buffer = ByteBuffer::create(8, endianness); buffer.put_uint64(value); + buffer.flip(); return buffer; } ByteBuffer ByteBuffer::wrap(float value, Endian endianness) { ByteBuffer buffer = ByteBuffer::create(sizeof(float), endianness); buffer.put_float(value); + buffer.flip(); return buffer; } ByteBuffer ByteBuffer::wrap(double value, Endian endianness) { ByteBuffer buffer = ByteBuffer::create(sizeof(double), endianness); buffer.put_double(value); + buffer.flip(); return buffer; }