如何从Airpods访问GATT服务设备信息

问题描述

我想访问GATT服务设备信息及其AirPods的特征(特别是序列号)。我在Windows上尝试过高贵,暗淡和pybluez,在Mac上也尝试过。还没有在Linux上尝试过bluez。如果我能用Windows完成它,那将是很好。

在阴暗和高贵的环境中连接到AirPods都遇到麻烦。我已经将zadig工具用于高贵,将常规的蓝牙驱动程序用于bleak和pybluez。是否可以从AirPods上获得gatt特征序列号?我不确定我是否可以连接到他们。

这是我的惨淡脚本:

import asyncio
from bleak import discover,BleakClient
from bleak.backends.device import BLEDevice

dis_SERVICE_UUID         = '0000180A-0000-1000-8000-00805F9B34FB'
MANUFACTURER_CHAR_UUID  = "00002A29-0000-1000-8000-00805F9B34FB"
MODEL_CHAR_UUID         = "00002A24-0000-1000-8000-00805F9B34FB"
SERIAL_CHAR_UUID        = "00002A25-0000-1000-8000-00805F9B34FB"
PNP_ID_CHAR_UUID        = "00002A50-0000-1000-8000-00805F9B34FB"

async def run(loop):
    devices = await discover()
    for d in devices:
        #client = BleakClient(d.address,loop=loop) 
        print("starting",d.address,"loop")
        if (d.address == "AC:90:85:80:1D:5F"):
            print(d.details)
            try:
                async with BleakClient(d.address,loop=loop,timeout=5.0) as client:
                #client = BLEDevice(d.address,d.name)#,timeout=5.0)
                    #await asyncio.sleep(5.0,loop=loop)
                        #svcs = await client.get_services()
                        # await client.connect()
                    a = await client.is_connected()
                    print(a)
                    print(d.name)
                    svcs = await client.get_services()
                    print("Services:",svcs)
                    for service in client.services:
                        print("[Service] {0}: {1}".format(service.uuid,service.description))
                        for char in service.characteristics:
                            if "read" in char.properties:
                                try:
                                    value = bytes(await client.read_gatt_char(char.uuid))
                                except Exception as e:
                                    value = str(e).encode()
                            else:
                                value = None
                            print(
                                "\t[Characteristic] {0}: (Handle: {1}) ({2}) | Name: {3},Value: {4} ".format(
                                    char.uuid,char.handle,",".join(char.properties),char.description,value,)
                            )
                            for descriptor in char.descriptors:
                                value = await client.read_gatt_descriptor(descriptor.handle)
                                print(
                                    "\t\t[Descriptor] {0}: (Handle: {1}) | Value: {2} ".format(
                                        descriptor.uuid,descriptor.handle,bytes(value)
                                    )
                                )

                    model_number = await client.read_gatt_char(MODEL_CHAR_UUID)
                    print("Model Number: {0}".format("".join(map(chr,model_number))))
                    serial_number = await client.read_gatt_char(SERIAL_CHAR_UUID)
                    print("Serial Number: {0}".format("".join(map(chr,serial_number))))

            except Exception as e:
                print("Couldn't connect as client")
                print(e) 

            try:
                async with BLEDevice(d.address,d.name) as device:
                    print("connected as device")
                    print(device.details)
            except Exception as e:
                print("Couldn't connect as device")
                print(e) 
     
    

loop = asyncio.get_event_loop()
loop.run_until_complete(run(loop))

这是我高贵的剧本

var noble = require('noble');

noble.on('stateChange',function(state) {
  if (state === 'poweredOn') {
    noble.startScanning();
  } else {
    noble.stopScanning();
  }
});

const DEVICE_informatION_SERVICE_UUID = '38ba5b48baa14b08b72525c0e8a1e51b';

noble.on('discover',function(peripheral) {
    if (peripheral.address == 'ac:90:85:80:1d:5f') {
        noble.stopScanning();
        peripheral.connect((error) => {
          if (error) console.log(error);
          console.log("connected")
          peripheral.discoverServices(
            [DEVICE_informatION_SERVICE_UUID],(error,services) => {
              if (error) console.log(error);
              console.log('services array',services);
            }
          );
      })
        console.log(
            `Found device,name: ${peripheral.advertisement.localName},uuid: ${peripheral.uuid},address: ${peripheral.address}`
          );

        peripheral.on('connect',() => console.log('Device connected'));
        peripheral.on('disconnect',() => console.log('Device disconnected'));

    }
});

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...