Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Socket Bluetooth

I'm trying to pair my cardio bluetooth sensor to my windows pc. After some searches I found pyBluez for x64 systems and now i'm able to discover bluetooth devices around me, their names,address and services. My Polar sensor has an L2CAP protocol and teorically is too symple to listen what transmits.

I found an example like this

server_sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)

port = 5
server_sock.bind(port)
server_sock.listen(1)

client_sock = server_sock.accept()
print ("Accepted connection from "+address)

data = client_sock.recv(1024)
print ("received [%s]" % data)

Also with different ports
when i run this code, i never read "accepted connection...."

Probably the reason is the lack of L2CAP for pyBluez windows version. I tried also a socket connection but the "socket.AF_BLUETOOTH" method isn't available for windows too. Have you any suggestion?

Thanks a lot and sorry for my englis

like image 270
Danilo Avatar asked Sep 01 '25 04:09

Danilo


1 Answers

you try socket library.

import socket

baddr = 'a4:50:4f:f8:44:66'
channel = 4
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, 
socket.BTPROTO_RFCOMM)
s.connect((baddr,channel))
s_sock = server_sock.accept()
print ("Accepted connection from "+address)

data = s_sock.recv(1024)
print ("received [%s]" % data)

s.listen(1)

I have tried pybluez but it didn't run. I try on Linux. I hope it works on windows...

like image 175
Nuri can Avatar answered Sep 02 '25 17:09

Nuri can