# Receive Numerics with BLE

**URL:** https://community.thunkable.com/t/receive-numerics-with-ble/1277173
**Category:** Questions about Thunkable X
**Created:** [May 11, 2021, 9:29pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173 "2021-05-11T21:29:06Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![thunkablest5dru](https://avatars.discourse-cdn.com/v4/letter/t/97f17d/32.png) [@thunkablest5dru](https://community.thunkable.com/u/thunkablest5dru)
#### Post date: [May 11, 2021, 9:29pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/1 "2021-05-11T21:29:06Z")

</div>

I can receive text with the BLE receive String function but can’t receive any numeric data.

If I try to read it with receive byte array it fails with “**n is not a function. (In ‘n(void 0,f.t0.message)’,‘n’ is undefined)**”

Does anyone know what format the receive byteArray function actually requires as input and is there a way to receive numerics? I’d rather not have to convert all my numbers to strings before sending them.

---

<div class="post-metadata">

### Author: ![davew3q](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@davew3q](https://community.thunkable.com/u/davew3q)
#### Post date: [April 11, 2022, 3:03am UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/2 "2022-04-11T03:03:09Z")

</div>

Hi - I’m having the same problem, the “Receive Byte” array fails for me, and I can only receive a string. How do I convert it to the list of integers received from reading the BLE GATT?

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/a/fa7630730f8cdc1d87701b7a9023354c8f5f7af9.png)

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [April 11, 2022, 3:15am UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/3 "2022-04-11T03:15:58Z")

</div>

Oops, edited this post. I was asking about the string you’re able to get and what list of integers you need from it.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [April 11, 2022, 7:36am UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/4 "2022-04-11T07:36:27Z")

</div>

The `call BLE receive block` has a green block named `data (string)` which indicates that you will be receiving **text** from the sending BLE device. It is just a simple text like `Hello world` and then you can treat this text any way you would like.

---

<div class="post-metadata">

### Author: ![davew3q](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@davew3q](https://community.thunkable.com/u/davew3q)
#### Post date: [April 11, 2022, 12:45pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/5 "2022-04-11T12:45:08Z")

</div>

Yes, I’m communicating with a BLE toy ([www.heykube.com](http://www.heykube.com)), and this GATT characteristic can report the current battery voltage and charging status. It’s 2 bytes long.

uint8\_t data[2];

voltage\_int = data[0] | (data[1] & 0xf) \<\< 8);  
voltage = voltage\_int / 512.0  
charging = data[1] \>\> 4;

I would expect to receive bytes, [0x0, 0x18] to report that it’s at 4.0 volts and charging (since 0x800 / 512.0 = 4.0) and bit 12 is a 1.

- Using the Receive Byte Array version crashes the app, so I can only get the Receive String version to do something
- On the Transmit String, I can use a list of integers and it works to send the correct bytes
- I was hoping you can just extract the bytes from the string, but it’s not working yet.

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [April 11, 2022, 4:00pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/6 "2022-04-11T16:00:11Z")

</div>

I guess this is a bit over my head. I’m familiar with the idea of parsing bytes from a string but… what is the **exact string** that you’re able to get in Thunkable?

---

<div class="post-metadata">

### Author: ![davew3q](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@davew3q](https://community.thunkable.com/u/davew3q)
#### Post date: [April 13, 2022, 3:23am UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/7 "2022-04-13T03:23:22Z")

</div>

Unfortunately, I get an unreadable string, since it’s just raw HEX data.

Here is the crux of the problem, how can I convert “A” into the integer 65 (from the ASCII table). See this code here, trying to add 0 to the “A” results in NaN on the screen. In C, the equivalent is the atoi() function.

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/1/f/1fc839a9d18e5e30079c0bb4d488548537d2146a.png)

---

<div class="post-metadata">

### Author: ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)
#### Post date: [April 13, 2022, 4:57am UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/8 "2022-04-13T04:57:27Z")

</div>

When you say “unreadable”… what is the exact Hex you are seeing?

I spent some time learning to parse hex codes here:

