4

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

Danilo
  • 41
  • 1
  • 1
  • 3

2 Answers2

3

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...

Nuri can
  • 31
  • 2
0

@murtaza-haji - the value a4:50:4f:f8:44:66 is the Bluetooth address.

You can use the discover_devices method from pybluez to discover this.

import bluetooth  # from pip install pybluez

nearby_devices = bluetooth.discover_devices(lookup_names=True)
print(f"Found {len(nearby_devices)} devices.")

for addr, name in nearby_devices:
    print(f"  {addr} - {name}")
cod3monk3y
  • 9,508
  • 6
  • 39
  • 54
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 06 '22 at 01:56