1 Reply Latest reply on Mar 5, 2016 2:57 AM by rohit.kumar

    Reading Values off of Peripherals/Servers

    dturney_1462731

      I'm working on a project, and having trouble wrapping my head around the APIs in the BLE datasheet.  Currently I have a hub device acting as both Peripheral and Central and another device that is just Peripheral.  They communicate in pairs, but the hub device can also communicate with other hub devices.  To pair those up, I manually put one in Slave/Client/Central, and the other in Master/Server/Peripheral.  From there the Slave scans, finds, then connects to Master.  From there the Slave needs 2 bytes from the Master, and after it receives them, disconnects, but I don't know which APIs would best be suited for that, since the Server can't CyBle_GattcWriteCharactisticValue.  Would I need CyBle_GattcReadCharacteristicValue or CyBle_GattsWriteAttributeValue?  Which APIs to which side of the communication would I use specifically?  

        • 1. Re: Reading Values off of Peripherals/Servers
          rohit.kumar

          As your Master is Server, there must be GATT database (services and characteristics) defined over which data needs to be communicated. What kind of property does the characteristic have over which you wish to read 2 bytes?

             

          If it is Read, then use 'CyBle_GattcReadCharacteristicValue' API. Parameters include the connHandle (which is cyBle_connHandle) and the 'CYBLE_GATTC_READ_REQ_T' type of read request.

             


          If it is notification, then you need to write 0x0001 to the associated Client Characteristic Configuration Descriptor (CCCD) of the server so that it can send you the data you want. For this, use 'CyBle_GattcWriteCharacteristicDescriptors' with parameter set to the attribute Handle of the CCCD. You will get a response over the event 'CYBLE_EVT_GATTC_HANDLE_VALUE_NTF'.

             

          Oce you receive the data, issue the disconnect using 'CyBle_GapDisconnect() '.
           

             

          On the Server side, if the characteristic has read property, then update the GATT database with the new 2 byte value using the API 'CyBle_GattsWriteAttributeValue'. Once the Client connects, it will read the updated data.

             

          If the property is notification, then wait for write command on the CCCD with value 0x0001. Once that is done, use the API 'CyBle_GattsNotification' to send data to the client when you have it ready.