> [@A brick wall that i've smacked into with hex codes](https://community.thunkable.com/t/a-brick-wall-that-ive-smacked-into-with-hex-codes/1068428/13):
>
> Right but you’re not getting 0x0FA0 from a physical device/sensor, are you? You’re getting a value like 41 0C 0F A0, right, according to the updated “Reading Real-Time Data” link you posted? Just trying to understand the starting and ending points. Because if you have a device that gives you 0x0FA0, that’s going to be a different set of steps in Thunkable compared to the steps you’d need if you’re given 41 0C 0F A0. By the way, the 0x0FA0 is just the last four digits of 41 0C 0F A0. If you join…

But as far as your question about converting letter to integers, I’m not sure how to do that. I doubt it’s difficult but I’m not at my computer so I can’t work on a demo at the moment.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [April 13, 2022, 8:46am UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/9 "2022-04-13T08:46:24Z")

</div>

To convert HEX to decimal you need to create two lists; one for all hex numerals and a corresponding decimal list or you can create only the alphanumeric part of the hexadecimal numerals.

You would need to read the received string character by character and compare it to the hex list and take the corresponding decimal value to calculate.

See this example of converting hex colors to RGB

[https://x.thunkable.com/projectPage/61742edbc7e59500107319d4](https://x.thunkable.com/projectPage/61742edbc7e59500107319d4)

> [@davew3q](#):
>
> trying to add 0 to the “A” results in NaN on the screen

NaN means **Not a Number** which is of course it is because **A** is not a digit. However if you want the **A** to just display as **0A** then you should do

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/4/5/4554edf6f42b6952e42300e2a4d64ce08ba049ad.png)

Which will display **0A** in the `Label`.

---

<div class="post-metadata">

### Author: ![davew3q](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@davew3q](https://community.thunkable.com/u/davew3q)
#### Post date: [April 13, 2022, 12:03pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/10 "2022-04-13T12:03:56Z")

</div>

Sorry, it’s a little more low level then this. Normally a BLE read on returns a byte array.

`uint8_t rx_bytes[MAX_PACKET];`

- For me, using the BLE “Receive Byte Array” returns an error
- My current workaround is to try to use the Receive String, and we see if we can extract the bytes. The idea is that ASCII characters, numbers between 0-255. If I receive “Z”, it maps to an integer 90, if I receive a “/” it maps

It sounds like this is not the right approach, I should just debug why Receive Byte array doesn’t work.

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [April 13, 2022, 1:25pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/11 "2022-04-13T13:25:18Z")

</div>

I know what is a byte array and in Thunkable you can use JavaScript to get this. Not easy but you can.

See my demo of how to run JavaScript code in Thunkable.  
[https://x.thunkable.com/projectPage/621c9b6c73ba2500119d10ef](https://x.thunkable.com/projectPage/621c9b6c73ba2500119d10ef)

If you enter the following \*"/".charCodeAt(0)  
You should get **47**

![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/e/e/ee70bc9f869e0723512dadd53beca3d397d27663.png)

If you need to convert the number back to a character then use `String.fromCharCode(90)` which should gives you **Z**.

Of course you can build your own code and run it using the `Web Viewer` but you can start with this to test your output.

---

<div class="post-metadata">

### Author: ![davew3q](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@davew3q](https://community.thunkable.com/u/davew3q)
#### Post date: [April 13, 2022, 2:39pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/12 "2022-04-13T14:39:44Z")

</div>

Very cool, I like the idea of the web-browser posted messages to get Javascript to execute. It’s a pretty cool expert mode function, that I will take advantage of!

For this specific case, I think I should just wait on the Debug for the “Receive Byte Array”, instead of pursing the ASCII parsing.

[https://community.thunkable.com/t/why-does-ble-receive-string-work-and-ble-receive-byte-array-not-work/1831529](https://community.thunkable.com/t/why-does-ble-receive-string-work-and-ble-receive-byte-array-not-work/1831529)

---

<div class="post-metadata">

### Author: ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)
#### Post date: [April 13, 2022, 7:12pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/13 "2022-04-13T19:12:36Z")

</div>

I like to extend the available functions with `JavaScript`.

See this demo for choosing an image file from your local drive and view it in the screen. Of course, you can choose to save it to Firebase and then use it in your app.

[https://x.thunkable.com/projectPage/61f68431c3761001dba12df1](https://x.thunkable.com/projectPage/61f68431c3761001dba12df1)

---

<div class="post-metadata">

### Author: ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)
#### Post date: [November 8, 2024, 1:22pm UTC](https://community.thunkable.com/t/receive-numerics-with-ble/1277173/14 "2024-11-08T13:22:34Z")

</div>


