diff options
| author | Edvin <[email protected]> | 2025-04-04 08:44:18 +0200 |
|---|---|---|
| committer | Edvin <[email protected]> | 2025-04-04 08:44:18 +0200 |
| commit | 0c636a3290eb897381f9c06e898aef904c1eca4f (patch) | |
| tree | a16d9379c871649c8bf01d6d8f4d657ddb18dc34 /main.py | |
| parent | dedd9c7def062ac86d968bad7efce35a3455b07c (diff) | |
catching up
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 90 |
1 files changed, 90 insertions, 0 deletions
@@ -0,0 +1,90 @@ +import RPi.GPIO as GPIO +from time import sleep + +import os +import glob +import bluetooth + +import re + +GPIO.setmode(GPIO.BCM) +GPIO.setup(17, GPIO.OUT) +GPIO.setup(27, GPIO.OUT) +GPIO.output(17, False) +GPIO.output(27, False) + +target = "D4:D2:52:ED:14:89" + +server_sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) +server_sock.bind(("", bluetooth.PORT_ANY)) +server_sock.listen(1) + +port = server_sock.getsockname()[1] + +print("Waiting for connection on RFCOMM channel %d..." % port) + +client_sock, client_info = server_sock.accept() + +while client_sock: + read = client_sock.recv(1024) + read = read.decode("utf-8").strip('\n') + print(read) + + if read == "11": + GPIO.output(17, True) + GPIO.output(27, False) + elif read == "22": + GPIO.output(17, False) + GPIO.output(27, True) + else: + GPIO.output(17, False) + GPIO.output(27, False) +pi@pigroup3:~/TNE107-RPI$ cat main.py +import RPi.GPIO as GPIO +from time import sleep + +import os +import glob +import bluetooth + +import re + +GPIO.setmode(GPIO.BCM) +GPIO.setup(17, GPIO.OUT) +GPIO.setup(27, GPIO.OUT) +GPIO.output(17, False) +GPIO.output(27, False) + +target = "D4:D2:52:ED:14:89" + +server_sock = bluetooth.BluetoothSocket( bluetooth.RFCOMM ) +server_sock.bind(("", bluetooth.PORT_ANY)) +server_sock.listen(1) + +port = server_sock.getsockname()[1] + +print("Waiting for connection on RFCOMM channel %d..." % port) + +client_sock, client_info = server_sock.accept() + +while client_sock: + read = client_sock.recv(1024) + read = read.decode("utf-8").strip('\n') + print(read) + + if read == "11": + GPIO.output(17, True) + GPIO.output(27, False) + elif read == "22": + GPIO.output(17, False) + GPIO.output(27, True) + else: + GPIO.output(17, False) + GPIO.output(27, False) + +GPIO.output(17, False) +GPIO.output(27, False) + +print("Shutting down...") +server_sock.close() +print("Done.") |
