6 Replies Latest reply on Jan 10, 2017 1:16 PM by user_459156114

    Sending data between two BLE devices

    user_459156114

      I working to send a simple Int between two BLE devices. I've been able to run the UART example in which one device is setup as a central and the other as peripheral. All works well there. This allows you to type in a serial window and it sends it to the other device. 

         

      What I'm trying to do now is a simple Int programmatically between the two devices. I am able to get the data back and forth however it always comes out weird on the device that I'm sending it to. 

         

      Here is how I send a piece of data from my peripheral device: 

         

      void Send_Event_Code_To_Sensor(int eventCode)
      {
          CYBLE_API_RESULT_T              bleApiResult;
          CYBLE_GATTS_HANDLE_VALUE_NTF_T     tempHandle5;
         
          tempHandle5.attrHandle = CYBLE_SERVER_UART_SERVER_UART_TX_DATA_CHAR_HANDLE;
          tempHandle5.value.val = (uint8*)eventCode;
          tempHandle5.value.len = sizeof(eventCode); 
          
           do
           {
              bleApiResult = CyBle_GattsNotification(cyBle_connHandle, &tempHandle5);
              CyBle_ProcessEvents();
           }
           while((CYBLE_ERROR_OK != bleApiResult)  && (CYBLE_STATE_CONNECTED == cyBle_state));
      }

         

       

         

      Here is how I receive it on the central device: 

         

      void HandleUartRxTraffic(CYBLE_GATTC_HANDLE_VALUE_NTF_PARAM_T *uartRxDataNotification)
      {
          if(uartRxDataNotification->handleValPair.attrHandle == txCharHandle)
          {
              unsigned int paramVal = *uartRxDataNotification->handleValPair.value.val;
          }
      }

         

      The problem is that when I receive the data it's always something weird. 

         

      For instance, if I try to send the number 1 from my peripheral like this: 

         

      Send_Event_Code_To_Sensor(1);

         

      It decodes as 64 on my central device. What am I doing wrong here? Is it because I'm sending it as a pointer here: 

         

      tempHandle5.value.val = (uint8*)eventCode;

         

      Maybe?