-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbluetooth.py
36 lines (31 loc) · 1.19 KB
/
bluetooth.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
from authentication import *
import time
import serial
def bluetooth_read(channel):
print("bluetooth started")
while True:
ser = serial.Serial(port=str(channel), baudrate = 9600, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE , bytesize = serial.EIGHTBITS, timeout = 1)
read = str(ser.readline())
newstr = read[2:len(read)-5]
if len(newstr) != 0:
print(newstr)
try:
index = newstr.index("x")
if int(newstr[index+1:]) >= 0:
id=int(newstr[0:index])
print(id)
ok = True
except:
print("Something went wrong, loooolz")
ok = False
if ok == True:
print("a")
authentication(id)
print("b")
def bluetooth_send(message, channel):
ser = serial.Serial(port=str(channel), baudrate = 9600, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE , bytesize = serial.EIGHTBITS, timeout = 1)
counter = 0
while counter < 5:
counter += 1
time.sleep(2)
ser.write(bytes(str(message), 'utf-8'))