Bluetooth

There are many ways to configure the Aqara Bluetooth network. The difference lies in the way to obtain the Bluetooth mac address and modelId (for example, by scanning the broadcast, reading from the QR code, etc.); the data layer can be divided into Bluetooth hub and Bluetooth Sub-Device.

This SDK includes the logical part and UI interface of Aqara device network distribution; the iOS version that the SDK depends on cannot be lower than 11.0
Compiler environment: XCode14.0 or above
Language: Object-C

Integrated SDK

1.Environment Build

The Device Pairing SDK needs to use the Wi-Fi permission function, and the host project needs to add the following Capability:

 Wireless Accessory Configuration

2.Permission Profile

The SDK needs to apply to iOS for the following system permissions:

1.NSCameraUsageDescription Camera access permission (scan the QR code on the device for network configuration). 2.NSLocalNetworkUsageDescription Local network search authority (Device Pairing by LAN) 3.NSLocationWhenInUseUsageDescription Use geographic location permission (mobile phone obtains WiFi name, iOS 13 needs to confirm that the App has enabled the location permission. iOS 14 needs to confirm that the App has enabled the precise location permission. If the WiFi name is still not obtained after the above configuration, the developer needs to deal with it separately, such as Manually enter the WiFi name).

  1. NSBluetoothAlwaysUsageDescription Obtain Bluetooth permission (Device Pairing by Bluetooth).
  2. NSBonjourServicesUse the mDNS service to discover Greenmi devices, and set the service name "_aqara._tcp."

You can quickly add the following configuration in the info.plist file of the host project:

<plist version="1.0">
   <key>NSBonjourServices</key>
   <array>
          <string>_aqara._tcp.</string>
   </array>
   <key>NSCameraUsageDescription</key>
   <string>Allows the app to use the camera to add accessories</string>
   <key>NSHomeKitUsageDescription</key>
   <string>Allow this App to control HomeKit-enabled devices</string>
   <key>NSLocalNetworkUsageDescription</key>
   <string>Need to use local network to discover device information on LAN</string>
   <key>NSLocationWhenInUseUsageDescription</key>
   <string>Need your location information to provide better service</string>
   <key>NSBluetoothAlwaysUsageDescription</key>
   <string>Allow this app to use bluetooth connection</string>
</dict>
</plist>

4.Import SDK

The following SDK needs to be imported in the host project:

  1. LMSmartConnect.framework Bluetooth related API packaging SDK
  2. LMFramework.framework Basic SDK, basic configuration of Aqara, macro definition and encapsulation of general logic.

Resource:

  1. LMFramework.bundle Aqara multilingual files

5.Timing diagram and interface description

Reference header file

#import <LMSmartConnect/LMSmartConnect.h>

It is necessary to confirm that the system Bluetooth permission has been obtained, and call the method to start scanning Bluetooth devices:

- (void)startBluetoothScanDevice:(NSString *)manufacture model:(NSArray *)models macAddress:(NSString *)macAddress completion:(void (^)(CBManagerState state, CBPeripheral *peripheral, NSString *macAddress, NSString *model))completion
Parameter Description
manufacture Equipment manufacturers in the broadcast data (Lumi fixed transmission 4D4C))
models Array of device models that need to be filtered in the broadcast data (obtained from the open platform)
macAddress Specify the Bluetooth address of the device (the broadcast data filters out the corresponding object)

Return parameter description

Parameter Description
state CBManagerState Current Bluetooth status, see Apple documentation
peripheral CBPeripheral Bluetooth object, which needs to be saved for subsequent connection
macAddress Bluetooth address
model Device model
Interface 1

Obtain a bindkey request from AIoT,

/app/v1.0/lumi/dev/bindkey

Request example:

{
 "positionId":  "real2.550691449629310976",
 "appUrl": "https://aiot-rpc.aqara.cn"
}

Return data: |Name|Type |Remark| |----|----|---| |bindKey|string|Network access using bindKey| |controlUnitId|string|Parameters returned by the miot device connected to the network|

Return example:

{
    "code": 0,
    "requestId": "",
    "message": "Success",
    "result": {
        "bindKey": "HVFLFgHgPy56X"
    }
}

For details, refer to the Open Platform Interface Documentation

Interface 2
- (void)startConnectBleWithPeripheral:(NSString *)peripheralId serviceId:(NSString *)serviceId writeCharacteristicId:(NSString *)writeCharacteristicId readCharacteriticId:(NSString *)readCharacteriticId completion:(void (^)(NSError *error))completion
Parameter Description Is it optional
peripheralId peripheral.identifier.UUIDString Must
serviceId The service id of the peripheral Optional
writeCharacteristicId Write value feature id Optional
readCharacteriticId Read value feature id Optional
Interface 3
- (void)startBleAccessToNetWithType:(LMSmartBleConnectType)bleConnectType
                        bindKey:(nullable NSString *)bindKey
                         homeId:(NSString *)homeId
                           ssid:(NSString *)ssid
                       password:(NSString *)password
                  countryDomain:(NSString *)countryDomain
                   deviceDomain:(nullable NSString *)deviceDomain
                     macAddress:(nullable NSString *)macAddress
                     completion:(void (^)(NSError *error))completion
Parameter Description Is it optional
bleConnectType LMSmartBleConnectType Hub/ Sub-Device Must
bindKey Obtained from the Aqara cloud platform API Optional
writeCharacteristicId Write value feature id Optional
readCharacteriticId Read value feature id Optional
Interface 4

Request to AIoT whether the device is registered successfully

dev/bind/query

Request instance:

{
 "bindKey":  "xxxxx.xxxxxx",
}

Return data

Name Type Is it necessary Defaults Remark
code integer Must 0-success, 1-binding, 2-illegal 616 The device model does not support (can be used for cross-order reminder)

Return example:

{
    "code": 0,
    "requestId": "",
    "message": "Success",
    "result": {
        "code": 0
    }
}  

For details, please refer to the Aqara Developer Platform Interface Documentation.

Copyright © 2023 Lumi United Technology Co., Ltd. all right reserved,powered by GitbookFile Modify: 2024-09-27 21:51:47

results matching ""

    No results matching ""