Python 使用 BLED112 加密狗连接到 BLE 模块并读取/写入 GATT 服务特性的代码
Python code to connect to BLE module using BLED112 dongle and read/ write to GATT services-characteristics
我有一个 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()
我有一个 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()