I'm using PyBluez2 to try and connect a bluetooth device. I have it searching for a device printing them out 1 by 1 with the address and the name as well as throwing them in a list. I use some janky methods to get the mac address separate. I can't find a way to connect a bluetooth device any help is appreciated. All I need is to receive data from the device.
Code is as follows:
import bluetooth as bt
nearby_devices = bt.discover_devices(lookup_names=True)
print("Found {} devices.".format(len(nearby_devices)))
x = int(1)
bluetooth_devices = []
for addr, name in nearby_devices:
new_device = ("{} - Address: {} - Name: {}").format(x, addr, name)
bluetooth_devices.append(new_device)
x += 1
print(new_device + "\n")
#print(bluetooth_devices)
device_number = int(input("\nWhich bluetooth device do you want to connect to? (enter number) ")) - 1
print(bluetooth_devices[device_number])
device = bluetooth_devices[device_number]
y = 13
z = 30
if device_number > 9 < 100:
y += 1
z += 1
address = str(device)[y:z]
print(address)
I've tried the connect function that's in pybluez but it says its not a function in pybluez2. I also can't get pybluez to install it does a bunch of weird errors and pybluez2 just installed without issues.