4 Replies Latest reply on Dec 8, 2016 10:12 AM by JaDa_1584736

    Send string value from iOS app to BLE (pioneer kit)

      (disclosure: I followed the capsense tutorial to get my original code working)




      I'm able to successfully send single int values from my app to the BLE device. This is easy enough taken from the example code: 




          func writeLedCharacteristic(var val: Int8) {


              let ns = NSData(bytes: &val, length: sizeof(Int8))
              capsenseLedBoard!.writeValue(ns, forCharacteristic: ledCharacteristic, type: CBCharacteristicWriteType.WithResponse)


      I updated my BLE custom profile for the led characteristic so that it now looks like this (see Download IMG_0327.jpg): 


      Really only changed the type to uint16 so that it would accept more characters. My rational here was that the capsense characteristic needed to be of type uint16 since more than a single bit was going through. If you can't tell already I'm extremely new to this. 


      Next I updated my iOS code to try and send the data like this: 




              let string = "hello"


              let bytes: [UInt8] = Array(string.utf8)


              let data = NSData(bytes: bytes, length: bytes.count)


              capsenseLedBoard!.writeValue(data, forCharacteristic: ledCharacteristic, type: CBCharacteristicWriteType.WithResponse)




      I have updated my PSoC code to look like this: 




                      /* only update the value and write the response if the requested write is allowed */


                      if(CYBLE_GATT_ERR_NONE == CyBle_GattsWriteAttributeValue(&wrReqParam->handleValPair, 0, &cyBle_connHandle, CYBLE_GATT_DB_PEER_INITIATED))




                          UART_UartPutString("did get write request LED");


                          char t = wrReqParam->handleValPair.value.val[0];














      When I run and test my code I don't even get acknowledgement that the iOS device sent anything..aka this is never spit out in HyperTerminal: 


      UART_UartPutString("did get write request LED");




      My initial thought was that I was encoding was wrong so tried changing the led Custom Characteristic type to uint8 how that is still not working! 


      The other issue is that from what I can tell I should be getting a char array from this line handleValPair.value.val[0] in PSoC however I'm not sure how exactly to extract that into an array. 


      Again, I'm extremely new to this lower level stuff, my C is amateur at best. Any help is very much appreciated!!