TBluetoothLE

delphi 蓝牙技术

D:UsersPublicDocumentsEmbarcaderoStudio17.0SamplesObject PascalMulti-Device SamplesDevice Sensors and ServicesBluetoothClassic Bluetooth Basic app

System.Bluetooth

 Bluetooth Low Energy (BLE)

小米手环就是BLE4.0,在android手机上用HMBLEComAssistant.apk可以搜到小米手环。

 https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx

update,2015-09-25 12:08:41用delphi的BLE例子搜到小米手环了!!

SamplesObject PascalMulti-Device SamplesDevice Sensors and ServicesBluetoothBLEScanner

 蓝牙GAP、GATT(Generic Attribute Profile)

蓝牙音箱,通过android、iPhone都可以搜索到。

小米蓝牙音箱和小米手环的蓝牙版本完全相同吗?

 蓝牙耳机:蓝牙协议:HFP/A2DP/HSP/AVRCP

手环里使用了蓝牙4.0 BLE技术

 http://docwiki.embarcadero.com/RADStudio/Seattle/en/Using_Bluetooth

http://docwiki.embarcadero.com/RADStudio/XE8/en/Using_Bluetooth_Low_Energy

http://docwiki.embarcadero.com/CodeExamples/Seattle/en/Heart_Rate_Monitor_Sample

https://developer.apple.com/bluetooth/

蓝牙各种UUID

 Discovering Devices

BluetoothLE does not work as the Classic Bluetooth, you do not need to pair the devices. BluetoothLE clients need to discover BluetoothLE servers.  

蓝牙版本 V4.0 BLE

一节钮扣电池在静态工作状态可以支持一年。

蓝牙低功耗,也就是早前的Wibree,是蓝牙4.0版本的一个子集,它有着全新的协议栈,可快速建立简单的链接。作为蓝牙1.0 – 3.0版本中蓝牙标准协议的替代方案,它主要面向对功耗需求极低、用纽扣电池供电的应用。芯片设计可有两种:双模、单模和增强的早期版本。早期的Wibree蓝牙ULP(超低功耗)的名称被废除,取而代之的是后来用于一时的BLE。

delphi 获取小米手环数据 

手环在android上看到的

- Discovering services -->
1 - GAP - {00001800-0000-1000-8000-00805F9B34FB}
    - Device Name - {00002A00-0000-1000-8000-00805F9B34FB}
    - Appearance - {00002A01-0000-1000-8000-00805F9B34FB}
    - Peripheral Privacy Flag - {00002A02-0000-1000-8000-00805F9B34FB}
    - Peripheral Preferred Connection Parameters - {00002A04-0000-1000-8000-00805F9B34FB}
2 - GATT - {00001801-0000-1000-8000-00805F9B34FB}
    - Service Changed - {00002A05-0000-1000-8000-00805F9B34FB}
3 -  - {0000FEE0-0000-1000-8000-00805F9B34FB}
    -  - {0000FF01-0000-1000-8000-00805F9B34FB}
    -  - {0000FF02-0000-1000-8000-00805F9B34FB}
    -  - {0000FF03-0000-1000-8000-00805F9B34FB}
    -  - {0000FF04-0000-1000-8000-00805F9B34FB}
    -  - {0000FF05-0000-1000-8000-00805F9B34FB}
    -  - {0000FF06-0000-1000-8000-00805F9B34FB}
    -  - {0000FF07-0000-1000-8000-00805F9B34FB}
    -  - {0000FF08-0000-1000-8000-00805F9B34FB}
    -  - {0000FF09-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0A-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0B-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0C-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0D-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0E-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0F-0000-1000-8000-00805F9B34FB}
4 -  - {0000FEE1-0000-1000-8000-00805F9B34FB}
    -  - {0000FEDD-0000-1000-8000-00805F9B34FB}
    -  - {0000FEDE-0000-1000-8000-00805F9B34FB}
    -  - {0000FEDF-0000-1000-8000-00805F9B34FB}
    -  - {0000FED0-0000-1000-8000-00805F9B34FB}
    -  - {0000FED1-0000-1000-8000-00805F9B34FB}
    -  - {0000FED2-0000-1000-8000-00805F9B34FB}
    -  - {0000FED3-0000-1000-8000-00805F9B34FB}
5 -  - {0000FEE7-0000-1000-8000-00805F9B34FB}
    -  - {0000FEC7-0000-1000-8000-00805F9B34FB}
    -  - {0000FEC8-0000-1000-8000-00805F9B34FB}
    -  - {0000FEC9-0000-1000-8000-00805F9B34FB}
6 - IMMEDIATE ALERT - {00001802-0000-1000-8000-00805F9B34FB}
    - Alert Level - {00002A06-0000-1000-8000-00805F9B34FB}
View UUID

手环在苹果上看到的,少了前2行GAP和GATT。

1 -  - {0000FEE0-0000-1000-8000-00805F9B34FB}
    -  - {0000FF01-0000-1000-8000-00805F9B34FB}
    -  - {0000FF02-0000-1000-8000-00805F9B34FB}
    -  - {0000FF03-0000-1000-8000-00805F9B34FB}
    -  - {0000FF04-0000-1000-8000-00805F9B34FB}
    -  - {0000FF05-0000-1000-8000-00805F9B34FB}
    -  - {0000FF06-0000-1000-8000-00805F9B34FB}
    -  - {0000FF07-0000-1000-8000-00805F9B34FB}
    -  - {0000FF08-0000-1000-8000-00805F9B34FB}
    -  - {0000FF09-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0A-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0B-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0C-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0D-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0E-0000-1000-8000-00805F9B34FB}
    -  - {0000FF0F-0000-1000-8000-00805F9B34FB}
