BLE read more than one characteristic values

bluetooth

#1

I’m playing around with Thunkable and its bluetooth extension. I followed this tutorial on hackster.io that connects a thunkable app with ESP32 board.

The TX an RX characteristics work as expected but I couldn’t make the app read more than just RX characteristic.

As I understand the RegisterForStrings block, tells the app to wait for a characteristic value
and when it gets one the event StringsReceived is fired.

What I have working now is the following:

I receive TEMP_CHAR_UUID value and show it in a label.

Now to my question. How to get more than one characteristic value? I need to Register another characteristic HUMID_CHAR_UUID and set a Label with that characteristic value:
image


#2

Hi there! Glad you found my app useful. To send multiple values I would simply put them in a comma-separated variable (CSV) format. For example, if you want to send both temperature (21 *C) and humidity (52%) from your ESP32 you can simply put them together and send “21,52” and parse it on the app side. Same goes in the other direction from the app to the ESP32.

If you have a lot of data it might also be worth using a delimiter like “*” or “!” or something unique. You can either put this at the start or at the end of each message as long as you’re consistent and the app or ESP32 can check for this delimiter and see if it’s a command, sensor data, or some other type of data.

Just don’t exceed 20 bytes of data because that’s the max amount BLE can support in a single packet! Anything more than that will need to be split up. This is also where the delimiter can be very handy, because it can mark the end of a multiple transmits that would have been a single packet.

Hope that helps!


#3

Cool! Didn’t think of CSV format.

I will try that out. Thanks!


#4

Now it’s looking good. It worked separating the values with a comma. Now I can display both temperature and humidity.

If anyone interested here is the .aia file.
ESP32_BLE_DHT112_0 (1).aia (257.6 KB)


#5

Hey, :slight_smile:

I’m trying something similar.
But I have some trouble with setting my values in the CSV format in Arduino IDE.
Could you maybe share you Arduino file as well?


#7

Sure! I can share my code with you.

I basically did like the following:

humidity = dht.readHumidity();
temperature = dht.readTemperature();   

char humidityString[2];
char temperatureString[2];
dtostrf(humidity, 1, 2, humidityString);
dtostrf(temperature, 1, 2, temperatureString);

char dhtDataString[16];
sprintf(dhtDataString, "%d,%d", temperature, humidity);

pCharacteristic->setValue(dhtDataString);

pCharacteristic->notify(); // Send value to the app

I basically used sprintf to format both values with a comma between them. Like this “23,80” (%d,%d)

I’m not sure if this is the right way to do this but it worked for me.

Here is the GitHub with full code; https://github.com/filipeflop/esp32-ble-dht11


#8

Hey, do you know how to make a slider to control a RGB LED? or to make a PWM Singal with the slider to fade a normal led?
im a noob im trying for months now to do this
thank you^^


#9

I really think you may be on to something here. I am trying to understand the BLE properties and am trying to create an app that reads multiple analog values (which you’ve accomplished and I have to understand), send multiple analog values to the ESP32 (like settings for a app controlled PWM signal or set point), read multiple digital values from the ESP32 (like simple push button conditions), and send digital conditions to the ESP32 (which you’ve accomplished). I work in the water filtration industry and use HMI software and PLC software where it’s more graphic driven then programming driven. For me it’s easier to understand. Here I am trying to understand what lies underneath the graphics lol. Thank you.


#10

I’m getting a error whenever I try to compile this code using Arduino IDE.I have installed all the required packages . When I try to run your code I’m getting a error “Error compiling for board ESP32 DEV module”. BUT IF I RUN THE CODE PROVIDED BY INSTRUCTABLES SITE… THERE IS NO ERROR.Why? . THANKS IN ADVANCE


#11

I like your app but am unable to export the APK file - have you been able to?

I get compilation errors which appear to be connected to the BLE extension