Skip to content

BLECharacteristic.cpp ESP_GATTS_WRITE_EVT param->write.is_prep #7960

@ripper121

Description

@ripper121

Board

ESP32-S3-DevKitC-1U

Device Description

ESP32-S3-DevKitC-1U

Hardware Configuration

Nothing Connected

Version

latest master (checkout manually)

IDE Name

Arduino IDE

Operating System

Windows 10

Flash frequency

80 MHz

PSRAM enabled

no

Upload speed

921600

Description

I used the BLE_write.ino example.
I tried to send Values from the BLE Scanner App to the ESP32 but only seen my values when I turned on Core Debug Level "Debug" via the debug output.
The onWrite() Callback was never reached.

I had to remove the if (param->write.is_prep) from the ESP_GATTS_WRITE_EVT to get it working again.
Seams like the write.is_prep is the Problem

Sketch

case ESP_GATTS_WRITE_EVT: {
// We check if this write request is for us by comparing the handles in the event.  If it is for us
// we save the new value.  Next we look at the need_rsp flag which indicates whether or not we need
// to send a response.  If we do, then we formulate a response and send it.
			if (param->write.handle == m_handle) {

				setValue(param->write.value, param->write.len);


				log_d(" - Response to write event: New value: handle: %.2x, uuid: %s",
						getHandle(), getUUID().toString().c_str());

				char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len);
				log_d(" - Data: length: %d, data: %s", param->write.len, pHexData);
				free(pHexData);

				if (param->write.need_rsp) {
					esp_gatt_rsp_t rsp;

					rsp.attr_value.len      = param->write.len;
					rsp.attr_value.handle   = m_handle;
					rsp.attr_value.offset   = param->write.offset;
					rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE;
					memcpy(rsp.attr_value.value, param->write.value, param->write.len);

					esp_err_t errRc = ::esp_ble_gatts_send_response(
							gatts_if,
							param->write.conn_id,
							param->write.trans_id, ESP_GATT_OK, &rsp);
					if (errRc != ESP_OK) {
						log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
					}
				} // Response needed

				m_pCallbacks->onWrite(this, param);

			} // Match on handles.
			break;
		} // ESP_GATTS_WRITE_EVT

Debug Message

[492499][D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_WRITE_EVT
[492500][D][BLECharacteristic.cpp:292] handleGATTServerEvent():  - Response to write event: New value: handle: 2a, uuid: beb5483e-36e1-4688-b7f5-ea07361b26a8
[492513][D][BLECharacteristic.cpp:295] handleGATTServerEvent():  - Data: length: 4, data: 54657374
*********
New value: Test
*********
[492533][D][BLEDevice.cpp:102] gattServerEventHandler(): gattServerEventHandler [esp_gatt_if: 3] ... ESP_GATTS_RESPONSE_EVT

Other Steps to Reproduce

Flash the BLE_write.ino
Connect to the Device with the BLE Scanner APP
Write values to the Device

OnWrite() will never be called

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: BLEIssues related to BLE

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions