Skip to content

4 History ​

When a smartphone sends a history request command to Sesame5, the device returns the oldest history record stored in Flash.
If you need to delete that record, you must send a delete command after reading it.
(Just reading does not delete it)

Sequence Diagram ​

Mobile Sent Data ​

Read History ​

Byte10
Data0x01item code

item code : SSM2_ITEM_CODE_HISTORY (4)

0x01 : Read the oldest history record (do not delete)

Delete History ​

If you want to delete the read history, send HISTORY_DELETE:

ByteN ~ 0
DatarecordId

item code : SSM2_ITEM_CODE_HISTORY_DELETE
recordId : The history record ID (4 Bytes) obtained when reading

Response from ssm5 ​

When history exists ​

ByteN ~ 3210
Datapayloadresitem_codetype
說明History dataResultCommand IDPush type

type : SSM2_OP_CODE_RESPONSE (0x07)

item code : SSM2_ITEM_CODE_HISTORY(4)

res : CMD_RESULT_SUCCESS (0x00)

Payload structure ​

ByteN ~ 1615 ~ 98 ~ 543 ~ 0
Dataparammech_statuststypeid
説明History tagmech statustimestamphistory typerecord ID (4B)

param ​

Bytevariable1 ~ 0
DataValuetag
NoteUUID etc.History Tag type

History Tag Types ​

TagValueDescription
0x0000NFC CardUnlock with card
0x0001FingerprintUnlock with fingerprint
0x0002PasswordUnlock with password
0x0003FaceUnlock with face
0x0004Palm veinUnlock with palm vein
0x0005TouchPro UUIDTouchPro lock
0x0006Touch UUIDTouch lock
0x0007Open Sensor UUIDOpen Sensor lock
0x0008FacePro UUIDFacePro lock
0x0009Face UUIDFace lock
0x000ARemote UUIDRemote lock/unlock
0x000BRemote nano UUIDRemote nano lock/unlock
0x000CBiz User UUIDBiz lock/unlock
0x000DWeb API User UUIDWeb API lock/unlock
0x000EAndroid User BLE UUIDAndroid BLE lock/unlock
0x000FiOS User BLE UUIDiOS BLE lock/unlock
0x0010Android User Wi-Fi UUIDAndroid IoT lock/unlock
0x0011iOS User Wi-Fi UUIDiOS IoT lock/unlock

When no history exists ​

Byte210
Dataresitem_codetype
NoteResultCommand IDPush type

type : SSM2_OP_CODE_RESPONSE (0x07)

item code : SSM2_ITEM_CODE_HISTORY(4)

res : CMD_RESULT_NOT_FOUND (0x05)

Data Structure (C Definition) ​

c

#pragma pack(1)
union ss5_his_param {
    int8_t data_length;
    int8_t data[32];
};
#pragma pack()

#pragma pack(1)
typedef struct {
    uint32_t id;                    /// 4 Bytes
    uint8_t type;                   /// 1 Bytes
    uint32_t ts;                    /// 4 Bytes
    mech_status_t mech_status;      /// 7 Bytes
    union ss5_his_param param;      /// 32 Bytes
} ssm_history;                      /// 4+1+4+7+32 = 48 Bytes
#pragma pack()

iOS,Android,ESP32 Example ​

Android Example ​

kotlin
private fun readHistoryCommand() {
    if (isReadHistoryCommandRunning) {
        L.d("hcia", "[ss5][his][read] readHistoryCommand is already running")
        return
    }
    val isConnectNET = isInternetAvailable()
    sendCommand(SesameOS3Payload(SesameItemCode.history.value, byteArrayOf(0x01)), DeviceSegmentType.cipher) { res -> // 01: 从设备读取最旧的历史记录
        L.d("hcia", "[ss5][his][ResultCode]:" + res.cmdResultCode)
        val hisPaylaod = res.payload
        if (res.cmdResultCode == SesameResultCode.success.value) {
            // 改为 uuid 格式的 hisTag, APP不再兼容旧固件的历史记录, 若有客诉历史记录问题, 请升级锁的固件。
            if (isConnectNET && !isConnectedByWM2) {
                CHAccountManager.postSS5History(deviceId.toString().uppercase(), hisPaylaod.toHexString()) {
                    // 成功上传历史记录到云端后, 通过蓝牙删除这条历史记录, SS5固件会在它的Flash里删除掉这条历史记录。
                    val recordId = hisPaylaod.sliceArray(0..3)
                    it.onSuccess {
                        L.d("hcia", "[+]SSM2_ITEM_CODE_HISTORY_DELETE: ${recordId.toBigLong().toInt()}")
                        sendCommand(SesameOS3Payload(SesameItemCode.SSM2_ITEM_CODE_HISTORY_DELETE.value, recordId), DeviceSegmentType.cipher) { res ->
                            L.d("hcia", "[-]SSM2_ITEM_CODE_HISTORY_DELETE: ${res.cmdResultCode}")
                        }
                    }
                    it.onFailure { exception ->
                        L.d("hcia", "[ss5][history]postSS5History: $exception")
                    }
                }
            }
        }
        isReadHistoryCommandRunning = false
    }
}

iOS Example ​

swift
    func readHistoryCommand(_ result: @escaping (CHResult<CHEmpty>))  {
        L.d("[ss5][history] readHistoryCommand <=")
        URLSession.isInternetReachable { isInternetReachable in
//            L.d("[ss5][history] 連網?",isInternetReachable)
            self.sendCommand(.init( .history, "01".hexStringtoData())) { (result) in // 01: 从设备读取最旧的历史记录
                if result.cmdResultCode == .success {
                    guard isInternetReachable && !self.isConnectedByWM2 else { return }
                    self.postProcessHistory(result.data.copyData) { res in
                        if case .success(_) = res  {
                            let recordId = result.data.copyData[0...3].copyData
                            self.sendCommand(.init(SesameItemCode.historyDelete, recordId)) { response in
                                if response.cmdResultCode == .success  { L.d("[ss5][history]歷史删除成功") }
                            }
                        }
                    }
                } else {
                    (self.delegate as? CHSesame5Delegate)?.onHistoryReceived(device: self, result: .failure(self.errorFromResultCode(result.cmdResultCode)))
                    self.isHistory = false
                }
            }
        }
    }

ESP Example ​

c
// todo