Skip to content

Fix cannot write to characteristic unless read property is set for Silabs's board #8601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

silabs-ChatNguyen
Copy link

Hi Team,
We have an issue with characteristic properties:
When properties = (Characteristic.READ | Characteristic.WRITE_NO_RESPONSE), can change the value of characteristic normally
But when properties = (Characteristic.WRITE_NO_RESPONSE), cannot change the value of characteristic.
This pull request adds code handle for this case.
Thanks!

@silabs-ChatNguyen silabs-ChatNguyen changed the title Fix cannot write to characteristic locally on device unless read property is set Fix cannot write to characteristic unless read property is set for Silabs's board Nov 14, 2023
Copy link

@jepler jepler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Two questions:

  • Is it actually correct that a BT_GATT_CHRC_READ property (without _WRITE or _WRITE_WITHOUT_RESP) should be settable?
  • if none of those bits is set, the sl_bt_gatt_server_write_attribute_value call is not made but sl_bt_gatt_server_send_notification / send_indication calls could occur if those bits are set. Should an exception be raised in this case? This is what the (incomplete) implementation of sl_bt_gatt_server_send_notification in the ble-hci implementation does.

@tannewt
Copy link
Member

tannewt commented Nov 14, 2023

What BLE service requires that the server write a WRITE_NO_RESPONSE characteristic? Doesn't that say only the client is writing to the characteristic?

@silabs-ChatNguyen
Copy link
Author

silabs-ChatNguyen commented Nov 15, 2023

What BLE service requires that the server write a WRITE_NO_RESPONSE characteristic? Doesn't that say only the client is writing to the characteristic?

Hi @tannewt
This issue is raised by a user. He uses a custom BLE service.
With only Characteristic.WRITE_NO_RESPONSE, we can't set value for "TestSVC.TestValue = random.randint(0, 255)"
When properties = (Characteristic.READ | Characteristic.WRITE_NO_RESPONSE), The value can change normally.
You can see the below example.

-----------------------------------------------------------------------------------------------------------------
import random
from adafruit_ble import*
from adafruit_ble.services import*
from adafruit_ble.uuid import*
from adafruit_ble.characteristics.int import *
from time import sleep
 
class TestService(Service):
    uuid = StandardUUID(0x2A06)
    TestValue = Uint8Characteristic(
        uuid = StandardUUID(0x2a6e),
        properties=(Characteristic.WRITE_NO_RESPONSE),
    )
  
TestSVC = TestService()
ble = BLERadio()
adv = Advertisement()
adv.short_name="Silabs-BLE"
adv.connectable = True

while True:
    ble.start_advertising(adv)
    print("start_advertising")
    while not ble.connected:
        pass
    ble.stop_advertising()
    print("stop_advertising")

    while ble.connected:
        TestSVC.TestValue = random.randint(0, 255)
        print(f'TestValue = {TestSVC.TestValue}')
        sleep(1)
    print("disconnected")
-----------------------------------------------------------------------------------------------------------------------

So i added code handle for case with only WRITE_NO_RESPONSE.

@silabs-MartinL
Copy link

silabs-MartinL commented Nov 15, 2023

This is for the Alert Level characteristic in the Immediate Alert service part of the Find Me profile. The Alert Level should only have WRITE_NO_RESPONSE so can be written remotely, however the alert should also be able to be cancelled locally on the device, hence the need to update the characteristic value locally in addition to remotely.

Edit: see - https://www.bluetooth.com/specifications/specs/immediate-alert-service-1-0/

@dhalbert dhalbert merged commit 0dffd06 into adafruit:main Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants