valid reports

valid moving and barrier position data
master
nathan wagner 3 years ago
parent 07cb242a0a
commit ddc2bfdf3c

@ -36,6 +36,9 @@ class Barrier:
def position (self): def position (self):
return bytes([0,10])+bytes([self.duint8]) + self.barrier_position return bytes([0,10])+bytes([self.duint8]) + self.barrier_position
def movement (self):
return bytes([0,1]) + bytes([self.denum8]) + self.moving
def command(self, seq, payload): def command(self, seq, payload):
self.ad4.value(1) self.ad4.value(1)
time.sleep_ms(600) time.sleep_ms(600)
@ -45,8 +48,8 @@ class Barrier:
def watch(self): def watch(self):
current_door = self.door current_door = self.door
current_motor = self.motor current_motor = self.motor
self.door = self.ad0.value().to_bytes(2, "big") self.door = self.ad0.value().to_bytes(1, "big")
self.motor = self.ad1.value().to_bytes(2, "big") self.motor = self.ad1.value().to_bytes(1, "big")
#print("door: "+str(self.door)) #print("door: "+str(self.door))
#print("motor:" +str(self.motor)) #print("motor:" +str(self.motor))
if (current_door != self.door) or (current_motor != self.motor): if (current_door != self.door) or (current_motor != self.motor):
@ -61,8 +64,8 @@ class Barrier:
if self.door == b'\x01': if self.door == b'\x01':
self.moving = b'\x00' self.moving = b'\x00'
self.barrier_position = b'\x00' self.barrier_position = b'\x00'
if self.motor == b'\x00': if self.motor == b'\x01':
if self.door == b'\x00': if self.door == b'\x01':
if self.barrier_position == b'\x64': if self.barrier_position == b'\x64':
self.barrier_position = b'\x32' self.barrier_position = b'\x32'
self.moving = b'\x01' self.moving = b'\x01'

