我有个问题。我有一个项目,一个家庭自动化(家庭自动化)系统,我必须通过接口向一些传感器、温度传感器、功率传感器、接触传感器等发送一些命令。
我已经完成了可以将开/关/切换命令发送到 ZigBee 传感器的部分。我已遵循本手册,此命令在第 196 页进行了描述。
我在我的项目中有这部分 python 来设置正确的数据包发送到传感器:
if command not in ['ON', 'OFF', 'TOGGLE']:
raise tornado.web.HTTPError(404, "Unknown command: " + str(command))
op_group = "70"
op_code = "50"
# *9999999999999999;70;50;;100260EB008060008000000D8#
# 70 50 100231AC00000000000008060008000101A9
packet_meta = "*%s;%s;%s;%s;02%s%s600080000%s#" # D8 i s the CRC who compute that?
pkt_len = hextransform(16, 2)
# Hexify the network ID
netid = hextransform(int(nid), 16)
# Hexify the sensor ID
# TODO: - split sensor_id in ZTC sensor_id and endpoint!
# - ZTC sens ID is 2 bytes
# - ZTC endpoint is 1 byte
# sens_id = hextransform(int(sid) >> 8, 4)
# end_point = hextransform(int(sid) & 0x0000FF, 2)
# print("\nsens_id: '" + sens_id + "'\n")
# print("\nendpoint: '" + end_point + "'\n")
# TODO: - split sensor_id in ZTC sensor_id and clusterid!
# - ZTC sens ID is 2 bytes
# - ZTC clusterid is 2 bytes
sens_id = hextransform(int(sid) >> 16, 4)#elisa
sens_id_little = invert2bytes(sens_id,0)
cluster_id = hextransform(int(sid) & 0x00FFFF, 4)#elisa
end_point = "08" #elisa
if command == 'ON':
cmd_data = "01"
elif command == 'OFF':
cmd_data = "00"
elif command == 'TOGGLE':
cmd_data = "02"
packet = packet_meta % (netid, op_group, op_code, pkt_len, sens_id, end_point, cmd_data)
packet = packet.upper()
print("\t\t " + packet + "\n")
################ ELISA #########################################
cmd_meta = "02%s000000000000080600080000%s" #elisa
mycommand = cmd_meta % (sens_id_little, cmd_data) #elisa
len_mycommand = len(mycommand)/2
op_group_hex=0x70
op_code_hex=0x50
mynet_type ="ztc"
cmdjson = packet2json(op_group_hex,op_code_hex, mycommand)
#
#
#TODO : -write command into db
ts = datetime.datetime.now().isoformat()
self.lock_tables("write", ['confcommands'])
self.db.execute("INSERT INTO confcommands (network_id, ntype, timestamp, command) \
VALUES (%s,%s,%s,%s)", nid, mynet_type, ts, cmdjson)
self.unlock_tables();
现在,按照手册,我将添加重新启动命令以重新启动传感器。然后还要添加恢复启动配置命令。
所以我不知道这些命令在手册中的哪里。其中有几个。然后,我看不到命令重新启动或恢复启动配置的明确值。如果对于开/关/切换有三个值(00、01、02),在这种情况下,手册没有说明分配给 cmd_data 变量以创建正确的数据包以发送到传感器的值是什么。
我希望你能帮助我,因为我不知道在哪里搜索这个了。非常感谢。