I am working on a program to help my 'bar code scanner'(HID) connect to back to my Raspberry Pi once it loses connection. There is an issue with Ubuntu based computers with reconnecting to Bluetooth devices.
Long story short I realized a folder appears when my device is connected, my goal is to detect the folder and reboot the bluetooth communications as soon as the folder is not detected anymore. here is my code:
import os, time
while(1):
if os.path.isdir("/sys/bus/usb/devices/1-1.5:1.0/bluetooth/hci0/hci0:72"):
print("Safe!")
time.sleep(10)
else:
os.system("sudo rfkill block bluetooth && sudo rfkill unblock bluetooth") #RESET BLUETOOTH COMMUNICATIONS - allows device to reconnect!!!!
print("Bluetooth system rebooted")
time.sleep(10)
Everything works great however from time to time the "hci0:72" changes to "hci0:71" or "hci0:XX" and I want to cover myself for these situations.
P.S. "hci0:XX" is a directory....
I've tried
os.path.isdir("/sys/bus/usb/devices/1-1.5:1.0/bluetooth/hci0/hci0:**"):
and
os.path.isdir("/sys/bus/usb/devices/1-1.5:1.0/bluetooth/hci0/hci0:.."):
but False is returned whenever I try using "*" or ".".
Would love some help with polishing off this program, thank you for any and all help!!!!