У меня есть два двухэлементных мостовых контроллера (которые используются для подачи питания на вентиляторы), которые подключены к моему Raspberry Pi 3 B через GPIO и аккумулятор для питания. Я создал скрипт на Python 3, который использует Bluetooth classic для запросаподключенный телефон в терминале, как долго вентилятор должен быть включен и как долго он должен быть выключен в цикле У меня это работает, БОЛЬШОЙ, но это работает только на Android, так как это классический Bluetooth, я теперь хочу сделать эту работудля моего iPhone я также узнал, что мне нужно использовать BLE, поэтому мой вопрос заключается в том, как я могу преобразовать свой оригинальный скрипт в Bluetooth classic (используя RF COMM Sockets) для использования Bluetooth Low Energy.
Вот мой оригиналscript
# Importing the Bluetooth Socket library
import bluetooth
# Importing the GPIO library to use the GPIO pins of Raspberry pi
import RPi.GPIO as GPIO
import time
fan_pin = 16# Initializing pin 16 for fan
fan2_pin = 18
GPIO.setmode(GPIO.BOARD) # Using BCM numbering
GPIO.setup(fan_pin, GPIO.OUT) # Declaring the pin 16 as output pin
GPIO.setup(fan2_pin, GPIO.OUT) # Declaring the pin 16 as output pin
host = ""
port = 1 # Raspberry Pi uses port 1 for Bluetooth Communication
# Creaitng Socket Bluetooth RFCOMM communication
server = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
print('Bluetooth Socket Created')
try:
server.bind((host, port))
print("Bluetooth Binding Completed")
except:
print("Bluetooth Binding Failed")
server.listen(1) # One connection at a time
# Server accepts the clients request and assigns a mac address.
client, address = server.accept()
print("Connected To", address)
print("Client:", client)
while 1:
# Receivng the data.
client.send("How long do you want the fans to be on for?/n")
On = int(client.recv(1024)) # 1024 is the buffer size.
time.sleep(5)
client.send("Ok, Now how long do you want the fans to be off for?/n")
Off = int(client.recv(1024))
print(On)
print(Off)
while True:
GPIO.output(fan_pin, GPIO.HIGH)
GPIO.output(fan2_pin, GPIO.HIGH)
time.sleep(On)
GPIO.output(fan_pin, GPIO.LOW)
GPIO.output(fan2_pin, GPIO.LOW)
time.sleep(Off)
# Making all the output pins LOW
GPIO.cleanup()
# Closing the client and server connection
client.close()
server.close()
Я бы подумал, что это будет так же просто, как заменить все, что было классическим кодом Bluetooth, на код BLE.Макс как 20 строк поменять?