Android 蓝牙 UUID 理解

您所在的位置:网站首页 ios和安卓蓝牙传输一样吗 Android 蓝牙 UUID 理解

Android 蓝牙 UUID 理解

2024-07-07 00:22:48| 来源: 网络整理| 查看: 265

你的每一个赞 都是我坚持的动力 

大部分为转载 :

 http://dxjia.cn/2016/01/29/android-bluetooth-uuid/ 对Android蓝牙UUID的理解

Android 蓝牙开发常用UUID表_cc_want的博客-CSDN博客  蓝牙开发常用UUID表

先来段百度百科上的解释: 

UUID含义是通用唯一识别码 (Universally Unique Identifier),这 是一个软件建构的标准,也是被开源软件基金会 (Open Software Foundation, OSF) 的组织应用在分布式计算环境 (Distributed Computing Environment, DCE) 领域的一部分。它保证对在同一时空中的所有机器都是唯一的。通常平台会提供生成的API。按照开放软件基金会(OSF)制定的标准计算,用到了以太网卡地址、纳秒级时间、芯片ID码和许多可能的数字 UUID 的目的,是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定。如此一来,每个人都可以建立不与其它人冲突的 UUID。

总结起来就是,UUID是根据一定算法,计算得到的一长串数字,这个数字的产生使用了多种元素,所以使得这串数字不会重复,每次生成都会产生不一样的序列,所以可以用来作为唯一标识。

蓝牙RFCOMM数据(SPP 串口)通信

在来看看在蓝牙中为啥会用到UUID。 在蓝牙协议中,UUID被用来标识蓝牙设备所提供的服务,并非是标识蓝牙设备本身哦,一个蓝牙设备可以提供多种服务,比如A2DP(蓝牙音频传输)、HEADFREE(免提)、PBAP(电话本)、SPP(串口通信)等等,每种服务都对应一个UUID,其中在蓝牙协议栈里,这些默认提供的profile是都有对应的UUID的,也就是默认的UUID,比如SPP,00001101-0000-1000-8000-00805F9B34FB就是一个非常 well-known的UUID,基本上所有的蓝牙板不修改的话都是这个值,所以,如果是与一个蓝牙开发板进行串口通信,而蓝牙侧又不是自己可以控制的,就可以试试这个值。

当然,我们进行串口通信的开发,一般都会自己同时开发两侧,因为串口传递的数据就是数据流,没有格式之说,具体发送的数据的意义需要自己来定义,就是说自己定义规则,这就要求一端发送的数据,另一端可以理解。两者的通信基于socket进行实现,所以必须有一端做服务端,另一端做客户端。

再来说下,android里进行蓝牙串口通信的接口,以android端作为客户端为例,也就是对方蓝牙设备作为server端,等着android端来连接。 那么android端需要通过

1 public BluetoothSocket createRfcommSocketToServiceRecord (UUID uuid)

这个接口来创建一个socket,并用这个socket对connect(),UUID参数类似用来指定socket对应的端口,而server端必须也有在这个UUID上创建好server端socket上监听才可以成功连接上,两者用的UUID必须一样才可以。

所以UUID的用处就在这里。

如何使用UUID

根据上面的描述,要使用蓝牙进行串口通信,前提条件就是两侧都是你可以定义的(如果不可以,那么你可以尝试well-known SPP UUID,但双方的数据你是没办法控制的),两侧都可以自定义,这样的场景才是使用蓝牙串口通信解决问题的合理场景啊,要不然通信了,互发的数据不认识,没啥用啊。。。。

所以,这种情况,最好是使用自己生成的UUID,在windows下,命令行里执行uuidgen 就可以得到一个,类似:

1 14c5449a-6267-4c7e-bd10-63dd79740e5d

这样的好处就是,只有我们自己的设备可以通信,别人的UUID来连接是连接不上的,我们也不会连接上别人的设备。

