This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

sending data using GATT_Notification()-cc2541

Other Parts Discussed in Thread: CC2541, CC2541DK-MINI, CC2650, CC2540

Hi all,

Can anyone please suggest if i need to create any service for sending data using GATT_Notification()? I have modified the changes given in File:Cc2540 throughput 10ms 20byte notifications.zip provided in processors.wiki.ti.com/.../CC2540_Data_Throughput for sending 20bytes data using sendData(). I can see in sniffer 20 bytes data is getting transmitted but not able to receive this data in mobile phone. In stead if i use some predefined service like magnetometer service for sending 20bytes then i am able to receive 20 bytes data in mobile phone. I want to know

1)if i need to create any service in cc2541 FW for sending data using sendData() so that it can be received in mobile phone?

2)Do i need to create service in android side for receiving data sent using GATT_Notification() in sendData()?

If anyone can suggest any document which can describe for receiving gatt notification data then it will be useful for me.

  • i think a service is required and mobile application should also be modified to access that service. We are also working on this thing.
  • Hi Nikhil,
    As i am able to transmit 20bytes using magnetometer service, so what's advantage of using GATT_Notification() over sending data using magnetometer service? Will throughput decrease(throughput 5.9kbytes/sec by using GATT_Notification())? if we continue to use same service(magnetometer suppose) is it going to affect anything? i need to transmit around 500kbytes in as less time as possible. Do you have any idea?
  • Hi kumar ,

    I want to know that how you did that , i am also working on same thing but i am unable to implement it as i am not able to understand how to do it ??
  • Hi Ansul,
    May i know which side you need help hardware or android side? If you can tell me more what do you want then i can explain you.
  • Hi kumar

    Hardware side and i want to know what changes you made in your code??
  • You can use CC2541DK-MINI as test HW. For SW part, you can refer to processors.wiki.ti.com/.../CC2540_Data_Throughput.
  • i had used TI sensortag code and flashed in my hardware and i was able to scan and connect to the mobile without any problem.
  • I think there should be no impact on performance by using magnetometer service. Anyway, you can test to confirm it.
  • Thanks for your reply. I will test it. Can you please tell if i use magnetometer service then also maximum i can send just 20bytes at a time or i can increase it?
  • You can only send 20 bytes at a time.
  • What is the lowest possible frequency for sending data. I mean if not more at once, we can send 20bytes more frequently.
  • If you read data in processors.wiki.ti.com/.../CC2540_Data_Throughput, the max data rate is 5.9K bytes per second using CC254x.
  • Hi Yikai,
    Is there any specific guide for creating custom bluetooth embedded application using CC2541 i mean creating vendor specific service guide?
    I have found one similar guide for cc2650DK and trying to modify simple ble peripheral project according to the steps given but i am worried if the modification will work or not as there are lots to change.
  • I don't understand your question well. Can you tell me which guide you refer to for CC2650 so I can know what to suggest?
  • As I know, there's no similar document for CC254x. However, these steps should be applied to CC254x without problem.
  • I don't think throughput will be similar in case data is sent using Gatt Notification and using some service because for sending data using service, it needs to process multiple functions but using gatt notification its comparatively less. For this purpose only i am trying to create my own service both at cc2541 and android side but don't know about result. Need to wait until completed.
    Can you please tell if i want to receive data sent using gatt notification(sendData() in zip file) in some ble central device(cc2541) then how can i receive it? Is there any helping guide for this? if possible i will try to read using the service i am creating.
  • If you run HostTest on CC2540 USB dongle and connect it with Btool, GATT_notification would be output to Btool UART directly.
  • Hi Yikai,
    I want to know that i want to communicate between PC and sensorTAG CC2650 using UART and i am using UART echo example but i am not able to implement it .Can you suggest me something else??
  • As you said we can test data sent using GATT_Notification() in BTool, so for testing throughput(5.9kbytes/sec) and whether data is transmitted and received by cc2540 dongle its acceptable to use BTool but until we implement receiving data in some real time application like some ble central device then its not fruitful as we don't have source code of BTool how it receives gatt notification data and how it processes. So up to my understanding using some service is the only possibility until we have source code.
  • BTool communicate with CC2540 USB dongle using HCI Vendor Specific HCI commands. You can refer to TI BLE HCI Vendor Specific HCI Guide pdf in BLE stack document folder.
  • Ok. First i will test creating new service and then look into HCI commands. It seems that it's suitable for application which uses uart data transfer like pc based application.
  • Variable SUNLIGHTSERVICE_CHAR1 is undefined in project but used in http://processors.wiki.ti.com/index.php/Tutorial:_How_to_Create_a_Custom_Bluetooth_Smart_Embedded_Application_with_the_CC2650DK

    Will it be SUNLIGHT_CHAR1 in place?

  • In reference to the document for creating custom profile, i had modified the FW. I am using CC2540 USB dongle as central device and using it in BTool. Here i have included the log for different characteristics. I am not able to get either of the two custom characteristic values(marked in green). i have checked by debugging using key press. SUNLIGHT_CHAR1 value is incremented every time key is pressed and periodic event is called every 5sec. As shown in the flow chart of the document, if two characteristics values are equal then 1st it will check notification is enable or not and if enabled, it will send notification.

    1)Can you please specify how to check and enable/disable notification?

    2)Which part of code(function) sends notification?  

    I will debug to check if concerned function is called or not.

  • I have replied you that Btool uses TI_BLE_Vendor_Specific_HCI_Guide.pdf so please read it first. By the way, you can contact your TI local representative and see if you can sign SLA with TI to get BTool source code.
  • I don't need BTOOL source code as my application doesn't uses uart(for PC). Its simply sending and receiving data to and from mobile phone.
    I have read different documents including vendor specific HCI guide and software developers guide. Now i have got some idea about working of BLE but still have some doubt about sending and receiving data.
    I have gone through different FW also.
    For example for reading characteristic in SimpleBLEPeripheral project, simpleProfile_ReadAttrCB is used. Similarly for writing data simpleProfile_WriteAttrCB.
    SimpleProfile_SetParameter() is used to set characteristic value. If there is any change in the characteristic value then data will be transmitted over the air. So i don't have problem in sending data, simply i need to call SimpleProfile_SetParameter() which will in turn result to sending data to the central device.
    Up to my understanding, if any data is received from the client then simpleProfile_ReadAttrCB will be called as there will be change in the characteristic value when data will be written.
    So here comes my doubt which function i need to modify code to read the characteristic value when any data is sent from client and how to process it. i also know we can read using different parameters like UUID,handle etc but finding difficult to implement it.
  • Can you please confirm if characteristic value "SIMPLEPROFILE_CHAR1" is sent from client to peripheral in simplebleperipheral project then i can read the characteristic value using SimpleProfile_GetParameter()? Although it may be my misunderstanding but I am trying my best to get things and reading documents also but practically i am not able to get more as this is just beginning for me so only getting doubts.
  • Hi Kumar,

    I also had the same issue. I was not able to receive it. Did you find any work around? It seems that the data being sent from sendByte() function should come from characteristic values which has read and notify property. However this doesnt seems to be the case with sendByte() function.

    Any suggestions from yous side?

    thanks
  • Hi Spandan,
    It has been long since i worked on BLE but can you please tell me what actual issue you are facing? I had left idea of sending data using GATT Notification. Later i had used SimpleBLEPeripheral sample code and modified it according to my application. I had used SimpleProfile_GetParameter() being called in simpleProfileChangeCB for processing the received data based on UUID and SimpleProfile_SetParameter() for sending data and i could send,receive and process data successfully.
    If you can give me hint what do you actually want then i can help you up to what i have worked with.

    Regards
    Kumar
  • Hi,

    Untill now I have understood that SimpleBLEPeripheral application uses SimpleProfile_SetParameter() function to update the value to client. However In my application I'm just reading some data through SPI and want to send it as it is. One way is to save the data into some buffer and then save it into different characteristic value by using SimpleProfile_SetParameter() function, which will then update the value to client. Does that sound right? For this I will have to make all the char as Notify and read. Any suggestions ??
  • Hi Spandan,
    I think your understanding is correct about how data is sent from server to client. I don't have clear idea about how frequently you have to send data and how much is the size of data. If you have gone through the manuals then you can send maximum 23bytes(not sure) in one connection interval. If you have to send bulk of data then you can reduce the min and max connection interval and set timer based event to send data frequently by setting the characteristics using SimpleProfile_SetParameter() but keep in mind that whereas reducing connection interval will result in higher throughput and higher power consumption, Increasing them will result in late response and low power consumption. Which ever characteristic you want to send data, you will have to make the characteristic property as write and notify. If you want also to read data from the characteristics then you can also set characteristic property as read. As soon as the characteristic value is set at the server or client side and if the characteristic property is set as notify then the changed value will be notified to the other side in the next connection interval.
    Coming to your application, for better calculation, you can set characteristic length as 20. Set characteristic property accordingly. Now read 20bytes from your buffer and set them to the characteristic value. The changed value will be notified at the other end in next connection interval. If you want to send bulk of data then you can follow as mentioned above. You can also try to call function to set characteristic value twice or thrice in such case. If you have to send single data then one characteristic will be enough. It would be better if you can use two characteristics one for sending data and other for receiving data.
    Regards
    Kumar
  • Hi Kumar,

    using the setparameter(), i'm able to receive 20 bytes at once on char4 (I've modified the code). This 20 bytes works with the connection interval range of 100ms to 1000ms and calling the periodic task every 5 second (default settings). When I change periodi task period to every second , it doesnt work. Any idea?
  • Hi Spandan,
    If possible can you please show me your settings for connection interval and how you set periodic event to send data? I have been able to send by setting the min conn interval as 12.5ms and max conn interval as 15ms and calling periodic event every 25ms.
    I have also been able to send and receive data by setting different connection intervals in the range of 12.5ms-1000ms and setting periodic event with different time interval.
    As far as i think there may be problem with your connection interval settings. Please verify once if your connection with client remains active when you send data every 1sec. If connection is inactive then data will not be sent.
    Regards
    Kumar
  • Hi Kumar,

    following are my settings:
    #define SBP_PERIODIC_EVT_PERIOD 1000 /* original is 5000. changed to 1000*/
    #define DEFAULT_ADVERTISING_INTERVAL 160
    #define DEFAULT_DESIRED_MIN_CONN_INTERVAL 80
    #define DEFAULT_DESIRED_MAX_CONN_INTERVAL 800
    #define DEFAULT_DESIRED_CONN_TIMEOUT 1000

    In the header file.
    #define SIMPLEPROFILE_CHAR5_LEN 15 /* works well if its 12, break on 15 */
    #define SIMPLEPROFILE_CHAR4_LEN 15 /* works well if its 12, break on 15 */

    With this settings I'm able to get 12 bytes. When I try to send 15 bytes it doesnt work. I think i'm getting confused between 3 things.
    1. minimum connection interval that can be supported by either party (client or server)
    2. the rate of periodic event is called and
    3. number of bytes and packets we are sending per connection event

    There is no clear documentation explaining the relation between these 3 things. If you know these I would really appreciate your help. One more thing, with your setting, how many bytes were you able to get on the phone?

    Also I've just verified that with 7ms (periodic event), 10ms (connection interval) I'm able to get 12 bytes successfully. but when I try to send 15 bytes it doesnt work.
  • Hi Kumar,

    I found the problem. It wasnt with the connection interval parameters. I forgot to change the array length to 20. Now it works well.

    Thanks
  • Hi Spandan,
    Connection interval is entirely dependent on central device which is mobile in your case i.e. central device assigns connection interval in between the min and max connection interval set by the server. Different mobiles support different min connection interval.
    If you go through software developers guide(SWRU271G page no 18) then you can find its clearly mentioned that "The connection interval can range from a minimum value of 6 (7.5ms) to a maximum of 3200 (4.0s)." Hence you need to select min and max conn interval in between 6(7.5ms) and 3200(4s). For better performance and for testing with different mobiles, you can set the min conn interval as DEFAULT_DESIRED_MIN_CONN_INTERVAL=10(10-16 will be better).
    However you should keep in mind that BLE is not designed for higher throughput so setting this interval would lead to much higher power consumption and hence you should be smart in setting min and max conn interval depending on your application requirement.
    It would be better if first you decide at what interval you want to send data. Based on that you can wisely set the connection parameters. If possible try to set min and max connection interval close to each other so that you can judge that central device will connect in that interval otherwise you can't predict exactly what connection interval central device has assigned(mostly central device assigns connection interval as max conn interval(not sure)). You can get all connection related information in the document specified above.
    2)Devices can send data only at connection interval assigned by central device. It would be better if you set your periodic event to be greater than the max conn time otherwise packets will be dropped.
    3)Maxm you can send 23bytes in a packet at a time(section 5.5 in document). You can test how much packets is actually received in one connection interval without any loss because different mobiles will give you different results. You can try to send 2-3 packets and check if any data is missing.
    As per your setting of periodic event and conn interval, i think you will be missing more data. Please verify it.
    Regards
    Kumar