barriercontrol is recognized cluster

working on responding to attribute request, it's been a long time
so I've forgotten byte format
master
nathan wagner 3 years ago
parent ca35196646
commit ed17e0b311

@ -15,14 +15,27 @@ class Barrier:
motor = ad1.value().to_bytes(2, "big")
update = True
def status(self, seq, payload):
def status(self,seq, kwargs):
#moving state is x0001 enum8(0x30)
#Barrierposition is 0x000A uint8(0x20)
# 2 octets attribute identifier
# 1 octet attribute data type
# 1 octet attribute value
to_return = bytes([1,0,32]) + bytes(self.moving) +bytes([10,0,20]) + bytes(self.barrier_position)
return to_return
print("really messed up early in the game eh")
attributes = kwargs['attributes']
print(attributes)
if len(attributes) == 1:
print("length")
if attributes[0] == 10:
print("position request")
print(self.barrier_position)
return self.barrier_position
if attributes[0] == 1:
print("moving request")
print(self.moving)
return self.moving
#to_return = bytes([1,0,48]) + bytes(self.moving) + bytes([10,0,20]) + bytes(self.barrier_position)
return -1
def command(self, seq, payload):

@ -9,9 +9,9 @@ def announce():
srcarry = srcaddr.to_bytes(2, "big")
initial_payload=bytes([171, srcarry[1], srcarry[0], 141, 194, 209, 65, 0, 162, 19, 0, 142])
xbee.transmit(xbee.ADDR_COORDINATOR,initial_payload, source_ep=0, dest_ep=0, cluster=19,profile=0, tx_options=0)
def fancy_transmit(payload, source_ep, dest_ep, cluster,profile):
send = 0
i = 0
while send == 0:
try:
if xbee.transmit(xbee.ADDR_COORDINATOR, payload, source_ep=source_ep, dest_ep=dest_ep, cluster=cluster, profile=profile,

@ -15,6 +15,8 @@ import struct
#ad0 = Pin("D0", Pin.IN, Pin.PULL_UP)
#ad1 = Pin("D1", Pin.IN, Pin.PULL_UP)
#ad2 = Pin("D2", Pin.IN, Pin.PULL_UP)
while xbee.atcmd("AI") != 0:
time.sleep(0.1)
ad4 = Pin("D4", Pin.OUT, value=0)
def status_cb(status):
print("m stat: {:02x}".format(status))
@ -43,11 +45,21 @@ while 1 != 0:
packet = com.receive()
if packet is not None:
print(packet)
b = bytearray(packet['payload'])
print(b[0])
if packet['cluster'] == 259: #barrier cluster
cluster_name, seq, CommandType, command_name, disable_default_response, kwargs = spec.decode_zcl(
packet['cluster'], packet['payload'])
if "attributes" in kwargs:
garage.status(seq,packet['payload'])
#garage.status(seq,packet['payload'])
print("found attribute request")
stat=garage.status(seq, kwargs)
if payload != -1:
print("garage status")
print(payload)
payload = bytes([12, 30, 16, seq, 1])
payload = payload + bytes([0, 0, 16,stat ])
com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'], cluster=packet['cluster'], profile=packet['profile'])
if CommandType is not None:
garage.command(seq, packet['payload'])
pass
@ -87,12 +99,16 @@ while 1 != 0:
print(b[0])
payload=bytes([b[0], 00, b[1], b[2], 1, 8])
com.fancy_transmit(payload=payload,source_ep=0,dest_ep=0,cluster=32773, profile=0)
#payload = bytes([b[0], 00, b[1], b[2], 1, 16])
#time.sleep(0.5)
#com.fancy_transmit(payload=payload, source_ep=0, dest_ep=0, cluster=32773, profile=0)
print("sent-endpoint-response")
if packet['cluster']==4: #simple descriptor request
print(bytes(packet['payload']))
b = bytearray(packet['payload'])
print(b[0])
payload = bytes([b[0], 00, b[1], b[2], 14, 8, 4, 1, 2, 0, 6, 4, 0, 0, 3, 0, 6, 3, 1,0, 0])
#payload = bytes([b[0], 00, b[1], b[2], 14, 8, 4, 1, 2, 0, 6, 3, 0, 0, 3, 0, 6, 0, 0])
payload = bytes([b[0], 00, b[1], b[2], 14, 8, 4, 1, 2, 0, 6, 4, 0, 0, 3, 0, 6,0, 3, 1,0, 0])
com.fancy_transmit(payload=payload, source_ep=0, dest_ep=0, cluster=32772, profile=0)
print("simple descriptor response")
@ -136,14 +152,17 @@ while 1 != 0:
#payload = bytes([12, 30, 16, 171, 5,0, 0, 0, 16, ad4.value()]) # zcl_header
#payload = bytes([])
#payload = zcl_head# + payload
florp = garage.status(None, None)
garage.watch()
florp = garage.barrier_position
dumb = bytes([12, 30, 16, 171, 5])
com.fancy_transmit(payload=bytes([12, 30, 16, 171, 5,0, 0, 0, 16, ad4.value()]), source_ep=8, dest_ep=1, cluster=6, profile=260)
com.fancy_transmit(payload=bytes([12, 30, 16, 171, 10])+florp, source_ep=8, dest_ep=1, cluster=6, profile=260)
com.fancy_transmit(payload=dumb , source_ep=8, dest_ep=1, cluster=259, profile=260)
if garage.watch():
zcl_head = bytes([12, 30, 16, 171, 5]) # zcl_header
zcl_head = bytes([12, 30, 16, 171, 10]) # zcl_header
payl = zcl_head + garage.status()
print("door: "+ str(garage.door))
print("motor: "+ str(garage.motor))
com.fancy_transmit(payload=payl, source_ep=8, dest_ep=1, cluster=259, profile=260)
time.sleep(1)
garage.update = False

Loading…
Cancel
Save