This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Bluetooth characteristics usage

hi guys, i've a general question about bluetooth (general usage of characteristics), and i hope somebody could give me a hint how to use them properly.

So, i want to communicate with my ble-device. E.g. i want to receive a value corresponding to a key, like "char_get_value(param key)". On the ble-device i "calculate" the value, and send it back to the device which calls the caracteristic. What would be the common way? Have an additional characteristic "char_response" which notifies the device, that the value is ready, and it could read out of response, or should i update the "char_get_value" and send a notification that the characteristic has changed?

Another (similar) design question is, i want to request an action on the ble-device "char_request_action(param action_id)", how would you send an response (OK/ERROR) to the device? Would you use an additional "char_response" characteristics, which the device could bind and will get notified as soon the operation is done?

Would be great if someone could help me! Thanks in advance, Leo

Parents
  • Hi Leo,

    There are many ways of accomplishing what you need using BLE, but it is not quite clear to me exactly which one would be best suited for you.

    If your BLE device holds the data and the peer (smartphone for example) wants to use a key-value type storage, then you could simply:

    1. Use the BLE device as a GATT server, the smartphone as a GATT client

    2. Write Request from the smartphone to the BLE device to a characteristic you have set up. The Write Request contains the key.

    3. The BLE device places the value in a second characteristic you have set up and acks by sending a Write Response

    4. Read Request from the smartphone to the BLE device to the second characteristic you have set up.

    5. Read Response with the value is sent by the BLE device

    All write actions on the server are notified by means of a BLE_GATTS_EVT_WRITE event. If you want to be notified of read events too, you need to set rd_auth = 1 when populating your characteristic.

    If you want to learn more about BLE basics, this book may be of help.

  • Hi Carles, thanks! i was hoping you answer my question (saw your post about your new book) :) So you would use a second characteristic to communicate with the device, and not update and send a notification with the "char_get_value" characteristic? (To make it clear. You would separate the communication in 2 characteristics, 1 characteristic the smartphone can write, and 1 characteristic the smartphone can read?) Thanks a lot.. i think i will order the book now :)

Reply
  • Hi Carles, thanks! i was hoping you answer my question (saw your post about your new book) :) So you would use a second characteristic to communicate with the device, and not update and send a notification with the "char_get_value" characteristic? (To make it clear. You would separate the communication in 2 characteristics, 1 characteristic the smartphone can write, and 1 characteristic the smartphone can read?) Thanks a lot.. i think i will order the book now :)

Children
No Data
Related