我有一个 BLED112 适配器和一个 BLE 设备。 我的 BLE 设备有一项服务和两项特征。 我需要开发一个 python 脚本,使用 BLED112 扫描附近的 BLE 设备并连接到我的 BLE 设备。 然后我需要找到服务特征并对它们进行读写。
我在github上找到了对BGAPI和PYGATT的支持,但它们看起来很复杂。
请帮助我举一个简单的例子来完成我的任务。
提前非常感谢。
最佳答案
我能够添加一个文本框和按钮来获取兼容性并扫描附近的设备 以下是我的代码:-
import pygatt
import re
import tkinter as tk
from functools import partial
def call_result(label_result, n1):
num1 = str(n1.get())
label_result.config(text="Comport is %s" % num1)
adapter = pygatt.BGAPIBackend(serial_port=str(num1))
adapter.start()
listOfDevices = adapter.scan()
print (listOfDevices)
return
root = tk.Tk()
root.geometry('800x400+100+200')
root.title('Project')
number1 = tk.StringVar()
labelTitle = tk.Label(root, text="Project").grid(row=0, column=2)
labelNum1 = tk.Label(root, text="Enter Comport of dongle").grid(row=1, column=0)
labelResult = tk.Label(root)
labelResult.grid(row=7, column=2)
entryNum1 = tk.Entry(root, textvariable=number1).grid(row=1, column=2)
call_result = partial(call_result, labelResult, number1)
buttonCal = tk.Button(root, text="Get ComPort", command=call_result).grid(row=3, column=0)
root.mainloop()
关于python-3.x - 使用 BLED112 加密狗连接到 BLE 模块并读/写 GATT 服务特征的 Python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60760119/