Gateway Server Client User Manual
Contents
- 1 Overview
- 2 Gateway Management
- 3 Lock Management
- 4 Remote Unlock/Lock
- 5 Lock Status Query and Calibration
- 6 WiFi Lock Status Query
- 7 Passcode Management
- 8 IC Card Management
- 9 Fingerprint Management
- 10 Face Management
- 11 Palm Vein Management
- 12 QR Code Management
- 13 Lock Settings
- 14 Matter Configuration (G6 Gateway)
- Appendix A Entity Classes
1 Overview
1.1 Introduction
The gateway-server-client JAR provides the com.ttlock.gateway.client.GatewayServerClient class. It sends HTTP requests to the on premise gateway server (gateway-server-on-premise) to query connected gateways and operate locks remotely via gateways (unlock, lock, manage passcodes/IC cards/fingerprints/faces/palm veins/QR codes, modify lock settings, etc.).
General notes:
- The
lockDataparameter of all methods must be generated by the APP SDK on premise after adding a lock. - Before operating a lock remotely, call
addLockto add the lock data to the gateway server, and the lock must be within the Bluetooth range of a gateway. - All time parameters (startDate, endDate, etc.) are timestamps in milliseconds.
- Unless otherwise specified, methods have no return value; a call without exception means the operation succeeded. On failure, a
GatewayExceptionis thrown (with error code, error message and HTTP status code). - Methods with the
WithSelectedGatewaysuffix operate via a specified gateway MAC; methods without the suffix let the server automatically select the gateway with the best RSSI.
1.2 Initialization
GatewayServerClient client = new GatewayServerClient("192.168.8.178", 8888, "1234abcd");
String lockData = "xxx"; // lockData is obtained from TTLock SDK on premise
client.addLock(lockData); // add lockData to gateway server
client.unlock(2340, lockData); // if no exception is thrown, the unlock is successfulConstructor parameters:
| Name | Type | Description |
|---|---|---|
| ip | String | The host IP of the gateway server |
| port | Int | The HTTP server port of the gateway server, 8888 by default, can be configured in the gateway server's config.properties by the http_server_port property |
| secret | String | The secret of the gateway server, 1234abcd by default, can be configured in the gateway server's config.properties by the secret property. The gateway server must be restarted for the new configuration to take effect |
1.3 Common Parameters
The following parameters are shared by multiple methods and are not repeated in later sections:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data, generated by the APP SDK on premise |
| gatewayMac | String | Gateway MAC address, e.g. B4:89:1F:9E:D6:D1 |
| uid | Int | User ID, identifies the operator / unlock record |
| startDate | Long | Valid start time, timestamp in milliseconds |
| endDate | Long | Valid end time, timestamp in milliseconds |
| cyclicConfig | String | Recurring time period, a JSON array, can be null. For example: [{"weekDay":1,"startTime":480,"endTime":1080},{"weekDay":2,"startTime":480,"endTime":1080}] means valid from 8:00 to 18:00 on Mondays and Tuesdays. weekDay ranges from 1-7 for Monday to Sunday; startTime/endTime are minutes of the day (e.g. 480 for 8:00) |
1.4 Exceptions and Error Codes
All method calls fail with a com.ttlock.gateway.exception.GatewayException (a subclass of RuntimeException). Use getErrorCode(), getErrorMsg() and getHttpStatusCode() to get the error details.
Error codes:
| Error Code | Description |
|---|---|
| -1 | Operation failure (or means "no") |
| -1004 | MAC format error |
| -1009 | Invalid command |
| -1021 | The IC card does not exist |
| -1023 | The fingerprint does not exist |
| -2018 | Permission denied |
| -3002 | The lock is not connected to any gateway |
| -3003 | Gateway is busy, please try later |
| -3004 | Lock info not found |
| -3005 | The link between gateway and lock is broken |
| -3006 | Passcode length invalid, should be 4-9 |
| -3007 | Passcode exists |
| -3008 | Passcode does not exist |
| -3009 | No free memory |
| -3015 | This record does not exist |
| -3036 | WiFi lock offline |
| -3049 | This face exists |
| -4056 | Lack of storage space and failure of operation |
| -4082 | Auto locking period invalid |
| -7000 | Invalid lock data |
| -7001 | Invalid client secret, should be the same as the gateway server's secret |
2 Gateway Management
2.1 List Gateways
public List<Gateway> listGateway()
public List<Gateway> listGatewayByUid(Integer uid)
public List<Gateway> listGatewayByLock(String lockData)listGateway: list gateways of all users.listGatewayByUid: list gateways of a user.listGatewayByLock: list gateways that can connect to a lock (with connection RSSI).
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Integer | User ID |
| lockData | String | Lock data |
Return: List<Gateway> gateway list, see Appendix A for Gateway fields.
2.2 List Locks Connected to a Gateway
public List<Lock> listLockByGateway(String gatewayMac)List locks that connect to a gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | Gateway MAC address |
Return: List<Lock> lock list, see Appendix A for Lock fields.
2.3 List Lock-Gateway Connections
public List<DeviceRelation> listDeviceRelation()List the connect relations of all locks and their best-RSSI gateways. No parameters.
Return: List<DeviceRelation> connection list (lockMac, gatewayMac, rssi), see Appendix A for fields.
2.4 Delete Gateway
public void deleteGateway(String gatewayMac)Delete a gateway from the gateway server.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | Gateway MAC address |
2.5 Transfer Gateway
public void transferGateway(Integer fromUid, Integer toUid, List<String> gatewayMacList)Transfer gateways to another user.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| fromUid | Integer | The original user ID |
| toUid | Integer | The target user ID |
| gatewayMacList | List<String> | List of gateway MACs to be transferred |
2.6 Query Gateway Online/Busy Status
public boolean queryGatewayOnlineStatus(String gatewayMac)
public boolean queryGatewayBusyStatus(String gatewayMac)queryGatewayOnlineStatus: query whether the gateway is online.queryGatewayBusyStatus: query whether the gateway is busy.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | Gateway MAC address |
Return: Boolean, true-online/busy, false-offline/idle.
2.7 Set Gateway Upgrade Mode
public void setGatewayUpgradeMode(String gatewayMac)Set the gateway into firmware upgrade mode.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | Gateway MAC address |
3 Lock Management
3.1 Add Lock
public void addLock(String lockData)
public void addLock(Integer uid, String lockData)Add lock data to the gateway server. The lock can be operated remotely via gateways only after being added. The overload with uid also assigns the admin user ID of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Integer | The admin user ID of the lock |
| lockData | String | Lock data |
3.2 Transfer Lock
public void transferLock(Integer fromUid, Integer toUid, List<String> lockMacList)Transfer locks to another user.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| fromUid | Integer | The original user ID |
| toUid | Integer | The target user ID |
| lockMacList | List<String> | List of lock MACs to be transferred |
3.3 Filter Out Online Locks
public List<String> filterOutOnlineLocks(List<String> lockMacList)Filter out online locks from the given lock MAC list. A lock is online if any online gateway discovered it in the last 30 minutes; a WiFi lock is also online if it is connected to the WiFi lock server.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockMacList | List<String> | List of lock MACs to be checked |
Return: List<String> MAC list of online locks.
4 Remote Unlock/Lock
4.1 Remote Unlock
public void unlock(int uid, String lockData)Unlock the lock remotely via gateway (as a normal user).
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Int | User ID of the user who unlocks the lock, identifies the unlock record |
| lockData | String | Lock data |
4.2 Remote Unlock with Selected Gateway
public void unlockWithSelectedGateway(String gatewayMac, int uid, String lockData)Unlock the lock remotely with a selected gateway (as a normal user).
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| uid | Int | User ID of the user who unlocks the lock |
| lockData | String | Lock data |
4.3 Remote Unlock by Administrator
public void unlockByAdministrator(int uid, String lockData)Unlock the lock remotely via gateway as an administrator.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Int | User ID of the user who unlocks the lock |
| lockData | String | Lock data |
4.4 Remote Unlock by Administrator with Selected Gateway
public void unlockByAdministratorWithSelectedGateway(String gatewayMac, int uid, String lockData)Unlock the lock remotely with a selected gateway as an administrator.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| uid | Int | User ID of the user who unlocks the lock |
| lockData | String | Lock data |
4.5 Remote Lock
public void lock(int uid, String lockData)Lock the lock remotely via gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Int | User ID of the operator |
| lockData | String | Lock data |
4.6 Emergency Unlock
public void emergencyUnlock(int uid, String lockData)Unlock the lock remotely for emergency. Auto lock will be disabled after unlocking (the lock remains unlocked).
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Int | User ID of the user who unlocks the lock |
| lockData | String | Lock data |
4.7 Emergency Lock
public void emergencyLock(int uid, String lockData, int seconds)Lock the lock remotely for emergency. The lock will be locked and auto lock will be turned on.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Int | User ID of the operator |
| lockData | String | Lock data |
| seconds | Int | The lock will auto relock after the specified seconds; set 0 to turn off auto lock |
5 Lock Status Query and Calibration
5.1 Query Lock Datetime
public long queryDatetimeOfLock(String lockData)Query the current datetime of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Long, datetime of the lock, Unix timestamp in milliseconds.
5.2 Calibrate Lock Datetime
public void calibrateDatetimeOfLock(String lockData)Calibrate the datetime of the lock to the server's current time.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
5.3 Query Lock Battery Level
public int queryElectricQuantityOfLock(String lockData)Query the battery level of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Int, battery level percentage, 1-100.
5.4 Query Lock Open State
public int queryOpenStateOfLock(String lockData)Query the open state of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Int, 0-locked, 1-unlocked, 2-unknown.
5.5 Query Open State of Lock and Door
public JSONObject queryOpenStateOfLockAndDoor(String lockData)Query the open state of the lock and the door sensor state (the lock must support a door sensor).
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: JSONObject with the following fields:
| Field | Type | Description |
|---|---|---|
| state | Int | Open state of lock: 0-locked, 1-unlocked, 2-unknown |
| sensorState | Int | Open state of door: 0-open, 1-closed, 2-unknown |
5.6 Query Lock Freeze Status
public int queryFreezeStatusOfLock(String lockData)Query the freeze status of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Int, 0-not frozen, 1-frozen.
5.7 Query Accessory Battery Level
public JSONObject queryAccessoryBatteryLevel(int uid, String lockData, String accessoryMac, int type)
public JSONObject queryAccessoryBatteryLevelWithSelectedGateway(String gatewayMac, int uid, String lockData, String accessoryMac, int type)Query the battery level of a lock accessory (wireless keypad, remote, door sensor). The overload with the WithSelectedGateway suffix operates via a specified gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| uid | Int | User ID of the operator |
| lockData | String | Lock data |
| accessoryMac | String | Accessory MAC address |
| type | Int | Lock accessory type: 1-wireless keypad, 2-remote, 3-door sensor |
Return: JSONObject containing the accessory battery level information.
6 WiFi Lock Status Query
6.1 Query WiFi Lock Online Status
public boolean queryWifiLockOnlineStatus(String lockData)Query whether the WiFi lock is online (connected to the WiFi lock server).
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Boolean, true-online, false-offline.
6.2 Query WiFi Lock Busy Status
public boolean queryWifiLockBusyStatus(String lockData)Query whether the WiFi lock is busy. Throws GatewayException (error code -3036) if the lock is offline.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Boolean, true-busy, false-idle.
6.3 Query WiFi Lock RSSI
public int queryWifiLockRssi(String lockData)Query the network RSSI of the WiFi lock. Throws GatewayException (error code -3036) if the lock is offline.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
Return: Int, network RSSI.
7 Passcode Management
7.1 Add Custom Passcode
public void addPasscode(String lockData, String passcode, Long startDate, Long endDate)
public void addPasscode(String lockData, String passcode, Long startDate, Long endDate, String cyclicConfig)
public void addPasscodeWithSelectedGateway(String gatewayMac, String lockData, String passcode, Long startDate, Long endDate)
public void addPasscodeWithSelectedGateway(String gatewayMac, String lockData, String passcode, Long startDate, Long endDate, String cyclicConfig)Add a custom passcode to the lock. The overloads with cyclicConfig support recurring time periods; the overloads with the WithSelectedGateway suffix operate via a specified gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| passcode | String | Passcode to be added, 4-9 digits |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
7.2 Delete Passcode
public void deletePasscode(String lockData, String passcode)
public void deletePasscodeWithSelectedGateway(String gatewayMac, String lockData, String passcode)Delete a passcode from the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| passcode | String | Passcode to be deleted |
7.3 Change Passcode
public void changePasscode(String lockData, String passcode, String newPasscode, Long startDate, Long endDate)
public void changePasscode(String lockData, String passcode, String newPasscode, Long startDate, Long endDate, String cyclicConfig)
public void changePasscodeWithSelectedGateway(String gatewayMac, String lockData, String passcode, String newPasscode, Long startDate, Long endDate)
public void changePasscodeWithSelectedGateway(String gatewayMac, String lockData, String passcode, String newPasscode, Long startDate, Long endDate, String cyclicConfig)Change an existing passcode of the lock (both the passcode value and the valid period can be changed). The overloads with cyclicConfig support recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| passcode | String | The passcode to be changed |
| newPasscode | String | The new passcode |
| startDate | Long | Valid start time of the new passcode |
| endDate | Long | Valid end time of the new passcode |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
7.4 Change Admin Passcode
public String changeSuperPasscode(String lockData, String newPasscode)Change the admin passcode of the lock. On success, returns the lock data containing the new admin passcode. The developer's system should save the new lock data for subsequent operations.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| newPasscode | String | The new admin passcode |
Return: String, new lockData with the new admin passcode.
8 IC Card Management
8.1 Add IC Card
public void addIdentityCard(String lockData, String cardNumber, Long startDate, Long endDate)
public void addIdentityCard(String lockData, String cardNumber, Long startDate, Long endDate, String cyclicConfig)
public void addIdentityCardWithSelectedGateway(String gatewayMac, String lockData, String cardNumber, Long startDate, Long endDate)
public void addIdentityCardWithSelectedGateway(String gatewayMac, String lockData, String cardNumber, Long startDate, Long endDate, String cyclicConfig)Add an IC card to the lock. The overloads with cyclicConfig support recurring time periods; the overloads with the WithSelectedGateway suffix operate via a specified gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| cardNumber | String | Number of the card to be added |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
8.2 Delete IC Card
public void deleteIdentityCard(String lockData, String cardNumber)
public void deleteIdentityCardWithSelectedGateway(String gatewayMac, String lockData, String cardNumber)Delete an IC card from the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| cardNumber | String | Number of the card to be deleted |
8.3 Change Valid Period of IC Card
public void changePeriodOfIdentityCard(String lockData, String cardNumber, Long startDate, Long endDate)
public void changePeriodOfIdentityCard(String lockData, String cardNumber, Long startDate, Long endDate, String cyclicConfig)Change the valid period of an existing IC card in the lock. The overload with cyclicConfig supports recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| cardNumber | String | Number of the card to be changed |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
8.4 Compress Card Number
public static String compressCardNumber(String cardNumber)Static utility method. Compress an 8-byte card number into a 4-byte card number (the high bytes and low bytes are added together). If the card number is no more than 4 bytes, it is returned unchanged.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| cardNumber | String | 8-byte card number |
Return: String, 4-byte card number.
8.5 Reverse Card Number
public static String reverseCardNumber(String cardNumber)Static utility method. Reverse the byte order of a card number. The card numbers read by card readers of different brands may differ because they are displayed in different byte order (big endian or little endian); use this method to convert.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| cardNumber | String | Card number |
Return: String, the card number with reversed byte order.
9 Fingerprint Management
9.1 Add Fingerprint
public String addFingerprint(String lockData, String fingerprintData, Long startDate, Long endDate)
public String addFingerprint(String lockData, String fingerprintData, Long startDate, Long endDate, String cyclicConfig)Add a fingerprint to the lock. The overload with cyclicConfig supports recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| fingerprintData | String | Fingerprint data (obtained from a fingerprint collector / APP SDK) |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
Return: String, the fingerprint number (fingerprintNumber) assigned on success, used for subsequent delete/change operations.
9.2 Delete Fingerprint
public void deleteFingerprint(String lockData, String fingerprintNumber)Delete a fingerprint from the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| fingerprintNumber | String | Number of the fingerprint to be deleted |
9.3 Change Valid Period of Fingerprint
public void changePeriodOfFingerprint(String lockData, String fingerprintNumber, Long startDate, Long endDate)
public void changePeriodOfFingerprint(String lockData, String fingerprintNumber, Long startDate, Long endDate, String cyclicConfig)Change the valid period of an existing fingerprint in the lock. The overload with cyclicConfig supports recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| fingerprintNumber | String | Number of the fingerprint to be changed |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
10 Face Management
10.1 Add Face
public String addFace(String lockData, String featureData, Long startDate, Long endDate)
public String addFace(String lockData, String featureData, Long startDate, Long endDate, String cyclicConfig)Add face feature data to the lock. The overload with cyclicConfig supports recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| featureData | String | Face feature data |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
Return: String, the face number (faceNumber) assigned on success, used for subsequent delete/change operations.
10.2 Add Face with Photo URL
public String addFaceWithPhotoUrl(String lockData, String photoUrl, Long startDate, Long endDate, String cyclicConfig)Add a face by a face photo URL; the server extracts the face feature. The photo must meet the lock's requirements (size, resolution, format), which can be queried via the faceImageSize, faceImageHeight, faceImageWidth and faceImageType fields returned by TTLockUtil.getLockInfo.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| photoUrl | String | Face photo URL |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
Return: String, the face number (faceNumber) assigned on success.
10.3 Delete Face
public void deleteFace(String lockData, String faceNumber)Delete a face from the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| faceNumber | String | Number of the face to be deleted |
10.4 Change Valid Period of Face
public void changePeriodOfFace(String lockData, String faceNumber, Long startDate, Long endDate)
public void changePeriodOfFace(String lockData, String faceNumber, Long startDate, Long endDate, String cyclicConfig)Change the valid period of an existing face in the lock. The overload with cyclicConfig supports recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| faceNumber | String | Number of the face to be changed |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
11 Palm Vein Management
11.1 Clear Palm Veins
public void clearPalmVein(String lockData)Clear all palm veins of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
11.2 Delete Palm Vein
public void deletePalmVein(String lockData, String number)Delete a palm vein from the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| number | String | Number of the palm vein to be deleted |
11.3 Change Valid Period of Palm Vein
public void changePeriodOfPalmVein(String lockData, String number, Long startDate, Long endDate)
public void changePeriodOfPalmVein(String lockData, String number, Long startDate, Long endDate, String cyclicConfig)Change the valid period of an existing palm vein in the lock. The overload with cyclicConfig supports recurring time periods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| number | String | Number of the palm vein to be changed |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
12 QR Code Management
12.1 Add QR Code
public void addQrCode(String lockData, String qrCodeNumber, Long startDate, Long endDate, String cyclicConfig)
public void addQrCodeWithSelectedGateway(String gatewayMac, String lockData, String qrCodeNumber, Long startDate, Long endDate, String cyclicConfig)Add a QR code number to the lock (authorize the QR code of this number to unlock). The QR code content can be generated by TTLockUtil.getQrCodeData. The overload with the WithSelectedGateway suffix operates via a specified gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| qrCodeNumber | String | QR code number to be added |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
12.2 Delete QR Code
public void deleteQrCode(String lockData, String qrCodeNumber)
public void deleteQrCodeWithSelectedGateway(String gatewayMac, String lockData, String qrCodeNumber)Delete a QR code number from the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| qrCodeNumber | String | QR code number to be deleted |
12.3 Change Valid Period of QR Code
public void changePeriodOfQrCode(String lockData, String qrCodeNumber, Long startDate, Long endDate, String cyclicConfig)
public void changePeriodOfQrCodeWithSelectedGateway(String gatewayMac, String lockData, String qrCodeNumber, Long startDate, Long endDate, String cyclicConfig)Change the valid period of an existing QR code number in the lock. The overload with the WithSelectedGateway suffix operates via a specified gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | The selected gateway MAC |
| lockData | String | Lock data |
| qrCodeNumber | String | QR code number to be changed |
| startDate | Long | Valid start time |
| endDate | Long | Valid end time |
| cyclicConfig | String | Recurring time period, see 1.3 Common Parameters |
13 Lock Settings
13.1 Update Lock Setting
public void updateSetting(String lockData, int type, int value)Update lock settings, including privacy lock, tamper alert, reset button, opening direction, double verification, etc.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| type | Int | Setting item: 2-privacy lock, 3-tamper alert, 4-reset button, 7-opening direction, 12-double verification, 20-secure M1 card, 21-power saving care mode |
| value | Int | Setting value: 1-on, 2-off; opening direction: 1-left, 2-right |
13.2 Set Lock Volume
public void setLockVolume(String lockData, int volume)Set the volume of the lock's prompt sound.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| volume | Int | Volume level: 1-5; 0-turn off the prompt sound |
13.3 Set Auto Lock Time
public void setAutoLockTime(String lockData, int seconds)Set the auto lock delay of the lock.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| seconds | Int | The lock will auto relock after the specified seconds after unlocking; set 0 to turn off auto lock |
13.4 Config Passage Mode
public void configPassageMode(String lockData, int passageMode, String passageModeConfig)
public void configPassageMode(String lockData, int passageMode, String passageModeConfig, Integer autoUnlock)
public void configPassageMode(String lockData, int passageMode, int startDate, int endDate, int isAllDay, String weekDays)Configure passage mode. The lock keeps unlocked during the configured time periods until locked manually. The first two overloads support multiple time periods per weekday; the third overload configures a single time period.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| passageMode | Int | Passage mode: 1-on, 2-off |
| passageModeConfig | String | Valid time periods for each day of the week, a JSON array, for example: [{"weekDay":1,"startTime":480,"endTime":1080},{"weekDay":2,"startTime":420,"endTime":1020}] means 8:00-18:00 on Mondays and 7:00-17:00 on Tuesdays. startTime/endTime are minutes of the day; both 0 means all day |
| autoUnlock | Integer | Auto unlock: 1-on, 2-off. If on, the lock unlocks automatically when a passage period starts |
| startDate | Int | Start time of the period, minutes of the day, e.g. 480 for 8:00 |
| endDate | Int | End time of the period, minutes of the day, e.g. 1080 for 18:00 |
| isAllDay | Int | Whether all day: 1-yes, 2-no. startDate/endDate are ignored if all day |
| weekDays | String | Effective weekdays, a JSON array, e.g. [1,7] means Monday and Sunday |
13.5 Config Working Mode
public void configWorkingMode(String lockData, int workingMode, String workingModeList)Set the working mode of the lock. During working periods the lock can be unlocked by ekey, passcode, etc.; outside working periods the lock automatically enters freeze mode, only the mechanical key works and all other unlock methods are disabled.
Tip: to freeze/unfreeze the lock, use
configWorkingMode(lockData, 2, null)/configWorkingMode(lockData, 1, null)instead of the deprecatedfreezeLock/unfreezeLockmethods.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| workingMode | Int | Working mode: 1-work all day, 2-not work all day, 3-custom |
| workingModeList | String | Custom working time configuration, required when workingMode is 3. A JSON array, element format: {"isAllDay":1-yes 2-no, "startTime":minutes of the day, "endTime":minutes of the day, "weekDays":[1-7]}, for example: [{"isAllDay":2,"startTime":480,"endTime":1080,"weekDays":[1,2,3,4,5]}] means working from 8:00 to 18:00 every Monday to Friday |
13.6 Freeze/Unfreeze Lock (Deprecated)
@Deprecated
public void freezeLock(String lockData)
@Deprecated
public void unfreezeLock(String lockData)Freeze/unfreeze the lock. Deprecated (@Deprecated), use configWorkingMode(lockData, 2, null) to freeze and configWorkingMode(lockData, 1, null) to unfreeze instead.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
13.7 Set Access Name
public void setAccessName(String lockData, String number, AccessType accessType, String name)Set a name for an access credential on the lock (card number, face number, etc.), so that the user can be identified in unlock records.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| lockData | String | Lock data |
| number | String | Credential number (card number, face number, etc.) |
| accessType | AccessType | Credential type enum, see Appendix A |
| name | String | Name |
14 Matter Configuration (G6 Gateway)
14.1 Configure Matter Lock
public void configureMatterLockForG6Gateway(int uid, String gatewayMac, String lockData)Configure the lock into the Matter network of a G6 gateway. After configuration, the lock can be unlocked via Matter.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| uid | Int | User ID used for Matter unlocking |
| gatewayMac | String | G6 gateway MAC address |
| lockData | String | Lock data |
14.2 Delete Matter Lock
public void deleteMatterLockForG6Gateway(String gatewayMac)Delete the configured Matter lock from the G6 gateway.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | G6 gateway MAC address |
14.3 Set Matter Pairing Mode
public void setMatterPairingMode(String gatewayMac)Set the G6 gateway into Matter pairing mode.
Parameter Description:
| Name | Type | Description |
|---|---|---|
| gatewayMac | String | G6 gateway MAC address |
Appendix A Entity Classes
Gateway (com.ttlock.gateway.entity.Gateway)
| Field | Type | Description |
|---|---|---|
| mac | String | Gateway MAC address |
| name | String | Gateway name |
| version | Int | Gateway version |
| uid | Integer | Admin user ID |
| aesKey | String | AES key |
| rssi | Int | Connection RSSI between the gateway and the lock (returned by listGatewayByLock) |
| isOnline | Boolean | Whether the gateway is online |
Lock (com.ttlock.gateway.entity.Lock)
| Field | Type | Description |
|---|---|---|
| mac | String | Lock MAC address |
| rssi | Int | Connection RSSI between the gateway and the lock |
DeviceRelation (com.ttlock.gateway.entity.DeviceRelation)
| Field | Type | Description |
|---|---|---|
| gatewayMac | String | Gateway MAC address |
| lockMac | String | Lock MAC address |
| rssi | Int | Connection RSSI between the gateway and the lock |
AccessType (com.ttlock.gateway.param.AccessType)
Access credential type enum:
| Enum | Code | Description |
|---|---|---|
| FINGERPRINT | 1 | Fingerprint |
| CARD | 2 | IC card |
| WIRELESS_KEY | 3 | Wireless key |
| FACE | 4 | Face |
| PALM_VEIN | 5 | Palm vein |
| PASSWORD | 6 | Passcode |
| QR_CODE | 7 | QR code |
