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

查看:712
本文介绍了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.

我要实现的是一个加特服务器,它是从命令行创建的,并且可以被任何中央设备(例如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个服务的Gatt Server,其中包含3个特征.

Gatt Server with 1 service which contains 3 characteristics.

  • 服务uuid​​ = 0xFFFF
  • Char 1 uuid = 0xAAAA,值= 01,属性=可读
  • 字符2 uuid = 0xBBBB,值= 00,属性=可读&可写的
  • Char 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天全站免登陆