[Solved] Bluetooth LE Transmit Byte Array

A few questions about the “data (byte array)” option of the BLE transmit block:

1: What data type does it actually take (i.e. list, number, string, etc.)?
2: Why does it just instantly crash the Thunkable Live app whenever I attempt to transmit with it? Bearing in mind that the transmit string option works just fine.
3: Is the inability to transmit purely an issue with the Thunkable Live app (i.e. if I was to download and install the app on my phone, would it then work successfully)?

If it helps anyone, the phone I’m using is a Xiaomi Mi 9t Pro (Android) and my desired application is to send literally a single-byte value to a BLE module (again, if it helps, a RN4871 by Microchip). Ideally, I would want this value to be produced by a slider but honestly, I’ll take something that will actually work for now.

Thanks in advance for any input on this topic.

EDIT: It’s not just the Thunkable Live app.

1 Like

Hey @abrotzman4598f5a4 - welcome to the community!

  1. My assumption was a string, but I can follow up with the team an get a confirmation for you.
  2. Hard to say for sure without testing it out.
  3. I’d recommend doing this as a first step - can you try installing your app and let us know if that makes any difference.

Thanks.

First off, downloading and installing the compiled app made no difference to crashing.

I did, however, find a workaround for TRANSMITTING RAW HEX DATA. If you use the ‘transmit data (string)’ block but feed it a list with n items, setting each of these items to a number between 0 and 255 inclusive, you can send n bytes (or octets if you prefer) of raw hex data. This skirts the limitation of ASCII characters only covering 7 bits.

EDIT: In this example, this would send a single byte of value 0x03

hopefully, this can be of use to people in the future.

3 Likes

Thanks @abrotzman4598f5a4 for this fantastic solution, now I’m able to TRANSMIT RAW HEX DATA using BLE.
@domhnallohanlon please share this solution to the community.

Thanks for the great post - I can WRITE a byte to my hardware over BLE.

→ Now I need to READ a byte from the BLE - do you have any examples that work ?

edit 1: attached screenshots
edit 2: attached screenshot of the receiving blocks

@Paolo_Tealdi & @shawnmccazl thanks to this comment by @gaston_fabbietti I have also solved how to READ data over BLE - the answer is annoyingly self-explanatory: the characteristic has to be set up with the READ property and NOT the NOTIFY or INDICATE (which is usually the default).

As an example, I am (still) using the RN4871 module from Microchip - although the RN4870 is functionally identical for the purpose of this post. This module allows you to configure your own services with their own characteristics; however, it has a default service called “Device Information”. Within this, there is a characteristic (UUID: 00002A29-0000-1000-8000-00805F9B34FB) which contains the manufacturer string. As seen in the screenshot below, this string is “Microchip”. As also seen, this characteristic is READ ONLY (for comparison, there is a screenshot of a custom service that also has the “N” (notify) and “I” (indicate) properties).

Another screenshot shows the app correctly reading the manufacturer as “Microchip”. When trying to read from a characteristic with NOTIFY or INDICATE, however, the read fails because the client (your phone) has not subscribed to notifications… There is no way to do this currently with Thunkable?

So, in theory, if using the RN487x modules, you could create your own service with its own characteristics (and associated UUIDs) and make the property so that it’s READ ONLY. Then, by using the ‘LS’ & ‘SHW’ commands with the RN4871 (as described in the user guide on pages 45 & 51 respectively) you could program in your own data which can then be read by the app.

This is a very long post, I know, and probably very rambly, but hopefully it makes some degree of sense? I am also yet to test the whole ‘custom service’ part but will respond with more info when that is found… Also, this should probably be put into its own thread to help others… I will do this when I have a more concise explanation of the above information.

^ App correctly reading the manufacturer string with an empty error field (the “undefined” text)

^ The READ ONLY manufacturer string as shown in the BLE Scanner app, note there is only the “R” 'dot’

^The NOTIFY/INDICATE characteristic, note the additional “N” & “I” 'dots’

^ The blocks used for READing the (READ ONLY) manufacturer string, pretty simple really

1 Like

Do you know how to read data from a Bluetooth iBeacon? How to read their UUID, Major, Minor data?

No idea, I have no Apple devices. I have, however, given all the information you need to check whether it is possible (i.e. whether the characteristic is read-only or not). I suggest you download an app like BLE Scanner, or perhaps LightBlue, and find out what properties the characteristics of your devices have. You would be looking for any characteristics that have a property of hex value 0x02 (or that only show the ‘read’ property).

May I also suggest that future questions relating to READING are started in a new thread? I will probably create this later today to give a more concise overview of all the information in this thread.

1 Like

edit 1: attached further screenshots for clarity.

In reply to my own theory about creating a custom service that is READ ONLY, I can confirm that this does work, as shown by the two screenshots below (I have updated my test app’s UI, but the blocks used to receive data are identical to those shown in my previous post.

^ Screenshot of the commands sent to the RN4871, and its responses. This shows key info such as the characteristic UUID (for the app to read) and the characteristic handle (for the MCU/serial terminal to write data to, so that it can be read by the app). Note the long string of numbers after the ‘SHW’ command, is the string of “Hello, World!” written out in ASCII (i.e. 48 = ‘H’, 65 = ‘e’ etc. etc.

^ The app after having successfully received the string that was written out in the above screenshot. Note that the characteristic UUID NEEDS to have those dashes IN THE EXACT SAME PLACE every time (8-4-4-4-12 characters). If the dashes are not present, the app fails to read the string since it can’t find the UUID (although it just throws the generic error message).

I have not yet tried extracting the data as a byte array, although if I was to try and implement it I would use the “Make list from text with delimitter” block and format the data on the MCU side as a simple CSV array. See the example screenshots below for more clarity.

^ Blocks used for creating a list of ‘hex pairs’ or numbers or whatever (further conversion may be required after this).

Screenshot_20210811-115632

^ Dummy Arduino code for creating a CSV list

Note that these last two screenshots are UNTESTED.

1 Like