Я делаю проект о динамике Bluetooth, и эта часть посвящена графическому интерфейсу и команде sendind на мой динамик Bluetooth, который сделан из (модуль Arduino + Bluetooth)
from tkinter import *
from bluetooth import *
window = Tk()
client_socket=BluetoothSocket( RFCOMM )
i = 0
##Function
def play_pause():
global i
global client_socket
if ( i == 0 ):
client_socket.send("pl")
i = 1
elif ( i == 1 ):
client_socket.send("pa")
i = 0
def forward():
global client_socket
client_socket.send("fw")
def back():
global client_socket
client_socket.send("rv")
def volup():
global client_socket
client_socket.send("++")
def voldown():
global client_socket
client_socket.send("--")
def search_dev():
listdevice.delete(0,END)
nearby_devices = discover_devices(lookup_names = True)
search_label = Label(window, text=("found", len(nearby_devices), "devices"))
search_label.grid(row = 1, column = 1)
for name, addr in nearby_devices:
listdevice.insert(END,(addr,",",name))
def connect_command():
global client_socket
device = listdevice.curselection()
selected = listdevice.get(device)
client_socket.connect((selected[2], 3))
## Bluetooth
search = Button(window, text = 'Search Device', width = 12, command = search_dev)
search.grid(row = 1, column = 0)
connect = Button(window, text = 'Connect', width = 12, command = connect_command)
connect.grid(row = 2, column = 3,sticky = 'N')
listdevice = Listbox(window, height = 8 ,width = 46)
listdevice.grid(row=2, column = 0, columnspan = 3)
## Music player
reverse = Button(window, text = '<<', height = 3, width = 12, command = back)
reverse.grid(row = 8, column = 0, rowspan = 2)
play = Button(window, text = '► / ┃┃', height = 3, width = 12, command = play_pause)
play.grid(row = 8, column = 1, rowspan = 2)
forward = Button(window, text = '>>', height = 3, width = 12, command = forward)
forward.grid(row = 8, column = 2, rowspan = 2)
volup = Button(window, text = 'Vol+', width = 12, command = volup)
volup.grid(row = 8, column = 3)
voldown = Button(window, text = 'Vol-', width = 12, command = voldown)
voldown.grid(row = 9, column = 3)
window.mainloop()
Сначала я пытаюсь протестировать мой мобильный телефонтелефон, я нашел это, когда я пытаюсь нажать кнопку воспроизведения после подключения
104, Connection reset by peer
107, Transport endpoint is not connected
И когда я пытаюсь с моим динамиком Bluetooth я нашел это.
a socket operation failed because the destination host was down
Я даже не знаю, как это исправить, и мои навыки английского языка ДЕЙСТВИТЕЛЬНО ужасны, поэтому я не совсем понимаю об ошибках