Bluetooth Low Energy Transmits but does not Receive

BLE receive is working!

If anyone is using the standard ESP32 libraries on Arduino IDE or the BLE DEMO instructable written for Thunkable Classic the key is to add property_read to the BLECharectoristics.

See in between ** ** bellow. Was working immediately!

Off a standard timer on Thunkable. Admittedly the BLE receive should probably be an event block

pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY**|BLECharacteristic::PROPERTY_READ**
);

Kind Regards Rich

2 Likes

That’s great! I’m trying to get a reading from a BLE temperature probe thermometer. I don’t know programming, so I’m not sure where the stuff between the ** ** goes in the blocks. Can you explain a little to someone like me?? :slight_smile:

Any help is greatly appreciated!!

Hi Pittsgsal,

This code (The bits between ** **) is for an Espressif esp32 (Like an arduino). It was a way for the Arduino to speak/communicate with thunkable.

This will not help you much with your Bluetooth Thermocouple I am afraid.

You could get temperature sensor for an arduino or esp32 and use the BLE Arduino template and the above extra snippet to transmit the information to thunkable.

Here a common sensors, most also have code ready to go so should only be a bit of studying and copy and paste to get it to work

Cheers Rich

Cheers, Rich!

I’m really at a loss as to how to get this working, as I have an API that explains it, but I just don’t have the skills to get the correct info in the blocks, or to even enter something extra that need to be in there to make it work. It supposedly will act like a GATT Server. All the Characteristic numbers are in the doc, and I set Global variables. I’m attaching a pic of the “meat” of the API in case you can magically think of a way to get a temperature from it… :slight_smile:

Looks like you just need to get the UUID, write that to the string outside the above code block and see what data you get and look for the float between byte 2 and 5.

If the documentation doesn’t specify the UUID Google how to find low energy Bluetooth UUID from Charectoristic. Might be easier to connect to it via a laptop find it that way.

You obviously need to connect when the page opens and all that… excuse the screen shots just on phone.

I can absolutely connect with no issues. Works great!
The issue comes when I’m looking for a reading from the thermometer. I try to show it in a Label, but it won’t show a temp. I assume that it doesn’t KNOW that it’s Little Endian, and can’t figure out what to do with the gibberish it gets.

You have done all the work already! You may be stuck if you cannot change the device property from notify to read. Its will show as undefined. If you have an old thunkable classic account you can do it easily there.

I guess you might need program it properly not blockely or down a more DIY route with an arduino and sensors. Give you plenty of options too.

If you by some remote chance figure a way. I know the community will be keen to know.

Good luck!

Thanks for the help, Rich! I’m going to keep trying!! Maybe I can figure a way to get an old account… lol!

Mike

But if you CAN get read the bytes into text (even if its HEX or ascii) you can use the text code blocks to extract the bytes and convert them.

Using length blocks, Trim then if HEX = hex hex = ascii equivalent

Then use math boxes to add them the right order and store them to a variable then to a label.

@pittsgal That Temperature Measurement appears to be in hexadecimal. I used an online converter to convert 0x2A1C to decimal and got 10780. Perhaps you tried that, too. I knew we could ignore the 0x after reading the article I link to below but I wasn’t sure about the rest of the value.

So it seems we need some more information about the type of value that is being output as temperature.

And there is some in the information you posted (I tried to find the API documentation you mentioned but couldn’t. Is it available online?).

“Byte 1 contains the flag field.” This helps us know if the temperature is in °C or °F but it doesn’t affect the actual value of the temperature.

According to the article below, each hexadecimal digit maps to 4 bits (4 binary digits). A byte is eight binary digits or two hexadecimal digits. So Byte 1 consists of the first two hexadecimal digits, “1C.” So we can ignore those for now.

“Byte 2 to 5 is a 4 byte float representing the temperature reading…” Now we’re getting somewhere!

If we take Byte 2 to 5 as a single value, we need to evaluate “2A.” Because that’s all that remains after we remove the 0x prefix and Byte 1 “1C.”

And 2A in hexadecimal converts to 42 in decimal. So the answer is 42 degrees! Woo hoo! But wait, is that 42°F or 42°C? Probably if you’re measuring the temperature at home with the physical device, you already know the answer. But if you need help with parsing the value from Byte 1, I could take a crack at that, too.

Mind you, I just figured this out and I’ve never worked with hexadecimal. So even though I feel pretty good about the chances that 42° is correct, you might want someone else to double-check my assumptions.

I found this useful: Hexadecimal - learn.sparkfun.com, especially the part titled " Hex-to-Decimal Example: Convert 0xC0DE" and the couple of sections below that. Also, I had to read this to understand that in “little endian,” bytes are read from right to left: Is binary code read from right to left? - Quora.

Edit: I can’t leave well enough alone when it comes to learning more about coding! Byte 1’s value of 1C in hexadecimal equals 00011100 in binary. That’s eight bits: 0, 0, 0, 1, 1, 1, 0, and 0. According to what you posted above, “Bit 0 [is the] Temperature scale.” So if we look at bit 0, the value is 0 – I’m pretty sure that’s the right-most value. So this temperature is in Celsius (a value of 1 would indicate Fahrenheit). I hope I’m right! :smiley:

To contextualize, I’m going to say you’re probably measuring some nice hot tub water at about 108 °F.

Screen Shot 2020-11-12 at 4.55.43 PM download download

2 Likes

Confirmed, working.
Check this post

2 Likes

i can confirm that adding the property PROPERTY_READ ble is working both ways on esp32 and iphone 12 pro max ios 14.3
tks!

That’s great! How did you add the “PROPERTY_READ” to your app??? I’m clearly not as educated as you guys are!

Thanks!

Hi there, any update about this issue? Thanks

Hi, any one can help to share a sample of data string receiving with BLE?
Thanks