Utilizing the Client/Server BLE to get ADC data

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am using a CY8CKIT-042-BLE PSoC 4 bluetooth kit, and the end goal of this objective I am trying to complete is, I want to utilize the bluetooth dongle (CYBL10162-56LQXI) as a central hub to gather ADC value from the PSoC peripheral (CY8C4247LQI-BL483). I noted that the bluetooth dongle, when using the 100 projects 100 days Day 13 Client/Server program (https://github.com/cypresssemiconductorco/PSoC-4-BLE/tree/master/100_Projects_in_100_Days/Day013_Cli...) that depending on the commands by the dongle, it can enable/disble notifications as well s read the Tx Power level.

   

 

   

I want to modify it in such a way so that when the command for reading Tx power level is sent via the bluetooth dongle, that instead of getting the TX power level, it gets an ADC value from the PSoC. The PSoC itself will have its own set up of an ADC SAR SEQ which would give just an ADC value gathered, example could be temperature. But the problem is that I am unsure how to go about it. I don't know if it is a modification within the PSoC's programming, and the understanding of what the CYBLE_TPS_TX_POWER_LEVEL value would be, or if it can grab the value of an ADC input from the PSoC in some other way. Could someone point me in the right direction of how to proceed?

   

 

   

I noted that one of the functions within the peripheral is "CyBle_TpssSendNotification()" which in its current set up, sends the power level. can that be modified in such a way to send the adc value instead?

   

 

   

Went into it a bit more and found the end of sending notification has to do with the CyBle_GattsNotification() function. presuming the same cyBle_connHandle, what would need to change is the type for CYBLE_GATTS_HANDLE_VALUE_NTF_T (aka CYBLE_GATT_HANDLE_VALUE_PAIR_T), but I dont really know what type it is and it will nto let me look it up

0 Likes
1 Solution

I suggest looking at the AppNote explaining how to create a custom service (http://www.cypress.com/file/140826/download ).

   

the attribute handle is a constant thats created from your service definition, and follows the pattern CYBLE_SERVICENAME_CHARACTERISTICNAME_CHAR_HANDLE .

   

I cannot help with the receiving end since I never used that (my client was an Android device). But probably the 100 BLE example projects might help you further with that.

View solution in original post

0 Likes
11 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

I don't think you can easily the supplied BLE stack, which is handling this notification. Why don't you create your own customer service, its not that complicated...

0 Likes
Anonymous
Not applicable

Yes I was looking into that a little bit about the creating a custom profile/service, code is still a little confusing to me but im going to try to follow somewhat of a similar model to how the txpower profile looks, Thanks for input!

0 Likes
Anonymous
Not applicable

from what i am getting when using a custom service, when assigning the actual 16-bit adc value, it would go into the gatts handle as the command:

   

notificationhandle.value.val = &ADCVal;

   

 

   

where ADC value is the 16-bit ADC_GetResult16(CHANNEL);

   

I do have it set so notificationhandle.value.len = 2; as in two bytes of data (at least thats how i understand it)

   

however I am getting an error that says "incompatible pointer types assigning to uint8 from int16" So i am worried that when i test this out, it will not work, or it will not display the entire value (up to 2048). is there a reason that the value.val is always a uint8, or can that be changed?

0 Likes

Since 'notificationhandle.value.val' doesn't know anything about your data, it is just expecting a pointer to a byte array (which means uint8_t in C). Your ADCVal is probably an uint16_t, thats why the compiler complains aboutn incompatible bytes. You can just cast the pointer to uint8_t* and everything will be fine - this is just about the data format, not about the length.

   

(and on the receiving end, you need to do the reverse - you get a byte array and must parse it into a uint16)

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

If you could tell me if I have this correct:

   

On the peripheral side (The PSoC) that has a custom service char handle, the lines of code required to send it over to the dongle as notification would be as such:

   

                        uint16_t testval = 1234;

   

                        notificationhandle.attrHandle = customServiceCharHandle;
                        notificationhandle.value.len = 2;
                        notificationhandle.value.val = (uint8_t*) testval;
                        CyBle_GattsWriteAttributeValue(&notificationhandle, 0u, NULL, CYBLE_GATT_DB_LOCALLY_INITIATED);
                        CyBle_GattsNotification(cyBle_connHandle,&notificationhandle);

   

note on this part, it doesnt seem to recognize my custom handle, and gives a "use of undeclared identifier" error unless i declare it in main code with "CYBLE_GATT_DB_ATTR_HANDLE_T customServiceCharHandle;". I wasn't sure; would that be a problem? It is in the generated source BLE_Custom.h file, so that confuses me a little bit. I believe it would give a "customServiceCharhandle may be used uninitialized in this function" warning, which may be in part why value wont get sent. How would i fix this?

   

and on the receiving end of the stick (the dongle) to process the number that comes in and display it, would be something like:

   

<within the TPS Client Event handler (uint32 event, void *eventParam)>

   

 

   

    case CYBLE_EVT_TPSC_NOTIFICATION:
            CharValue=*(CYBLE_TPS_CHAR_VALUE_T*)eventParam;
            printf("Notification received. Value read:%d dBm\r\n",(int8)(CharValue.value->val[0]));
        break;

   

 

   

I do ensure that the device is connected and notifications are enabled, but I am guessing that there is something that has to be changed or I am missing something on the receiving end, in order for it to display "Value read: 1234" If the custom service handle is set and recognized correctly, what could be the reason for it not being able to read that value?

   

Another part wanted to add was this

   

typedef struct
{
    CYBLE_CONN_HANDLE_T         connHandle;             /* Connection handle */
    CYBLE_TPS_CHAR_INDEX_T      charIndex;              /* Characteristic index */
    CYBLE_GATT_VALUE_T          *value;                 /* Pointer */
} CYBLE_TPS_CHAR_VALUE_T;

   

 

   

And i thought, if i created a custom structure that would get only the testval, it could work, however I am having trouble understanding the charIndex. What would I need to utilize to get the value to send?

0 Likes

I suggest looking at the AppNote explaining how to create a custom service (http://www.cypress.com/file/140826/download ).

   

the attribute handle is a constant thats created from your service definition, and follows the pattern CYBLE_SERVICENAME_CHARACTERISTICNAME_CHAR_HANDLE .

   

I cannot help with the receiving end since I never used that (my client was an Android device). But probably the 100 BLE example projects might help you further with that.

0 Likes
Anonymous
Not applicable

Would it be perhaps that the client would need to have a custom service that matches that of the custom service handle in the peripheral server? 

Say the server is what has the 0 to 2048 number with its own handle/attribute. Would in turn, the receiver need to have a handle/attribute that matches that of the peripheral in order to recognize it?

0 Likes

Yes, of course the client needs to know the service that the BLE device is using. If the client is also a sPSoC BLE, the could copy over the BLE component to its project, and just swap the roles. Otherwise the cliebnt just needs to know the correct UUIDs for all services and characteristics.

0 Likes
Anonymous
Not applicable

ah alright now its starting to make sense. Going to give it a try and see if this works, thanks! Ill update as I continue developing programs

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

David You should look at 100 PROJECTS IN 100 Days Ble #005. I will attach the program. It uses an ADC and sends data to  CySmart and you can use any Cell Phone or the Dongle using the CYSmart Program. I am waiting for an answer from a Cypress engineer on the other forum issue  #020 example.

Anonymous
Not applicable

This looks like it will help a lot, thank you!

   

 

   

Part of what I have to do in the project as well though is going to have to graph the changing ADC through a terminal program. I have one written already though, which just takes in the number that comes in from the COM Port and graphs it versus time, so that is set.

   

 

   

It will be more so getting the PSoC to continuously sending the changing ADC value to the bluetooth dongle is issue. Thank you for getting this to me though! This will be useful. 

   

 

   

I may have more questions a bit later but still, looks like this should get me on about the right track.

0 Likes