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

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

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

(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];

   

                    CyBle_GattsWriteRsp(cyBle_connHandle);

   

                    UART_UartPutChar(t);

   

                    //red_Write(!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!! 

0 Likes
1 Solution
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Have you tried our 100 projects in 100 days Ble? you may find some examples there that do what you need. Also for more training look at the video training examples on this site. Post your project so we can check it.

View solution in original post

0 Likes
4 Replies
Anonymous
Not applicable

Shameless bump 😞 

0 Likes
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Have you tried our 100 projects in 100 days Ble? you may find some examples there that do what you need. Also for more training look at the video training examples on this site. Post your project so we can check it.

0 Likes
Anonymous
Not applicable

I appreciate your response! I've looked through a bunch of them and see nothing about sending a string from smartphone to the ble device. Perhaps I missed it? 

0 Likes
JaDa_1584736
Level 1
Level 1
First like received

handleValPair.value.val[0]  is just the bit used to turn on or off the LED.  

0 Likes