How to send multiple data in one characteristic BLE

Hello

I am sending simple data from My Arduino Nano 33 BLE to RaspberryPi. I don't have any problems to send characteristic with data. One characteristic one value -> one variable.

According to the describtion of usage of BLE from Arduino BLE libary site I want to send many variables in one characteristic. How I can do that ?
Probably I have to send string data, but how i can do this ?

Someone of You do this before ? I will be gratefull for any help :smiley:

Text about which I talking:

Service design patterns

A characteristic value can be up to 512 bytes long. This is a key constraint in designing services. Given this limit, you should consider how best to store data about your sensors and actuators most effectively for your application. The simplest design pattern is to store one sensor or actuator value per characteristic, in ASCII encoded values.
Characteristic Value
Accelerometer X 200
Accelerometer Y 134
Accelerometer Z 150

This is also the most expensive in memory terms, and would take the longest to read. But it's the simplest for development and debugging.

You could also combine readings into a single characteristic, when a given sensor or actuator has multiple values associated with it.
Characteristic Value
Motor Speed, Direction 150,1
Accelerometer X, Y, Z 200,133,150

This is more efficient, but you need to be careful not to exceed the 512-byte limit. The accelerometer characteristic above, for example, takes 11 bytes as a ASCII-encoded string.

1 Like

Okay I found solution!

I will post it here at night or tomorrow. Maybe it will be helpful for someone.

mataldomen:
According to the describtion of usage of BLE from Arduino BLE libary site I want to send many variables in one characteristic. How I can do that ?
Probably I have to send string data, but how i can do this ?

In Bluetooth LE you do not send data like when you use a UART. Bluetooth LE has been designed much smarter.

You should look at it from a server client point of view. The BLE device that has the data is the server even though in many cases it is the device with much lower power. In BLE the client is the device that has many resources and intelligence.

So, you should design your BLE server device with a simple structure. One characteristic per value. Each characteristic is setup with Read and/or Write permissions.

The device can then decide which data it wants to read and at what interval. This allows for devices with different capabilities to just read the data it can process without ever changing the server device. For instance, if you have a temperature, humidity, barometric pressure sensor with three different characteristics. A low cost client that can just display temperature just reads that characteristics and a client that can display all three reads all three. It makes the software easier on all sides and save battery power on the server side.

I had the same problem. See solution: https://forum.arduino.cc/index.php?topic=660532.0