cancel
Showing results for 
Search instead for 
Did you mean: 

Issues with BLE Write Request for LED Control on STEVAL-STWINKT1

KaisBo7
Associate II

Hello,

I'm working on a BLE server using the STEVAL-STWINKT1 board and the STSW-STWINKT01 package , and I'm encountering issues with the GATT characteristic write operations, particularly for controlling an LED.

Setup:
Board: STEVAL-STWINKT1
BLE stack: Using the ST BlueNRG BLE libraries
GATT DB: The GATT database includes a characteristic to control an LED (LedCharHandle).
Functionality: I'm trying to control the LED on the server side using write requests from a BLE client.
Problem:
The BLE client sends a write request to the server (STEVAL-STWINKT1) to toggle the LED. However, the write request either isn't received or isn't processed correctly by the server.
I've verified that the Write_Request_CB function is implemented and checks the correct handle (LedCharHandle + 1). It attempts to read the data to control the LED, but the LED control functionality isn't triggered as expected.
Key Code Sections:
Here is the key section of the write request handler:

void Write_Request_CB(uint16_t handle, uint8_t *data, uint8_t length) {
if (handle == LedCharHandle + 1) {
if (length == 1) {
uint8_t led_status = data[0];
Control_LED(led_status); // Custom function to handle LED control
}
}
}

void Control_LED(uint8_t led_status) {
if (led_status) {
LedOnTargetPlatform(); // Function to turn on the LED
TargetBoardFeatures.LedStatus = 1;
} else {
LedOffTargetPlatform(); // Function to turn off the LED
TargetBoardFeatures.LedStatus = 0;
}
}

void aci_gatt_write_permit_req_event(uint16_t Connection_Handle,
uint16_t Attribute_Handle,
uint8_t Data_Length,
uint8_t *Data)
{
printf("Write permit request received. Handle: 0x%X, Data length: %d\n", Attribute_Handle, Data_Length);

// Call the write request callback with appropriate parameters
Write_Request_CB(Attribute_Handle, Data, Data_Length);

// Respond to the client after processing the write request
aci_gatt_write_resp(Connection_Handle, Attribute_Handle, 0x00, 0x00, Data_Length, Data);
}

I also modified the properties to CHAR_PROP_WRITE_WITHOUT_RESP | CHAR_PROP_READ in the tBleStatus Add_HWServW2ST_Service(void).

What I've Tried:
Verified that LedCharHandle is set correctly during characteristic initialization.
Added debug prints in the Write_Request_CB function to confirm the handle check is correct. The function is either not triggered or doesn't process the data correctly.
The read requests for other characteristics (e.g., environmental sensors) work fine, but the LED characteristic seems to be the issue.

Questions:
Could this be an issue with the way the characteristic handle is being initialized or used?
Is there any additional configuration required in the GATT DB to properly handle write requests?
Could this be related to how events are processed (e.g., HCI events in APP_UserEvtRx)?
Any insights or suggestions would be greatly appreciated!

Thanks in advance!

 

0 REPLIES 0