Third-party Bluetooth Device Integration

1. Introduction

With the mass shipment of locks using the TTLock solution, more and more third-party devices need to control our locks. If the third-party device has an Android or Apple system, it can be supported by our provided SDK. However, many devices do not have an operating system and require us to open some protocols for control. This solution is designed to meet this usage scenario, allowing the door lock to be controlled by a Bluetooth module (without an operating system) to unlock or lock and query the lock status.

1.1 Supported chip models for third-party devices

The following chip models support adding and adjusting Bluetooth broadcast times for third-party devices. Please contact your lock manufacturer/vendor to purchase a lock with the corresponding chip model or request a firmware version upgrade:

SN534-15-1, SN534-16-1, SN503-18-1, SN8534-3-1, SN8534-1-1, SN8503-2-1

2.Operation Procedures

When adding a device, communication is required between the app, the lock, and the third-party Bluetooth device. The third-party Bluetooth device must also support receiving Bluetooth broadcast data. The specific process is as follows:

image-20251103134933405

2.1. Unlocking with third-party devices

image-20251103141314610

2.2. Lockout with third-party devices

image-20251103141619723

2.3. Query lock status

The lock status can be obtained directly from the lock's normal broadcast data. Below is an example of broadcast data:

img

The manufacturer-defined data of type 0xFF contains door lock status information, with the following specific format:

img

Please Note: The lock status can also be queried using the following command.

3. Communication Protocol

3.1. Communication format

Field nameByte countRemark
Sync header20x7F 0x5A
Fixed data 170x05 0x03 0x00 0x00 0x01 0x00 0x01
Command code1When a third-party device sends a command code to the door lock, it fills in the command code; when the door lock returns, it's always 0x54
Fixed data 210xB0
Parameter length1 
ParameterNThe number of bytes indicated by the parameter length field
CRC check1CRC checksum of all preceding fields
Fixed data20x0D 0x0A

Synchronization Header: 2 bytes, fixed at 0x7F 0x5A

Fixed Data 1: 7 bytes, fixed at 0x05 0x03 0x00 0x00 0x01 0x00 0x01

Command Code: 1 byte, see commands below for details

Fixed Data 2: 1 byte, fixed at 0xB0

Data Length: 1 byte, the number of bytes in the following data field

Data: n bytes, the specific number of bytes is indicated by the value of the data length field. The content of the data field needs to be encrypted and decrypted using the AES algorithm, see the appendix for the algorithm.

CRC Checksum: 1 byte, the CRC checksum value of all data from the synchronization header (0x7F 0x5A) to this field, see the appendix for the algorithm.

Example Data Packet: 7F5A0503000001000188B010C18C99218D9912CB9D36CE659678D95CDC0D0A0A

3.2. Communication key between third-party devices and the lock

Fixed AES key:

0x87,0x12,0x35,0xAE,0x45,0x23,0xC9,0xE3,0x3F,0x67,0x34,0x32,0xBD,0xF9,0xA2,0xC9 The device addition process uses the above fixed AES key; other processes use the key generated during the addition process.

 

3.3. Broadcast data

After receiving the command from the App to allow the addition of a device, the lock will broadcast via Bluetooth. The broadcast UUID is 0x1911, and the broadcast manufacturer-defined data is as follows (where the status field is 0x01).:

Byte numberDataRemark
10x06Fixed data
20x01Fixed data
30xXXStatus0x01-Allow adding devices0x02-Devices addition complete
4-90xXXXXXXXXXXXXThe lock's Bluetooth address is listed with the low number first and the high number last.

After adding a third-party device, the broadcast status field changes to 0x02.

Please Note: Third-party Bluetooth devices can search for Bluetooth devices with UUID 0x1911 and manufacturer-defined data starting with 0x06, 0x01, or 0x01 to add the device.

3.4. Communication Commands

3.4.1. Communication commands between third-party Bluetooth devices and door locks

Command code: 0x88

Subcommand code:

