-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclearpass.py
executable file
·62 lines (43 loc) · 1.31 KB
/
clearpass.py
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
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
from bluepy.btle import Peripheral, DefaultDelegate, BTLEException
import struct
import argparse
import sys
import time
import binascii
import atexit
class delegate(DefaultDelegate):
def __init__(self):
DefaultDelegate.__init__(self)
def handleNotification(self, cHandle, data):
hex_data = binascii.hexlify(data)
hex_string = hex_data.decode('utf-8')
print(hex_string)
def main():
if len(sys.argv) > 1:
address = str(sys.argv[1])
else:
print("Need address arg")
exit()
try:
print('Connecting to BMS ' + address)
bt = Peripheral(address, addrType="public")
except BTLEException as ex:
time.sleep(10)
bt = Peripheral(address, addrType="public")
except BTLEException as ex:
print('Connection failed')
exit()
else:
print('Connected ', address)
d = delegate()
bt.setDelegate(d)
# [Start Byte][write][clearpass reg][payload len][payload ][checksum][stop byte]
# dd 5a 09 06 4a 31 42 32 44 34 fe8a 77
# J 1 B 2 D 4
#
# Checksum = 65536 - ([reg byte] + [payload len byte] + [payload bytes])
bt.writeCharacteristic(0x15, b'\xdd\x5a\x09\x06\x4a\x31\x42\x32\x44\x34\xfe\x8a\x77', True)
bt.waitForNotifications(10.0)
if __name__ == "__main__":
main()