7 Replies Latest reply on Sep 4, 2016 5:30 AM by samay.salunke

    Send Temperature data from server to client through custom characteristic value

    dharmadhikari.neeraj1_1561511

      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);    
              
          }
      }