BlueZ:如何从命令行设置 GATT 服务器 [英] BlueZ: How to set up a GATT server from the command line

查看:15
本文介绍了BlueZ:如何从命令行设置 GATT 服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法从 Linux 命令行设置 gatt 服务器.我知道 BlueZ gatttool 命令允许您充当 gatt 客户端并询问远程 gatt 服务器,但是,我认为此工具不能用于设置服务器.

I would like to know if there is a way to set up a gatt server from the Linux command line. I know that the BlueZ gatttool command allows you to act as a gatt client and interrogate a remote gatt server, however, I do not think that this tool can be used to set up a server.

我想要实现的是一个 gatt 服务器,从命令行创建,并且可以被任何中央设备(例如 iOS 或 Android 设备)询问以连接到 GATT 服务器,发现服务和特征,并操作特征中的数据.

What I want to achieve is a gatt server, created from the command line, and can be interrogated by any central device (e.g. iOS or Android device) to connect to the GATT server, discover the services and characteristics, and manipulate the data in the characteristics.

示例:

具有 1 个包含 3 个特征的服务的 Gatt 服务器.

Gatt Server with 1 service which contains 3 characteristics.

  • 服务 uuid = 0xFFFF
  • 字符 1 uuid = 0xAAAA,值 = 01,属性 = 可读
  • Char 2 uuid = 0xBBBB,值 = 00,属性 = 可读 &可写
  • 字符 3 uuid = 0xCCCC,值 = 02,属性 = 可通知

我使用的是内核版本 3.11.0 和 BlueZ 5.19

I am using kernel version 3.11.0 and BlueZ 5.19

推荐答案

所以现在使用新的 bluetoothctl 工具来处理这个问题.可以使用此工具设置 gatt 表,如下所示:-

So this is now handled with the new bluetoothctl tool. A gatt table can be set up using this tool as follows:-

#bluetoothctl
[bluetoothctl] menu gatt
[bluetoothctl] register-service 0xFFFF # (Choose yes when asked if primary service)
[bluetoothctl] register-characteristic 0xAAAA read       # (Select a value of 1 when prompted)
[bluetoothctl] register-characteristic 0xBBBB read,write # (Select a value of 0 when prompted)
[bluetoothctl] register-characteristic 0xCCCC read       # (Select a value of 2 when prompted)
[bluetoothctl] register-application # (This commits the services/characteristics and registers the profile)
[bluetoothctl] back
[bluetoothctl] advertise on

我已经尝试了一些服务/特性组合,并且能够让它发挥作用.GAP (0x1800) 和 GATT (0x1801) 服务在默认情况下可用,并且在您发布广告时将成为 GATT 表的一部分.您也可以使用以下命令查看可用的服务:-

I've tried this with a few service/characteristic combinations and was able to get it to work. The GAP (0x1800) and GATT (0x1801) services are available by default and will be part of the GATT table when you advertise. You can also use the following command to see the available services:-

[bluetoothctl] show
Controller 00:AA:BB:CC:DD:EE (public)
    Name: MyMachine
    Alias: MyMachine
    Class: 0x000c0000
    Powered: yes
    Discoverable: no
    Pairable: yes
    UUID: Headset AG                (00001112-0000-1000-8000-00805f9b34fb)
    UUID: Generic Attribute Profile (00001801-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control        (0000110e-0000-1000-8000-00805f9b34fb)
    UUID: Generic Access Profile    (00001800-0000-1000-8000-00805f9b34fb)
    UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
    UUID: A/V Remote Control Target (0000110c-0000-1000-8000-00805f9b34fb)
    UUID: Audio Source              (0000110a-0000-1000-8000-00805f9b34fb)
    UUID: Audio Sink                (0000110b-0000-1000-8000-00805f9b34fb)
    **UUID: Unknown                   (0000ffff-0000-1000-8000-00805f9b34fb)**
    UUID: Headset                   (00001108-0000-1000-8000-00805f9b34fb)
    Modalias: usb:v1D6Bp0246d0532
    Discovering: no

这篇关于BlueZ:如何从命令行设置 GATT 服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