2 -  - {0000FEE1-0000-1000-8000-00805F9B34FB}
    -  - {0000FEDD-0000-1000-8000-00805F9B34FB}
    -  - {0000FEDE-0000-1000-8000-00805F9B34FB}
    -  - {0000FEDF-0000-1000-8000-00805F9B34FB}
    -  - {0000FED0-0000-1000-8000-00805F9B34FB}
    -  - {0000FED1-0000-1000-8000-00805F9B34FB}
    -  - {0000FED2-0000-1000-8000-00805F9B34FB}
    -  - {0000FED3-0000-1000-8000-00805F9B34FB}
3 -  - {0000FEE7-0000-1000-8000-00805F9B34FB}
    -  - {0000FEC7-0000-1000-8000-00805F9B34FB}
    -  - {0000FEC8-0000-1000-8000-00805F9B34FB}
    -  - {0000FEC9-0000-1000-8000-00805F9B34FB}
4 - IMMEDIATE ALERT - {00001802-0000-1000-8000-00805F9B34FB}
    - Alert Level - {00002A06-0000-1000-8000-00805F9B34FB}
View Apple UUID

Android BLE 

BTX-110003 - 20:C3:8F:EA:1B:AF

1 - BTX-110003 - 20:C3:8F:EA:1B:AF

- Discovering services -->
1 - GAP - {00001800-0000-1000-8000-00805F9B34FB}
    - Device Name - {00002A00-0000-1000-8000-00805F9B34FB}
    - Appearance - {00002A01-0000-1000-8000-00805F9B34FB}
    - Peripheral Privacy Flag - {00002A02-0000-1000-8000-00805F9B34FB}
    - Reconnection Address - {00002A03-0000-1000-8000-00805F9B34FB}
    - Peripheral Preferred Connection Parameters - {00002A04-0000-1000-8000-00805F9B34FB}
2 - GATT - {00001801-0000-1000-8000-00805F9B34FB}
    - Service Changed - {00002A05-0000-1000-8000-00805F9B34FB}
3 - Key Service - {0000FFE0-0000-1000-8000-00805F9B34FB}
    - Key Service Characteristic - {0000FFE1-0000-1000-8000-00805F9B34FB}
View Code

Delphi XE8 Bluetooth 蓝牙

搜索蓝牙设备

FBluetoothManager.StartDiscovery(1000);

or

BluetoothLE1.DiscoverDevices(ScanningTime);

本机蓝牙设备名称

FBluetoothManager.CurrentAdapter.AdapterName;

配对

FAdapter.Pair(FDiscoverDevices[ComboboxDevices.ItemIndex])

取消配对

FAdapter.UnPair(FPairedDevices[ComboboxPaired.ItemIndex])

蓝牙通讯

FServerSocket:TBluetoothServerSocket;
FScocket:TBluetoothSocket;

  TBluetoothService = record
    Name: string;
    UUID: TBluetoothUUID;
  end;

FSocket := ldevice.CreateClientSocket(StringToGUID(ServiceGUI), False);

TBluetoothManager.CurrentAdapter
FSocket: TBluetoothSocket;
ToSend: TBytes;
FSocket.Connect; ToSend :
= TEncoding.UTF8.GetBytes(Edit1.Text); FSocket.SendData(ToSend);

BLE 发送数据

ADevice: TBluetoothLEDevice;

AChar: TBluetoothGattCharacteristic;

ADevice.WriteCharacteristic(AChar);

procedure TfrmHeartMonitor.BluetoothLE1EndDiscoverDevices(const Sender: TObject;
  const ADeviceList: TBluetoothLEDeviceList);
var
  I: Integer;
begin
  // log
  Memo1.Lines.Add(ADeviceList.Count.ToString +  ' devices discovered:');
  for I := 0 to ADeviceList.Count - 1 do Memo1.Lines.Add(ADeviceList[I].DeviceName);

  if BluetoothLE1.DiscoveredDevices.Count > 0 then
  begin
    FBLEDevice := BluetoothLE1.DiscoveredDevices.First;
    lblDevice.Text := HRDeviceName;
    if BluetoothLE1.GetServices(FBLEDevice).Count = 0 then
    begin
      Memo1.Lines.Add('No services found!');
      lblBPM.Font.Size := 26;
      lblBPM.Text := 'No services found!';
    end
    else
      GetServiceAndCharacteristics;
  end
  else
    lblDevice.Text := 'Device not found';
end;

LServices: TBluetoothServiceList;

LDevice: TBluetoothDevice;

LServices := LDevice.GetServices;

 LServices[I].Name;

GUIDToString(LServices[I].UUID);

蓝牙功能列表 

LAN Access Using PPP
DialupNetworking
OBEXObjectPush
OBEXFileTransfer
Cordless Telephony
Audio Source
Audio Sink
AV Remote Control Target
Advanced Audio Distribution
AV Remote Control
Headset Audio Gateway
WAP
WAP Client
Personal Area Network User (PANU)
Network Access Point (NAP)
Group Ad-hoc Network (GN)
Handsfree
Handsfree Audio Gateway
SIM Access
Phonebook Access - PCE
Phonebook Access - PSE
Phonebook Access
Headset headset
Message Access Server
Message Notification Server
Message Access Profile
Generic Networking
Generic Audio

原文地址:https://www.cnblogs.com/cb168/p/4785575.html