TBluetoothLE

delphi 藍牙技術android

D:\Users\Public\Documents\Embarcadero\Studio\17.0\Samples\Object Pascal\Multi-Device Samples\Device Sensors and Services\Bluetooth\Classic Bluetooth Basic appapp

System.Bluetooth

 Bluetooth Low Energy (BLE)less

小米手環就是BLE4.0,在android手機上用HMBLEComAssistant.apk能夠搜到小米手環。ide

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

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

Samples\Object Pascal\Multi-Device Samples\Device Sensors and Services\Bluetooth\BLEScannercode

 

 藍牙GAP、GATT(Generic Attribute Profile)server

藍牙音箱,經過android、iPhone均可以搜索到。blog

小米藍牙音箱和小米手環的藍牙版本徹底相同嗎?ip

 藍牙耳機:藍牙協議: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

 

相關文章
相關標籤/搜索