# Sending a string over bluetooth

**URL:** <https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921>\
**Category:** 101\
**Created:** [January 16, 2016, 10:40am UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921 "2016-01-16T10:40:54Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sifha03](https://avatars.discourse-cdn.com/v4/letter/s/3da27b/32.png) [@sifha03](https://forum.arduino.cc/u/sifha03)\
**Post date:** [January 16, 2016, 10:40am UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/1 "2016-01-16T10:40:54Z")

</div>

How do I send a string using Bluetooth? I used ble101char.setValue(0x02) to send 1 value and used the same function multiple times with different values to send a string but it is too slow.

I looked at BLECharacteristics.cpp and found  
BLECharacteristic::setValue(const unsigned char value[], uint16\_t length).

When I tried it an error occurred.  
bleTest:37: error: no matching function for call to 'BLECharCharacteristic::setValue(char [4], int)'  
ble101char.setValue(dataStream,4);

The rest of my code is below. I want to know how to send a string using Bluetooth

```cpp
#include <CurieBle.h>

BLEPeripheral ble101;
BLEService ble101Service("0BD51666-E7CB-469B-8E4D-2742F1BA77DD");
BLECharCharacteristic ble101char ("E7ADD780-B042-4876-AAE1-112855353CC1", BLEWrite | BLEIndicate);
char dataStream[] = {0x02,0x43,0x21,0x90};

void setup() {
  Serial.begin(9600);  
  ble101.setLocalName("ble101");
  ble101.setDeviceName("ble101");
  ble101.setAdvertisedServiceUuid(ble101Service.uuid());
  ble101.addAttribute(ble101Service);
  ble101.addAttribute(ble101char);
  ble101char.setValue(0);
  ble101.begin();
}

void loop() {  
  BLECentral central = ble101.central();

  if (central)
  {
    Serial.print("Connected to central: ");    
    Serial.println(central.address());

    while (central.connected()) 
    {      
    ble101char.setValue(dataStream,4);      
    }

    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());    
  }
}

```

---

<div class="post-metadata">

**Author:** ![dekduino](https://avatars.discourse-cdn.com/v4/letter/d/a587f6/32.png) [@dekduino](https://forum.arduino.cc/u/dekduino)\
**Post date:** [January 16, 2016, 2:38pm UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/2 "2016-01-16T14:38:24Z")

</div>

I just figured this out last night. Use the base class, BLECharacteristic. You can provide an initial string value via the constructor (although oddly, only takes a char \*, not a char \* and length), and then use .setValue(char \*, int len) to provide a string afterwards. Note that because this is binary data, you need to know the length of the string rather than expecting it to be zero-terminated.

---

<div class="post-metadata">

**Author:** ![matiasjaure](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/matiasjaure/32/1180746_2.png) [@matiasjaure](https://forum.arduino.cc/u/matiasjaure)\
**Post date:** [January 19, 2016, 11:09am UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/3 "2016-01-19T11:09:22Z")

</div>

Hello Guys, Do you know how to receive and convert a float from bluetooth? I'm trying on C# and can't make it work.

---

<div class="post-metadata">

**Author:** ![zwyber](https://avatars.discourse-cdn.com/v4/letter/z/9fc348/32.png) [@zwyber](https://forum.arduino.cc/u/zwyber)\
**Post date:** [January 19, 2016, 5:10pm UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/4 "2016-01-19T17:10:52Z")

</div>

Hi dekduino, does that mean you have managed to send a string over bluetooth? If possible, could you post the code you used for the arduino and whatever program you use for the receiving bluetooth side?

---

<div class="post-metadata">

**Author:** ![matiasjaure](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/matiasjaure/32/1180746_2.png) [@matiasjaure](https://forum.arduino.cc/u/matiasjaure)\
**Post date:** [January 20, 2016, 11:12am UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/5 "2016-01-20T11:12:23Z")

</div>

> zwyber:  
> Hi dekduino, does that mean you have managed to send a string over bluetooth? If possible, could you post the code you used for the arduino and whatever program you use for the receiving bluetooth side?

I used this on Arduino side:

Code: [Select]

char buff[10];  
String gyroString = "";  
dtostrf(yaw, 4, 2, buff); //4 is mininum width, 2 is precision  
gyroString += buff;  
gyroString += ", ";  
dtostrf(roll, 4, 2, buff);  
gyroString += buff;  
gyroString += ", ";  
dtostrf(pitch, 4, 2, buff);  
gyroString += buff;

char b[20] ;  
gyroString.toCharArray(b, 20);  
yawCharacteristic.setValue((unsigned char\*)b,20);

and then in c# you just parsed it like this on the notification event:

string gyro = System.Text.Encoding.UTF8.GetString(data);

---

<div class="post-metadata">

**Author:** ![amarie](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@amarie](https://forum.arduino.cc/u/amarie)\
**Post date:** [June 8, 2016, 8:24am UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/6 "2016-06-08T08:24:55Z")

</div>

Hi matiasjaure,  
Did you ever manage to build a C# client to connect via BLE and receive data? would you have any code snippet in c#? It's been really hard to find a good example!

Thanks!

---

<div class="post-metadata">

**Author:** ![timontunes](https://avatars.discourse-cdn.com/v4/letter/t/dc4da7/32.png) [@timontunes](https://forum.arduino.cc/u/timontunes)\
**Post date:** [October 27, 2018, 6:48pm UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/7 "2018-10-27T18:48:56Z")

</div>

> amarie:  
> Hi matiasjaure,  
> Did you ever manage to build a C# client to connect via BLE and receive data? would you have any code snippet in c#? It's been really hard to find a good example!
> 
> Thanks!

Hi Amarie, did you develop a C# app to connect via BLE and receive data?  
I am trying to do that now.

Thank you,  
Tim

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 6:03pm UTC](https://forum.arduino.cc/t/sending-a-string-over-bluetooth/358921/8 "2021-05-06T18:03:48Z")

</div>

Closed on May 6, 2021, 6:03pm UTC


