Skip to content

BLERemoteCharacteristic::writeValue fails with '0x00' #420

Open
@ghost

Description

SdkVersion: v3.1-dev-239-g1c3dd23f-dirty
Arduino IDE 1.8.5 with BT sources from esp32-snippets/cpp_utils/BLE*.*
Example: ESP32_BLE_Arduino/examples/BLE_client/

Bug in the method: BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) in BLERemoteCharacteristic.cpp

data is a bytearray with binary data.

writeValue calls writeValue(std::string newValue, bool response) . Here .length() gets the length of the string up to the first \0 (0x00) -> if the binary data includes 0x00's the length is wong and only the first part of the bytearray is send...

Possible solution: Add a writeBinary fnc

void BLERemoteCharacteristic::writeBinary(uint8_t* data,size_t length, bool response) {
	ESP_LOGD(LOG_TAG, ">> writeBinary(), length: %d", length());

	// Check to see that we are connected.
	if (!getRemoteService()->getClient()->isConnected()) {
		ESP_LOGE(LOG_TAG, "Disconnected");
		//////////throw BLEDisconnectedException();
	}

	m_semaphoreWriteCharEvt.take("writeValue");

	// Invoke the ESP-IDF API to perform the write.
	esp_err_t errRc = ::esp_ble_gattc_write_char(
		m_pRemoteService->getClient()->getGattcIf(),
		m_pRemoteService->getClient()->getConnId(),
		getHandle(),
		length,
		data,
		response?ESP_GATT_WRITE_TYPE_RSP:ESP_GATT_WRITE_TYPE_NO_RSP,
		ESP_GATT_AUTH_REQ_NONE
	);

	if (errRc != ESP_OK) {
		ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
		return;
	}

	m_semaphoreWriteCharEvt.wait("writeBinary");

	ESP_LOGD(LOG_TAG, "<< writeBinary");
} // writeBinary

and redirect or correct the writeValue()
-Pit

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions