Skip to content

Latest commit

 

History

History
42 lines (23 loc) · 3.14 KB

device_discover.md

File metadata and controls

42 lines (23 loc) · 3.14 KB

设备发现与查询 device discovery and query

##1. 网关设备发现(设备发现不加密) Gateway discovery (device discovery unencrypted)

设备发现用来在局域网中发现网关,使用组播 (ip: 224.0.0.50, peer_port: 4321) ,所有网关收到Whois命令都要应答、回复自己的IP信息: To discover gateway in Lan, multicast to (ip: 224.0.0.50, peer_port: 4321). Gateways in Lan will reply their IP status after receiving Whois command:

  • PC 组播方式 ->网关: {"cmd":"whois"}
  • PC multicast -> Gateway:{"cmd":"whois"}
  • 网关 单播方式->PC:{"cmd":"iam","ip" : "192.168.0.42","port" : "9898","model" : "gateway",.....}
  • Gateway unicast->PC:{"cmd":"iam","ip" : "192.168.0.42","port" : "9898","model" : "gateway",.....}

##2. 加密机制 Encryption mechanism

采用key加密方式,默认不加密。如果用户想限制其他人对网关及其子设备的控制权限,可以在小米智能家庭APP上对网关设置密钥(使用AES-CBC 128 加密,app下发随机的16个字节长度的字符串密钥)。 若没有设置密钥(即app里设置密钥为空字符串””)则其他人均有权限可以控制网关及其子设备。

Using key encryption, the default is not encrypted. If the user wants to restrict others to access the gateway and sub-devices, an encription key can be set on the Xiaomi smarthome APP for each gateway (using AES-CBC 128 encryption, the app issued a random 16-byte length of the string key). If there is no encription key configured (i.e. the key is set to the empty string ""), then everyone has permission to control the gateway and its sub-devices.

注: AES-CBC 128 初始向量定义为: Notes: The AES-CBC 128 initial vector is defined as: unsigned char const AES_KEY_IV[16] = {0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58, 0x56, 0x2e};

##3. 查询子设备id列表 Get of sub device ID

命令以单播方式发送给网关的udp 9898端口,网关以单播方式回复,用来获取网关中有哪些设备(网关返回子设备的设备id)。 Unicast a command to the gateway at udp 9898 port. The gateway replies in unicast mode a list devices in the gateway (the gateway returns the device ID of the sub-device)

  • PC->gateway: {"cmd" : "get_id_list"}
  • gateway->PC: {"cmd" : "get_id_list_ack","sid":"1022780","token":"1234567890abcdef","data":"[\"sid1\",\"sid2\",\"sid3\"]"}

Here “sid” is the gateway did,“token” is a random string generated by the gateway for user to generate write "key"

##4. 子设备状态上报 Sub-device status report

以组播方式发送给 (ip: 224.0.0.50, port: 9898) 。当子设备状态发生变化时,子设备会上报状态。例如窗磁上报open/close信息。用户可以拿这个状态去做联动。例如:开窗报警,开窗关空调。 Sub devices multicast status to (ip: 224.0.0.50, port: 9898). When the status of a sub device changes, it will report the status. E.g. (Not important.)

gateway->PC{"cmd":"report","model":"magnet","sid":"89234324","short_id":4343,"data":"{\"status\":\"open\"}"}