当然,你也可以选择well-known的UUID,这么干的也不少,这样有个缺点就是可能会有干扰,比如别人的设备也正好使用这个UUID起了个server端,那么我们的设备也使用这个UUID去连,就连上了。。。但。。。互发的数据还是不认识哦,没用。。。。

本身UUID就是用来标识唯一性的,还是自己生成吧。。。

附上,Android developer上的一段hint:

About UUID A Universally Unique Identifier (UUID) is a standardized 128-bit format for a string ID used to uniquely identify information. The point of a UUID is that it’s big enough that you can select any random and it won’t clash. In this case, it’s used to uniquely identify your application’s Bluetooth service. To get a UUID to use with your application, you can use one of the many random UUID generators on the web, then initialize a UUID with fromString(String). Hint: If you are connecting to a Bluetooth serial board then try using the well-known SPP UUID 00001101-0000-1000-8000-00805F9B34FB. However if you are connecting to an Android peer then please generate your own unique UUID.v

谷歌翻译:

关于UUID 通用唯一标识符(UUID)是用于唯一标识信息的字符串ID的标准化128位格式。 UUID的重点是它足够大,你可以选择任何随机的,它不会发生冲突。 在这种情况下,它用于唯一标识应用程序的蓝牙服务。 要使UUID与您的应用程序一起使用,您可以使用Web上的许多随机UUID生成器之一,然后使用fromString(String)初始化UUID。 提示:如果要连接蓝牙串行板,请尝试使用众所周知的SPP UUID 00001101-0000-1000-8000-00805F9B34FB。 但是,如果您要连接到Android对等设备,请生成您自己的唯一UUID.v

 蓝牙开发常用UUID表 Sample Services 0000180d-0000-1000-8000-00805f9b34fb    Heart Rate Service     0000180a-0000-1000-8000-00805f9b34fb    Device Information Service     Sample Characteristics.  00002a37-0000-1000-8000-00805f9b34fb    Heart Rate Measurement     00002a29-0000-1000-8000-00805f9b34fb    Manufacturer Name String          GATT Services  00001800-0000-1000-8000-00805f9b34fb    GenericAccess     00001801-0000-1000-8000-00805f9b34fb    GenericAttribute       GATT Declarations  00002800-0000-1000-8000-00805f9b34fb    Primary Service     00002801-0000-1000-8000-00805f9b34fb    Secondary Service     00002802-0000-1000-8000-00805f9b34fb    Include     00002803-0000-1000-8000-00805f9b34fb    Characteristic               GATT Descriptors  00002900-0000-1000-8000-00805f9b34fb    Characteristic Extended Properties     00002901-0000-1000-8000-00805f9b34fb    Characteristic User Description     00002902-0000-1000-8000-00805f9b34fb    Client Characteristic Configuration     00002903-0000-1000-8000-00805f9b34fb    Server Characteristic Configuration     00002904-0000-1000-8000-00805f9b34fb    Characteristic Presentation Format     00002905-0000-1000-8000-00805f9b34fb    Characteristic Aggregate Format     00002906-0000-1000-8000-00805f9b34fb    Valid Range     00002907-0000-1000-8000-00805f9b34fb    External Report Reference Descriptor     00002908-0000-1000-8000-00805f9b34fb    Report Reference Descriptor       GATT Characteristics  00002a00-0000-1000-8000-00805f9b34fb    Device Name     00002a01-0000-1000-8000-00805f9b34fb    Appearance     00002a02-0000-1000-8000-00805f9b34fb    Peripheral Privacy Flag     00002a03-0000-1000-8000-00805f9b34fb    Reconnection Address     00002a04-0000-1000-8000-00805f9b34fb    PPCP     00002a05-0000-1000-8000-00805f9b34fb    Service Changed               GATT Service UUIDs  00001802-0000-1000-8000-00805f9b34fb    Immediate Alert     00001803-0000-1000-8000-00805f9b34fb    Link Loss     00001804-0000-1000-8000-00805f9b34fb    Tx Power     00001805-0000-1000-8000-00805f9b34fb    Current Time Service     00001806-0000-1000-8000-00805f9b34fb    Reference Time Update Service     00001807-0000-1000-8000-00805f9b34fb    Next DST Change Service     00001808-0000-1000-8000-00805f9b34fb    Glucose     00001809-0000-1000-8000-00805f9b34fb    Health Thermometer     0000180a-0000-1000-8000-00805f9b34fb    Device Information     0000180b-0000-1000-8000-00805f9b34fb    Network Availability     0000180d-0000-1000-8000-00805f9b34fb    Heart Rate     0000180e-0000-1000-8000-00805f9b34fb    Phone Alert Status Service     0000180f-0000-1000-8000-00805f9b34fb    Battery Service     00001810-0000-1000-8000-00805f9b34fb    Blood Pressure     00001811-0000-1000-8000-00805f9b34fb    Alert Notification Service     00001812-0000-1000-8000-00805f9b34fb    Human Interface Device     00001813-0000-1000-8000-00805f9b34fb    Scan Parameters     00001814-0000-1000-8000-00805f9b34fb    Running Speed and Cadence     00001816-0000-1000-8000-00805f9b34fb    Cycling Speed and Cadence     00001818-0000-1000-8000-00805f9b34fb    Cycling Power     00001819-0000-1000-8000-00805f9b34fb    Location and Navigation           GATT Characteristic UUIDs  00002a06-0000-1000-8000-00805f9b34fb    Alert Level     00002a07-0000-1000-8000-00805f9b34fb    Tx Power Level     00002a08-0000-1000-8000-00805f9b34fb    Date Time     00002a09-0000-1000-8000-00805f9b34fb    Day of Week     00002a0a-0000-1000-8000-00805f9b34fb    Day Date Time     00002a0c-0000-1000-8000-00805f9b34fb    Exact Time 256     00002a0d-0000-1000-8000-00805f9b34fb    DST Offset     00002a0e-0000-1000-8000-00805f9b34fb    Time Zone     00002a0f-0000-1000-8000-00805f9b34fb    Local Time Information     00002a11-0000-1000-8000-00805f9b34fb    Time with DST     00002a12-0000-1000-8000-00805f9b34fb    Time Accuracy     00002a13-0000-1000-8000-00805f9b34fb    Time Source     00002a14-0000-1000-8000-00805f9b34fb    Reference Time Information     00002a16-0000-1000-8000-00805f9b34fb    Time Update Control Point     00002a17-0000-1000-8000-00805f9b34fb    Time Update State     00002a18-0000-1000-8000-00805f9b34fb    Glucose Measurement     00002a19-0000-1000-8000-00805f9b34fb    Battery Level     00002a1c-0000-1000-8000-00805f9b34fb    Temperature Measurement     00002a1d-0000-1000-8000-00805f9b34fb    Temperature Type     00002a1e-0000-1000-8000-00805f9b34fb    Intermediate Temperature     00002a21-0000-1000-8000-00805f9b34fb    Measurement Interval     00002a22-0000-1000-8000-00805f9b34fb    Boot Keyboard Input Report     00002a23-0000-1000-8000-00805f9b34fb    System ID     00002a24-0000-1000-8000-00805f9b34fb    Model Number String     00002a25-0000-1000-8000-00805f9b34fb    Serial Number String     00002a26-0000-1000-8000-00805f9b34fb    Firmware Revision String     00002a27-0000-1000-8000-00805f9b34fb    Hardware Revision String     00002a28-0000-1000-8000-00805f9b34fb    Software Revision String     00002a29-0000-1000-8000-00805f9b34fb    Manufacturer Name String     00002a2a-0000-1000-8000-00805f9b34fb    IEEE 11073-20601 Regulatory Certification Data List     00002a2b-0000-1000-8000-00805f9b34fb    Current Time     00002a31-0000-1000-8000-00805f9b34fb    Scan Refresh     00002a32-0000-1000-8000-00805f9b34fb    Boot Keyboard Output Report     00002a33-0000-1000-8000-00805f9b34fb    Boot Mouse Input Report     00002a34-0000-1000-8000-00805f9b34fb    Glucose Measurement Context     00002a35-0000-1000-8000-00805f9b34fb    Blood Pressure Measurement     00002a36-0000-1000-8000-00805f9b34fb    Intermediate Cuff Pressure     00002a37-0000-1000-8000-00805f9b34fb    Heart Rate Measurement     00002a38-0000-1000-8000-00805f9b34fb    Body Sensor Location     00002a39-0000-1000-8000-00805f9b34fb    Heart Rate Control Point     00002a3e-0000-1000-8000-00805f9b34fb    Network Availability     00002a3f-0000-1000-8000-00805f9b34fb    Alert Status     00002a40-0000-1000-8000-00805f9b34fb    Ringer Control Point     00002a41-0000-1000-8000-00805f9b34fb    Ringer Setting     00002a42-0000-1000-8000-00805f9b34fb    Alert Category ID Bit Mask     00002a43-0000-1000-8000-00805f9b34fb    Alert Category ID     00002a44-0000-1000-8000-00805f9b34fb    Alert Notification Control Point     00002a45-0000-1000-8000-00805f9b34fb    Unread Alert Status     00002a46-0000-1000-8000-00805f9b34fb    New Alert     00002a47-0000-1000-8000-00805f9b34fb    Supported New Alert Category     00002a48-0000-1000-8000-00805f9b34fb    Supported Unread Alert Category     00002a49-0000-1000-8000-00805f9b34fb    Blood Pressure Feature     00002a4a-0000-1000-8000-00805f9b34fb    HID Information     00002a4b-0000-1000-8000-00805f9b34fb    Report Map     00002a4c-0000-1000-8000-00805f9b34fb    HID Control Point     00002a4d-0000-1000-8000-00805f9b34fb    Report     00002a4e-0000-1000-8000-00805f9b34fb    Protocol Mode     00002a4f-0000-1000-8000-00805f9b34fb    Scan Interval Window     00002a50-0000-1000-8000-00805f9b34fb    PnP ID     00002a51-0000-1000-8000-00805f9b34fb    Glucose Feature     00002a52-0000-1000-8000-00805f9b34fb    Record Access Control Point     00002a53-0000-1000-8000-00805f9b34fb    RSC Measurement     00002a54-0000-1000-8000-00805f9b34fb    RSC Feature     00002a55-0000-1000-8000-00805f9b34fb    SC Control Point     00002a5b-0000-1000-8000-00805f9b34fb    CSC Measurement     00002a5c-0000-1000-8000-00805f9b34fb    CSC Feature     00002a5d-0000-1000-8000-00805f9b34fb    Sensor Location     00002a63-0000-1000-8000-00805f9b34fb    Cycling Power Measurement     00002a64-0000-1000-8000-00805f9b34fb    Cycling Power Vector     00002a65-0000-1000-8000-00805f9b34fb    Cycling Power Feature     00002a66-0000-1000-8000-00805f9b34fb    Cycling Power Control Point     00002a67-0000-1000-8000-00805f9b34fb    Location and Speed     00002a68-0000-1000-8000-00805f9b34fb    Navigation     00002a69-0000-1000-8000-00805f9b34fb    Position Quality     00002a6a-0000-1000-8000-00805f9b34fb    LN Feature     00002a6b-0000-1000-8000-00805f9b34fb    LN Control Point");

坚持 每天进步一点点



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


图片新闻

实验室药品柜的特性有哪些
实验室药品柜是实验室家具的重要组成部分之一,主要
小学科学实验中有哪些教学
计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
实验室各种仪器原理动图讲
1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
高中化学常见仪器及实验装
1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
微生物操作主要设备和器具
今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
浅谈通风柜使用基本常识
 众所周知,通风柜功能中最主要的就是排气功能。在

专题文章

    CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