-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed7a58e
commit 38ed9aa
Showing
5 changed files
with
63 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,5 @@ setuptools==57.5.0 | |
PyBluez==0.22 | ||
RPi.GPIO==0.7.1 | ||
keyboard==0.13.5 | ||
bluepy | ||
pyserial |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import threading | ||
from bluepy.btle import Scanner, DefaultDelegate | ||
|
||
class BLEConnector(threading.Thread): | ||
def __init__(self, device_name): | ||
self.device_name = device_name | ||
self.service_uuid = None | ||
self.characteristic_uuid = None | ||
def run(self, service_uuid, characteristic_uuid): | ||
self.service_uuid = service_uuid | ||
self.characteristic_uuid = characteristic_uuid | ||
self._process = p = threading.Thread(target=self._process) | ||
p.daemon = True | ||
p.start() | ||
|
||
def _process(self): | ||
|
||
while True: | ||
try: | ||
device = self.scan_devices() | ||
if not device: | ||
continue | ||
try: | ||
device.connect() | ||
services = device.getServices() | ||
for service in services: | ||
if service.uuid == self.service_uuid: | ||
characteristics = service.getCharacteristics() | ||
for char in characteristics: | ||
if char.uuid == self.characteristic_uuid: | ||
data = char.read() | ||
print(data) | ||
continue | ||
except Exception as e: | ||
return None, str(e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters