1. 门锁摄像头扫码配网
设备侧需自行完成门锁摄像头扫码解析小程序二维码的功能,具体如下:
1.1 启动小程序,选择手动添加设备,确认设备重置后,选择家庭 Wi-Fi 并输入密码,则可使用摄像头扫描小程序生成的配网二维码,其中二维码解析后的格式如下:
内容格式:len str len str len str。其中 len:2个字符,代表紧随内容 utf-8 解码的长度,str 顺序:ssid、password、token。
示例:
以 Tencent-wifi,密码为l,token 为 v3_00d……为例,设备侧需要解析的字符串为:
其对应的3个字段如下:
{ "SSID": "Tencent-wifi","password": "l","token": "v3_00d02b0248546d5a5fbf95a5812e4" }
1.2 设备侧解析完 Wi-Fi ssid 和密码后,自行完成联网操作。
1.4 在确认初始化接口返回成功且确保设备上线后,调用 iv_ad_send_bind_info() 配网接口,上报上述配网 token。
1.5 上报成功后,刷新小程序主页面即可看到刚添加的设备。
2. 语音对讲
设备对接协议:设备到小程序上行仅支持 AAC,小程序到设备下行支持 AAC 16K 采样率或者设置任意采样率的 PCM,但下行 PCM 不支持小程序回音消除,推荐使用 AAC 16K。
采样率:为了有更好的延时效果,设备到小程序的 AAC 格式请设置为 8K 采样率以上。
相关信令。
3. 云存回放
购买云存储,需要通过 云 API 后台操作,为设备配置云存储套餐。
设备端对接设备端 SDK,某一个事件发生时,通过事件上报接口 iv_cs_event_start() 或者 iv_cs_event_directly_report() 向控制台后台传入事件 ID、图片,并根据回调进行音视频流推送。
云存储模块说明
事件类型:目前支持事件类型如下表,注意 ID 和事件名称的对应关系,后续将持续拓展。
事件类型 | 事件 ID |
有人按门铃 | event ID = 3 |
撬锁告警 | event ID = 4 |
密码/指纹错误冻结告警 | event ID = 5 |
胁迫告警 | event ID = 6 |
徘徊告警 | event ID = 7 |
开门通知 | event ID = 8 |
关门通知 | event ID = 9 |
指纹禁试告警 | event ID = 10 |
密码禁试告警 | event ID = 11 |
卡片禁试告警 | event ID = 12 |
人脸禁试告警 | event ID = 13 |
逗留侦测 | event ID = 14 |
系统禁试告警 | event ID = 15 |
假锁告警 | event ID = 16 |
防遮挡告警 | event ID = 17 |
4. 消息上报
设备端对接设备端 SDK:当事件发生时,设备端通过 iv_msg_send_notice()传入通知 ID 到控制台后台,进行消息模板匹配,将通知参数传入小程序 {{time1.DATA}}
{{enum_string2.DATA}} 后,即可进行消息通知推送。
通知类型:目前支持通知类型如下表,注意 ID 和通知的对应关系,后续将持续拓展。通知将显示在小程序设备详情页中,保存有效期30天。
通知类型 | 通知 ID |
开门通知 | notice ID = 1 |
关门通知 | notice ID = 2 |
忘拔钥匙 | notice ID = 3 |
反锁 | notice ID = 4 |
低电量告警 | notice ID = 5 |
有人按门铃 | notice ID = 6 |
钥匙开门 | notice ID = 7 |
临时密码开门 | notice ID = 8 |
门未关提醒 | notice ID = 9 |
未上锁提醒 | notice ID = 10 |
门虚掩提醒 | notice ID = 11 |
未知情况 | notice ID = 12 |
说明:
设备端通过 iv_msg_send_notice(notice_id:1,ext:{unlock_type: xx})上报开门通知。不传入 unlock_type,消息显示为“开门通知”;传入unlock_type,消息显示对应的 unlock_type。unlock_type 有以下几种:
unlock_type | 通知 |
1 | 密码开门 |
2 | 人脸开门 |
3 | 指纹开门 |
4 | 卡片开门 |
5 | 门内开锁 |
6 | APP蓝牙开门 |
7 | 指纹+密码开锁 |
8 | 人脸+指纹开锁 |
9 | 人脸+密码开锁 |
设备端通过 iv_msg_send_notice(notice_id:12,ext:{unknown_info_id: xx})上报消息。不传入 unknown_info_id,消息显示为“未知情况”;传入 unknown_info_id,消息显示 id 对应的消息通知。unknown_info_id 有以下几种:
unknown_info_id | 通知 |
1 | 锁舌无法伸出告警 |
2 | 锁舌无法收回告警 |
3 | 防遮挡告警 |
4 | 布防告警 |
5 | 假期模式关闭告警 |
6 | 假锁告警 |
5. 落锁状态
设备端对接设备端 SDK,通过 mqtt 消息上报“落锁状态”属性物模型,同步门锁开关信息。
物模型模块介绍。
6. 远程解锁
设备端对接设备端 SDK,通过 SDK 接收到服务器下发的远程解锁行为物模型,接收解锁行为通知后,开锁指令下发成功,待小程序获取到落锁状态物模型由“已落锁”转为“未落锁”,则说明锁已开,提示用户“开锁成功”。
7. 电池电量信息上报
设备端对接设备端 SDK,通过上报“电池电量”属性物模型,同步门锁电量信息。
8. 临时密码解锁
原理:RFC4226
perio:密码有效期间隔,30 秒一个。
将设备 PSK 密钥按照 base64 解码后得到原始二进制,得到 secret。
将时间戳除以 period,向下取整,得到 counter。
对 counter 计算 sha1。
将 sha1 使用 dynamic truncation 计算为6位数字。
代码参考
设备端需自行实现 RFC4226 算法, 设备端在用户输入临时密码时,获取输入密码对应的时间戳后,通过 RFC4226 算法生成密码,并与输入密码进行逐一比对,至对比成功则可正常开锁。
注意:
当门锁状态显示已开锁时,临时密码不可使用。
9. 主动唤醒
实现流程如下:
1.1 小程序获取唤醒状态物模型的值为0,即休眠状态,则会下发唤醒门锁行为。
1.2 设备 Wi-Fi 收到唤醒命令,唤醒主控。待主控启动,调用 IoT Video SDK,待初始化成功后,设备 Wi-Fi 上报唤醒状态为“唤醒状态”。
1.3 小程序获取唤醒状态为“唤醒状态”时,出图显示门锁实况。
10. 相关物模型
导入相关物模型:
{"version": "1.0","profile": {"ProductId": "OSO00VC9U8","CategoryId": "595"},"properties": [{"id": "sensitivity","name": "灵敏度","desc": "人体移动监测灵敏度","mode": "rw","define": {"type": "enum","mapping": {"0": "低","1": "中","2": "高"}},"required": false},{"id": "battery_percentage","name": "电池电量","desc": "-1表示未获取到电量","mode": "rw","define": {"type": "int","min": "-1","max": "100","start": "0","step": "1","unit": "百分比"},"required": false},{"id": "volume","name": "音量","desc": "","mode": "rw","define": {"type": "enum","mapping": {"0": "静音","1": "低","2": "中","3": "高"}},"required": false},{"id": "wakeup_state","name": "唤醒状态","desc": "设备主动上报是否处于唤醒状态","mode": "r","define": {"type": "bool","mapping": {"0": "休眠状态","1": "唤醒状态"}},"required": false},{"id": "faces","name": "面容","desc": "","mode": "rw","define": {"arrayInfo": {"type": "struct","specs": [{"id": "id","name": "id","dataType": {"type": "string","min": "0","max": "100"}},{"id": "face_name","name": "face_name","dataType": {"type": "string","min": "0","max": "20"}}]},"type": "array"},"required": false},{"id": "cards","name": "卡片","desc": "","mode": "rw","define": {"arrayInfo": {"type": "struct","specs": [{"id": "id","name": "id","dataType": {"type": "string","min": "0","max": "100"}},{"id": "card_name","name": "card_name","dataType": {"type": "string","min": "0","max": "20"}}]},"type": "array"},"required": false},{"id": "passwords","name": "密码","desc": "","mode": "rw","define": {"arrayInfo": {"type": "struct","specs": [{"id": "id","name": "id","dataType": {"type": "string","min": "0","max": "100"}},{"id": "password_name","name": "password_name","dataType": {"type": "string","min": "0","max": "20"}}]},"type": "array"},"required": false},{"id": "fingerprints","name": "指纹","desc": "","mode": "rw","define": {"arrayInfo": {"type": "struct","specs": [{"id": "id","name": "id","dataType": {"type": "string","min": "0","max": "100"}},{"id": "fingerprints_name","name": "fingerprints_name","dataType": {"type": "string","min": "0","max": "20"}}]},"type": "array"},"required": false},{"id": "lock_motor_state","name": "落锁状态","desc": "","mode": "r","define": {"type": "bool","mapping": {"0": "未落锁","1": "已落锁"}},"required": false},{"id": "child_lock_state","name": "童锁状态","desc": "","mode": "rw","define": {"type": "bool","mapping": {"0": "关闭","1": "开启"}},"required": false},{"id": "disarming","name": "布防模式","desc": "","mode": "rw","define": {"type": "bool","mapping": {"0": "关闭","1": "开启"}},"required": false},{"id": "inner_lock_state","name": "反锁状态","desc": "","mode": "rw","define": {"type": "bool","mapping": {"0": "关闭","1": "开启"}},"required": false},{"id": "user_list","name": "绑定终端用户列表","desc": "","mode": "rw","define": {"type": "struct","specs": [{"id": "owner","name": "主人","dataType": {"type": "string","min": "0","max": "2048"}},{"id": "shared_person","name": "被分享者","dataType": {"type": "array","arrayInfo": {"type": "string","min": "0","max": "2048"}}}]},"required": false},{"id": "lock_state","name": "门锁状态","desc": "","mode": "rw","define": {"type": "enum","mapping": {"0": "未落锁","1": "已落锁","3": "门锁异常"}},"required": false},{"id": "_sys_xp2p_info","name": "xp2p信息","desc": "","mode": "rw","define": {"type": "string","min": "0","max": "64"},"required": false},{"id": "_sys_cs_days","name": "云存全时天数","desc": "","mode": "rw","define": {"type": "int","min": "0","max": "100","start": "0","step": "1","unit": ""},"required": false},{"id": "_sys_cs_status","name": "云存开关","desc": "","mode": "rw","define": {"type": "bool","mapping": {"0": "关","1": "开"}},"required": false},{"id": "_sys_cs_type","name": "云存类型","desc": "","mode": "rw","define": {"type": "enum","mapping": {"1": "全时","2": "事件"}},"required": false},{"id": "_sys_ai_status","name": "AI开关","desc": "","mode": "rw","define": {"type": "bool","mapping": {"0": "关","1": "开"}},"required": false}],"events": [],"actions": [{"id": "wake_up","name": "唤醒门锁","desc": "","input": [],"output": [{"id": "wakeup_state","name": "唤醒状态","define": {"type": "bool","mapping": {"0": "未唤醒","1": "已成功唤醒"}}}],"required": false},{"id": "unlock_remote","name": "远程解锁","desc": "","input": [],"output": [{"id": "result","name": "开锁成功状态","define": {"type": "bool","mapping": {"0": "开锁失败","1": "开锁成功"}}}],"required": false}]}