Send Temperature data from server to client through custom characteristic value

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

cross mob
Anonymous
Not applicable

Hello,
I am using PSoC4 Ble as a server to send temperature data to client. I have created custom profile in which one service has been created and characteristic for the temperature. I have used Cyble_GattsWriteAttributeValue() to write the values to the gatt database. But it's not working.  I have tested this on Windows CySmart application. I could connect to the psoc module, but i was unable to discover the attributes . 

   

Can anyone please suggest any corrections to be made in this code? 

   

Thank you in advance.
-Neeraj

   

void Stack_Handler(uint32 eventCode, void *event_Param)
{
    switch(eventCode)
    {
        case CYBLE_EVT_STACK_ON:
        case CYBLE_EVT_GAP_DEVICE_DISCONNECTED:
            CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST);
            break;             
        case CYBLE_EVT_GATT_CONNECT_IND:
            cyBle_connHandle = *(CYBLE_CONN_HANDLE_T *)event_Param ;
            break;
    }
}

   

void updateGattData(uint8 temp, uint16 attrH)
{   
    CYBLE_GATT_HANDLE_VALUE_PAIR_T *envdata;
    CYBLE_GATT_ERR_CODE_T result;
    envdata->attrHandle = attrH;
    envdata->value.val = &temp;
    envdata->value.len= 2;
    envdata->value.actualLen=2;
    result = CyBle_GattsWriteAttributeValue(envdata,0,&cyBle_connHandle,CYBLE_GATT_DB_LOCALLY_INITIATED);
}

   

int main()
{  
    int16 temp1, temp2,temp1_mV,temp2_mV, hum, hum_mV;
    uint8 temperature;
    CyGlobalIntEnable; /* Enable global interrupts. */
    CyBle_Start(Stack_Handler);
    ADC_SAR_Seq_1_Start();
    ADC_SAR_Seq_1_StartConvert();
   
    for(;;)
    {
        if( ADC_SAR_Seq_1_IsEndConversion(ADC_SAR_Seq_1_WAIT_FOR_RESULT))
        {    
            temp1 =ADC_SAR_Seq_1_GetResult16(0);
            temp2 =ADC_SAR_Seq_1_GetResult16(1);
            hum = ADC_SAR_Seq_1_GetResult16(2);
            
            temp1_mV = ADC_SAR_Seq_1_CountsTo_mVolts(0,temp1);
            temp2_mV = ADC_SAR_Seq_1_CountsTo_mVolts(1,temp2);
            hum_mV = ADC_SAR_Seq_1_CountsTo_mVolts(2,hum);
            temperature= (temp1_mV - temp2_mV);     
        } 
        CyBle_ProcessEvents();
        CyDelay(500);
        updateGattData(temperature,CYBLE_ENVSENSING_TEMPERATURE_CHAR_HANDLE);    
        
    }
}

0 Likes
1 Solution
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

You need to write the attribute - I think the notification just tells the GATT client that a new value is available, without sending the value with it.

View solution in original post

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

When you cannot discover the attributes, either you have set up the BLE profile the wrong way, or your client is doing something wrong. Are you using CySmart as GATT client?

   

(Note that writing to the attribute doesn't push the changes to the client automatically)

0 Likes
Anonymous
Not applicable

Okay.. Thank you.
As per your advice, i tried to push notifications to the client using Cyble_GattsNotification(). It worked properly. I can discover all the attributes and read the characteristics value on Cysmart windows application.
But writing to the attributes is not working . I think sending the data using notifications would be sufficient . Is it required to write the data values to the gatt database? 
I will try to combine both these things and check if it works or not.
Thank you very much.
-Neeraj

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

You need to write the attribute - I think the notification just tells the GATT client that a new value is available, without sending the value with it.

0 Likes
Anonymous
Not applicable

Thanks a lot. 
I have completed writing the attribute values into the gatt database and notifying the client with the notifications.
Both these things are working satisfactorily.
Thanks for your help.
-Neeraj

0 Likes
Anonymous
Not applicable
        Hey, Can you also tell me what are the configurations for your Cyschematic? What was your custom profile?   
0 Likes
Anonymous
Not applicable

I created a custom profile which contained my custom service along with the GAP and GATT service (Total 3 services). I created two custom characteristics : one for temperature and other for the humidity. 

0 Likes
Anonymous
Not applicable

Am I supposed to use a UART in schematic to send data to cysmart from psoc board? It would be helpful if you could forward me the project.

   

Thank You

0 Likes