Subcommand codeSubcommand Description
0x01Add device
0x02Get Temporary Token
0x03Unlock
0x04Lock
0x05Query lock status

3.4.1.1. Add Devices

A. Request parameters

Field NameByte countRemark
Subcommand Code1Fixed data 0x01
Bluetooth address of third-party device6byte order: low first, high last

B. Response parameters

Field NameByte countRemark
Command code10x88
Subcommand Code10x01
Door lock battery percentage10~100
Operation results10x00 - SuccessSee error code table for other codes.
Permanent Token44-byte integer, Big endian
AES Key16 

3.4.1.2. Get Temporary Token

A. Request parameters

Field NameByte countRemark
Subcommand Code10x02
Bluetooth address of third-party device6Little Endian

 

B. Response parameters

Field NameByte countRemark
Command code10x88
Subcommand Code10x02
Door lock battery percentage10~100
Temporary token44-byte integer,Big endian

3.4.1.3. Unlock

A. Request parameters

Field NameByte countRemark
Subcommand Code10x03
Unlock token4The sum of permanent tokens and temporary tokens,Big endian

B. Response parameters

Field NameByte countRemark
Command code10x88
Subcommand Code10x03
Door lock battery percentage10~100
Operation results10x00 - SuccessSee error code table for other codes.

3.4.1.4. Lock

A. Request parameters

Field NameByte countRemark
Subcommand Code10x04
Lock token4The sum of permanent tokens and temporary tokens, Big endian

B. Response parameters

Field NameByte countRemark
Command code10x88
Subcommand Code10x04
Door lock battery percentage10~100
Operation results10x00 - SuccessSee error code table for other codes.

3.4.1.5. Query lock status

A. Request parameters

Field NameByte countRemark
Subcommand Code10x05

B. Response parameters

Field NameByte countRemark
Command code10x88
Subcommand Code10x05
Door lock battery percentage10~100
Operation results10x00 - SuccessSee error code table for other codes.
Lock state10x00 - Locked0x01 - Unlocked0x02 - Unknown

Note: The lock status can also be obtained through the lock's broadcast data.

 

3.5. Error code table

Error codeDescription
0x0EExpired
0x11Not yet expired
0x13Unknown error
0x1CLock frozen
0x1EDoor locked from the inside
0x02Incorrect token

3.6. Appendix

3.6.1. CRC value calculation method

//================

//8-bit CRC Cheat Sheet

//================

/*

* Description:

* Calculates the CRC result using a fast lookup table method.

* Parameters:

* pData: The array to be calculated for CRC.

* nDataCount: The number of bytes in the array to be calculated for CRC.

* Return Value:

* CRC value.

*/

3.6.2 Example of adding a third-party device

Third-party device data:

MAC address of third-party device: 00-a1-26-66-bf-01

Fixed AES key:0x87,0x12,0x35,0xAE,0x45,0x23,0xC9,0xE3,0x3F,0x67,0x34,0x32,0xBD,0xF9,0xA2,0xC9

Parameters before encryption:0x01,0x00,0xA1,0x26,0x66,0xBF,0x01

Encrypted parameters:0xC1 0x8C 0x99 0x21 0x8D 0x99 0x12 0xCB 0x9D 0x36 0xCE 0x65 0x96 0x78 0xD9 0x5C

CRC checksum:0xDC

Complete data packet:7F5A0503000001000188B010C18C99218D9912CB9D36CE659678D95CDC0D0A

Lock reply data:

-7f-5a-05-03-00-00-01-00-01-54-b0-20-4a-6c-86-90-bd-43-29-c8-e1-8c-75-95-2c-4b-34-10-e8-ec-b9-81-8c-cc-f8-ad-4e-e1-e9-77-8b-89-af-45-f0-0d-0a-

Decrypted parameters:

-88-01-3d-00-1c-de-1a-d0-cb-c2-25-4f-29-6e-a8-ab-71-5f-7a-a9-a5-3f-93-f6-

4.Demo

Third party Bluetooth device integration code:demo