python-3.x - 使用 BLED112 加密狗连接到 BLE 模块并读/写 GATT 服务特征的 Python 代码

标签 python-3.x bluetooth-lowenergy

我有一个 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/

相关文章:

python - 计算 Elasticsearch 中索引中的文档数

python - 通过正则表达式提取带有 "only"的url链接 ".php.com"

python - 有条件地设置 Pandas 数据框列值

ios - iOS中将MTU换成BTLE的方法

android - 在实践中协商 Android 和 iOS 中央/外设上的蓝牙 LE ATT MTU

c++ - Windows 上的低功耗蓝牙堆栈溢出

安卓蓝牙低功耗特性值

python-3.x - 获取包含元组的列表的索引,其中元组的第一个元素与模式匹配

Python计数/字典计数

java - BluetoothGatt.writeCharacteristic 一半时间返回 false