# Bluetooth connection times out

**URL:** <https://discourse.processing.org/t/bluetooth-connection-times-out/35146>\
**Category:** Processing for Android\
**Created:** [February 13, 2022, 1:36pm UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146 "2022-02-13T13:36:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![un23](https://avatars.discourse-cdn.com/v4/letter/u/53a042/32.png) [@un23](https://discourse.processing.org/u/un23)\
**Post date:** [February 13, 2022, 1:36pm UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/1 "2022-02-13T13:36:02Z")

</div>

Hello,

I am trying to connect my tablet to a BT05 Bluetooth serial adapter. The Android version is 5.1, but I also tested a newer device with the same result. I used “Serial Bluetooth Terminal” to connect to the same adapter and it works fine there, so I guess the hardware should be ok.

I have tried several examples I found online, one using ketai and two working with android directly, the behaviour is always the same:

I can scan for devices, I see paired and discovered devices and mac addresses. When I try to connect,  
the device gets a connection, the serial side of the adapter says “Connected”, but no data is going through the link in either direction. About 12 seconds later, the connection breaks, the console gives me  
“java.io.IOException: read failed, socket might closed or timeout, read ret: -1”.  
I have added every permission that has Bluetooth in it, but it makes no difference.

Does anyone have a hint what could be the reason for this or what I could try?

Thanks a lot  
un23

---

<div class="post-metadata">

**Author:** ![un23](https://avatars.discourse-cdn.com/v4/letter/u/53a042/32.png) [@un23](https://discourse.processing.org/u/un23)\
**Post date:** [February 25, 2022, 3:41pm UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/2 "2022-02-25T15:41:29Z")

</div>

Hello,

I did some more research in the last days and found that my devices (BT05) are actually Bluetooth Low Energy devices and need a completely different method to connect to them. It is described in detail [here](https://punchthrough.com/android-ble-guide/), and ketai does not seem to support it at the moment.

Regards  
un23

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [February 26, 2022, 12:22am UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/3 "2022-02-26T00:22:37Z")

</div>

Hi

The (BT05) module works fine with ketai library  
Search here for @noel posts and topics he posted multi working examples

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [February 26, 2022, 12:26am UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/4 "2022-02-26T00:26:23Z")

</div>

This example without library

> [@Android Bluetooth](https://discourse.processing.org/t/android-bluetooth/27140):
>
> The Ketai Bluetooth Class method onBluetoothDataEvent() does not work on the latest Android modes. Also, it has no readStringUntil() method which makes it difficult to read fast incoming data. So I wrote a native Android Bluetooth code to make this possible. I tested it on a MultiLaser Lollipop 5.1 device, as well as on a Samsung Android 10, using an HC-05 module set to a baud rate of 115200, without losing a single reading byte. The first code is the simplest reading code, it will display a sin…

---

<div class="post-metadata">

**Author:** ![un23](https://avatars.discourse-cdn.com/v4/letter/u/53a042/32.png) [@un23](https://discourse.processing.org/u/un23)\
**Post date:** [February 26, 2022, 9:15am UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/5 "2022-02-26T09:15:57Z")

</div>

Hello,

that was one of the examples I tried and it does not work with bluetooth le. And also it doesn’t use ketai. So if I missed a real le example, please help me out with a link.

In the meantime I have something roughly working, sending characters back and forth, but it’s only a mess of code patches now.

Regards  
un23

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [February 26, 2022, 10:08am UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/6 "2022-02-26T10:08:37Z")

</div>

Hi

I have tried this with android 8

> [@APDE ketai example](https://discourse.processing.org/t/apde-ketai-example/27133):
>
> Hi this code receive data from terminal but not sending what I missed ? import android.content.Intent; import android.os.Bundle; import ketai.net.bluetooth.\*; import ketai.ui.\*; import ketai.net.\*; PFont fontMy; boolean bReleased = true; //no permament sending when finger is tap KetaiBluetooth bt; boolean isConfiguring = true; String info = ""; KetaiList klist; ArrayList devicesDiscovered = new ArrayList(); //\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* // The followin…

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [February 26, 2022, 1:33pm UTC](https://discourse.processing.org/t/bluetooth-connection-times-out/35146/7 "2022-02-26T13:33:33Z")

</div>

> [@Connecting Arduino with Android - Bluetooth](https://discourse.processing.org/t/connecting-arduino-with-android-bluetooth/32605):
>
> Hi, Im trying to run this code ([/dev/jarzebski: Przetwarzanie i wizualizacja danych](http://www.jarzebski.pl/arduino/wstep/przetwarzanie-i-wizualizacja-danych.html)) but with gyroscope instead of joystick. While connecting my arduino with PC via Bluetooth it works, but when i try connecting arduino with phone also via Bluetooth im reciving Error : the import processing.serial cannot be resolved. Im using APDE app. Is there any easy way to connect them? without rewriting whole code?