@ -36,12 +36,8 @@ com.announce()
time.sleep(1) time.sleep(1)
print("receiving") print("receiving")
diff = 3600000
first_report = False #war_header=b'\x10'
timestamp = time.ticks_ms()
garage = barrier.Barrier()
payload_header=b'\x18'
war_header=b'\x10'
#payload_header=b'\x0c\x1e\x10' #payload_header=b'\x0c\x1e\x10'
_rap=const(0x01) #read attribute response _rap=const(0x01) #read attribute response
_dap=const(0x0d) #discover attribute response _dap=const(0x0d) #discover attribute response
@ -53,134 +49,139 @@ duint16 =b'\x21'
denum8 = b'\x30' denum8 = b'\x30'
dbool = b'\x10' dbool = b'\x10'
SUCCESS = b'\x00' SUCCESS = b'\x00'
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'])
print("printing kwargs for incoming packet")
print(command_name)
if "attributes" in kwargs:
#garage.status(seq,packet['payload'])
print("found attribute request")
stat=garage.status(seq, kwargs)
if stat != 'b\xffff':
print("garage status")
payload = payload_header+ bytes([seq])+ bytes([_rap]) + stat
print(payload)
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:
if command_name == "stop":
garage.command(seq, packet['payload'])
pass
if packet['cluster'] == 6: #genOnOffCluster in HA Profile
if packet['profile'] == 260: #HA profile
cluster_name, seq, CommandType, command_name, disable_default_response, kwargs = spec.decode_zcl(packet['cluster'], packet['payload'])
# print(packet['payload'])
# print(CommandType)
# print(command_name)
# print(kwargs)
if "attributes" in kwargs:
if kwargs['attributes'][0] == 0:
payload = payload_header + bytes([seq]) + bytes([_rap]) + bytes([0,0])+ SUCCESS + dbool + bytes([ad4.value()])
print(payload)
com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'],
cluster=packet['cluster'], profile=packet['profile'])
if kwargs['attributes'][0] == 10:
payload = payload_header + bytes([seq]) + bytes([_rap]) + bytes([0, 0, 16, ad4.value()])
# payload= attr_bytes
print(payload)
com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'],
cluster=packet['cluster'], profile=packet['profile'])
if command_name == "on":
ad4.value(1)
if command_name == "off":
ad4.value(0)
if command_name == "toggle":
ad4.value(1)
time.sleep(1)
ad4.value(0)
if packet['cluster']==5: #active endpoint request
print(bytes(packet['payload']))
b = bytearray(packet['payload'])
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, 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")
if packet['cluster'] == 0: #network address request def main_loop ():
if packet['profile'] == 260: diff = 10000
#resp = bytearray(packet['payload']) first_report = False
cluster_name, seq, CommandType, command_name, disable_default_response, kwargs = spec.decode_zcl(packet['cluster'], packet['payload']) timestamp = time.ticks_ms()
garage = barrier.Barrier()
payload_header = b'\x18'
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'])
print("printing kwargs for incoming packet")
print(command_name) print(command_name)
print(kwargs) if "attributes" in kwargs:
if 'attributes' in kwargs: #garage.status(seq,packet['payload'])
attr_bytes=gen.attribute_result(kwargs) print("found attribute request")
#payload: control byte, code bytes(2), seq copy, command identifier(read_attributes_response, stat=garage.status(seq, kwargs)
#payload = bytes([4, 30, 16, seq, 1, attr_bytes, 0, 8, 0]) if stat != 'b\xffff':
zcl_header = payload_header + bytes([seq]) + _rap print("garage status")
payload = zcl_header+attr_bytes payload = payload_header+ bytes([seq])+ bytes([_rap]) + stat
#payload= attr_bytes print(payload)
print(payload) com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'], cluster=packet['cluster'], profile=packet['profile'])
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:
print("attribute_read_response") if command_name == "stop":
#spec.decode_zcl(packet['cluster'], packet['payload']) garage.command(seq, packet['payload'])
print(bytes(packet['payload'])) pass
b = bytearray(packet['payload']) if packet['cluster'] == 6: #genOnOffCluster in HA Profile
for x in b: if packet['profile'] == 260: #HA profile
print(x) cluster_name, seq, CommandType, command_name, disable_default_response, kwargs = spec.decode_zcl(packet['cluster'], packet['payload'])
if packet['cluster'] == 2: #node descriptor request # print(packet['payload'])
print(bytes(packet['payload'])) # print(CommandType)
b = bytearray(packet['payload']) # print(command_name)
print(b[0]) # print(kwargs)
payload = bytes([b[0], 00, b[1], b[2], 4, 143, 120, 8, 80, 160, 0, 1, 44, 160, 0, 0]) if "attributes" in kwargs:
com.fancy_transmit(payload=payload, source_ep=0, dest_ep=0, cluster=32772, profile=packet['profile']) if kwargs['attributes'][0] == 0:
print("node descriptor response") payload = payload_header + bytes([seq]) + bytes([_rap]) + bytes([0,0])+ SUCCESS + dbool + bytes([ad4.value()])
if packet['cluster'] == 32770: #node descriptor response print(payload)
print(bytes(packet['payload'])) com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'],
b = bytearray(packet['payload']) cluster=packet['cluster'], profile=packet['profile'])
print("Node descriptor response integer payload discard") if kwargs['attributes'][0] == 10:
#for key, value in packet.items(): payload = payload_header + bytes([seq]) + bytes([_rap]) + bytes([0, 0, 16, ad4.value()])
#1 print (key, ' : ', value) print(payload)
if (diff < time.ticks_diff(time.ticks_ms(), timestamp)) or (not first_report): com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'],
timestamp = time.ticks_ms() cluster=packet['cluster'], profile=packet['profile'])
first_report = True if command_name == "on":
#payload = bytes([12, 30, 16, 171, 5,0, 0, 0, 16, ad4.value()]) # zcl_header ad4.value(1)
#payload = bytes([]) if command_name == "off":
#payload = zcl_head# + payload ad4.value(0)
garage.watch() if command_name == "toggle":
zcl_header = war_header +oob + bytes([_war]) ad4.value(1)
payload=zcl_header+garage.position() time.sleep(1)
#dumb = bytes([12, 30, 16, 171, 5]) ad4.value(0)
#com.fancy_transmit(payload=bytes([12, 30, 16, 171, 10])+florp, source_ep=8, dest_ep=1, cluster=6, profile=260) if packet['cluster']==5: #active endpoint request
com.fancy_transmit(payload=payload , source_ep=8, dest_ep=1, cluster=259, profile=260) print(bytes(packet['payload']))
if garage.watch(): b = bytearray(packet['payload'])
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)
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,0, 3, 1,0, 0])
com.fancy_transmit(payload=payload, source_ep=0, dest_ep=0, cluster=32772, profile=0)
print("simple descriptor response")
#payload_header + oob + bytes([_war]) if packet['cluster'] == 0: #network address request
payl = war_header + oob + bytes([_war]) + garage.position() if packet['profile'] == 260:
print("door: "+ str(garage.door)) cluster_name, seq, CommandType, command_name, disable_default_response, kwargs = spec.decode_zcl(packet['cluster'], packet['payload'])
print("motor: "+ str(garage.motor)) print(command_name)
print(payl) print(kwargs)
com.fancy_transmit(payload=payl, source_ep=8, dest_ep=1, cluster=259, profile=260) if 'attributes' in kwargs:
time.sleep(1) attr_bytes=gen.attribute_result(kwargs)
garage.update = False zcl_header = payload_header + bytes([seq]) + _rap
payload = zcl_header+attr_bytes
print(payload)
com.fancy_transmit(payload=payload, source_ep=packet['dest_ep'], dest_ep=packet['source_ep'], cluster=packet['cluster'], profile=packet['profile'])
print("attribute_read_response")
#spec.decode_zcl(packet['cluster'], packet['payload'])
print(bytes(packet['payload']))
b = bytearray(packet['payload'])
for x in b:
print(x)
if packet['cluster'] == 2: #node descriptor request
print(bytes(packet['payload']))
b = bytearray(packet['payload'])
print(b[0])
payload = bytes([b[0], 00, b[1], b[2], 4, 143, 120, 8, 80, 160, 0, 1, 44, 160, 0, 0])
com.fancy_transmit(payload=payload, source_ep=0, dest_ep=0, cluster=32772, profile=packet['profile'])
print("node descriptor response")
if packet['cluster'] == 32770: #node descriptor response
print(bytes(packet['payload']))
b = bytearray(packet['payload'])
print("Node descriptor response integer payload discard")
#for key, value in packet.items():
#1 print (key, ' : ', value)
#print(time.ticks_diff(time.ticks_ms(),timestamp))
if (diff < time.ticks_diff(time.ticks_ms(), timestamp)) or (not first_report):
timestamp = time.ticks_ms()
first_report = True
#payload = bytes([12, 30, 16, 171, 5,0, 0, 0, 16, ad4.value()]) # zcl_header
#payload = bytes([])
#payload = zcl_head# + payload
garage.watch()
zcl_header = payload_header + oob + bytes([_ra])
payload=zcl_header+garage.position()+garage.movement()
#dumb = bytes([12, 30, 16, 171, 5])
#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=payload , source_ep=8, dest_ep=1, cluster=259, profile=260)
if garage.watch():
#payload_header + oob + bytes([_war])
payl = payload_header + oob + bytes([_ra]) + garage.position()+ garage.movement()
print("door: "+ str(garage.door))
print("motor: "+ str(garage.motor))
print("moving: "+ str(garage.moving))
print("barrierPosition: "+ str(garage.barrier_position))
print(payl)
com.fancy_transmit(payload=payl, source_ep=8, dest_ep=1, cluster=259, profile=260)
time.sleep(1)
garage.update = False
while 1 != 0:
try:
main_loop()
except Exception as e:
print(str(e))
#print(xbee.receive()) #print(xbee.receive())
#print("temperature") #print("temperature")
#print(tp) #print(tp)

Loading…
Cancel
Save