-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbluetooth_challenge.py
More file actions
64 lines (35 loc) · 1.26 KB
/
bluetooth_challenge.py
File metadata and controls
64 lines (35 loc) · 1.26 KB
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
import bluetooth
### GLOBAL VARIABLES ###
props_dict = {}
### FUNCTIONS ###
def init(props):
global props_dict
print("Python: starting challenge init()")
# Save properties in the global variable
props_dict = props
# Execute the challenge once during the init, so key is calculated from the beginning
executeChallenge()
return 0
def executeChallenge():
print("Python: starting executeChallenge()")
# The key will be 0000 or name+MAC depending on if the device is near or not
cad = ""
print("Searching...")
devices = bluetooth.discover_devices(duration=8, lookup_names=True,
flush_cache=True, lookup_class=False)
if ('00:1E:1A:20:66:46','MO9920') in devices:
cad='00:1E:1A:20:66:46'+'MO9920'
else:
cad='0000'
# Get key as UTF-8 and calculate its length
key = bytes(cad, 'utf-8')
key_size = len(key)
# The result is a tuple (key, key_size)
result = (key, key_size)
print("Python:", result)
return result
if __name__ == "__main__":
# Use a dictionary as example of properties obtained from the json
props_example_dict = {"param1": "hola", "param2": 3}
init(props_example_dict)
executeChallenge()