Bluetooth serial read data

1,022 views
Skip to first unread message

Geert-Jan Kreileman

unread,
Dec 18, 2014, 7:58:24 AM12/18/14
to kivy-...@googlegroups.com
Hi,

I used a example from someone online (someone from kivy i think it was) with a example to make a bluetooth serial connection from kivy on a android phone to a bluetooth serial device.

Connecting works, sending data probably also (even though i don't use that), but i can't get receiving to work.

Here's my example:

from jnius import autoclass
 
class BluetoothComm:
 
def get_socket_stream(self,name):
BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
BluetoothDevice = autoclass('android.bluetooth.BluetoothDevice')
BluetoothSocket = autoclass('android.bluetooth.BluetoothSocket')
UUID = autoclass('java.util.UUID')
paired_devices = BluetoothAdapter.getDefaultAdapter().getBondedDevices().toArray()
#Logger.info(str(paired_devices));
socket = None
for device in paired_devices:
#Logger.info(str(device.getName()));
#if device.getName() == name:
socket = device.createRfcommSocketToServiceRecord(
UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"))
recv_stream = socket.getInputStream()
send_stream = socket.getOutputStream()
break
socket.connect()
return recv_stream, send_stream
 
def __init__(self):
#try:
#buffer = bytes([1024]);
#byte buf = new byte[64];
global recv_stream;
global send_stream;
recv_stream, send_stream = self.get_socket_stream('hc06')
send_stream.write('hello\n')
#Logger.info(str(recv_stream.read(buffer)));
send_stream.flush()
Clock.schedule_interval(self.read, 5)
#except:
# Logger.exception("fout met blauwe tand");
def read(self, dt=0):
global recv_stream;
global send_stream;
Logger.info("start read");
#buffer = bytes([2048]);
try:
#Logger.info(str(recv_stream.read(bytes(1024)).decode("utf-8")));
Logger.info(str(recv_stream.available()));
if recv_stream.available() > 0:
#ik mag gaan lezen!
bytesread = recv_stream.read(bytes(1024));
print "test";
Logger.info(str(type(bytesread)));
except:
Logger.exception("au");

 
Reading doesnt work, it does sais that bytes are availible, but if i print recv_stream.read(bytes(1024)) the result is a 1 or a 4.

What should i do?! Thanks! :)

KyungHoon Baek

unread,
Apr 14, 2015, 9:30:39 PM4/14/15
to kivy-...@googlegroups.com

Have you solved this solution??
I also want to know this solution.

In my opinison, this maybe solved by callling java.io.InputStreamReader
by pyJNIus
Message has been deleted

Anders Högqvist

unread,
Apr 20, 2015, 12:17:42 PM4/20/15
to kivy-...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages