1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51#!/usr/bin/python
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2014, Oscar Acena <oscaracena@gmail.com>
# This software is under the terms of GPLv3 or later.
from __future__ import print_function
import sys
import time
from gattlib import GATTRequester
class Reconnect(object):
def __init__(self, address):
self.requester = GATTRequester(address, False)
times = 3
print("I will connect & disconnect {} times...".format(times))
for i in range(times):
self.connect()
self.disconnect()
def connect(self):
print("Connecting...", end=' ')
sys.stdout.flush()
self.requester.connect(True)
print("OK!")
time.sleep(1)
def disconnect(self):
print("Disconnecting...", end=' ')
sys.stdout.flush()
self.requester.disconnect()
print("OK!")
time.sleep(1)
if __name__ == '__main__':
if len(sys.argv) < 2:
print("Usage: {} <addr>".format(sys.argv[0]))
sys.exit(1)
Reconnect(sys.argv[1])
print("Done.")