- Install gatt and test it works with
sudo gattctl --discover
: https://github.com/getsenic/gatt-python - Get the mac of your Turn Touch using gattctl and update monitor.py appropriately (remember to unpair your tt from everything else first!)
- simply run
sudo python3 monitor.py
. Press some buttons and if everything is set up correctly, you will see it respond!
Last active
March 3, 2018 19:04
-
-
Save fredley/e0f707e814e23b0d98322a525ce1b7d1 to your computer and use it in GitHub Desktop.
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
import gatt | |
manager = gatt.DeviceManager(adapter_name='hci0') | |
class TurnTouch(gatt.Device): | |
button_codes = { | |
b'\xff\x00': 'Off', | |
b'\xfe\x00': 'North Press', | |
b'\xef\x00': 'North Double', | |
b'\xfe\xff': 'North Hold', | |
b'\xfd\x00': 'East Press', | |
b'\xdf\x00': 'East Double', | |
b'\xfd\xff': 'East Hold', | |
b'\xfb\x00': 'West Press', | |
b'\xbf\x00': 'West Double', | |
b'\xfb\xff': 'West Hold', | |
b'\xf7\x00': 'South Press', | |
b'\x7f\x00': 'South Double', | |
b'\xf7\xff': 'South Hold' | |
} | |
def connect_succeeded(self): | |
super().connect_succeeded() | |
print("Connected!") | |
def connect_failed(self, error): | |
super().connect_failed(error) | |
print("Connect failed with error {}".format(error)) | |
def services_resolved(self): | |
super().services_resolved() | |
print("Found services: {}".format([s.uuid for s in self.services])) | |
button_status_service = next(s for s in self.services | |
if s.uuid == '99c31523-dc4f-41b1-bb04-4e4deb81fadd') | |
button_status_characteristic = next(c for c in button_status_service.characteristics | |
if c.uuid == '99c31525-dc4f-41b1-bb04-4e4deb81fadd') | |
button_status_characteristic.enable_notifications() | |
def characteristic_enable_notifications_succeeded(self, characteristic): | |
super().characteristic_enable_notifications_succeeded(characteristic) | |
print("Subscribed to updates!") | |
def characteristic_value_updated(self, characteristic, value): | |
super().characteristic_value_updated(characteristic, value) | |
if value == b'\xff\x00': #off | |
return | |
print("Button press: {}".format(self.button_codes.get(value, "Unknown!"))) | |
if __name__ == '__main__': | |
device = TurnTouch(mac_address='c2:51:f2:36:3f:ad', manager=manager) | |
device.connect() | |
print("Running!") | |
manager.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment