From 67410efd8b02c213f6ff5735af7c4ce456c92c83 Mon Sep 17 00:00:00 2001 From: Nathan Date: Sun, 2 Jan 2022 21:10:52 -0500 Subject: [PATCH] command / attributes files in spec for decode barrier exists and is doing a watch for status change on pins 0 and 1 main is starting to add in the new cluster at endpoint 8 on interview com is where fancy_transmit is now --- barrier.py | 44 ++++++++++++++++++++++++++++++++++++-------- com.py | 2 +- main.py | 6 ++++-- spec.py | 24 ++++++++++++++++++++---- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/barrier.py b/barrier.py index b73925b..561cc3f 100644 --- a/barrier.py +++ b/barrier.py @@ -2,18 +2,46 @@ import com import xbee from machine import Pin -class barrier: + +class Barrier: moving = 0 - position = 0 - ad0 = Pin("D0", Pin.IN, Pin.PULL_UP) - ad1 = Pin("D1", Pin.IN, Pin.PULL_UP) - ad2 = Pin("D2", Pin.IN, Pin.PULL_UP) + barrier_position = 0 + ad0 = Pin("D0", Pin.IN, Pin.PULL_UP) #door + ad1 = Pin("D1", Pin.IN, Pin.PULL_UP) #motor ad4 = Pin("D4", Pin.OUT) + door = ad0.value() + motor = ad1.value() + update = False - def status(seq,payload): + def status(self, seq, payload): pass - def command(seq, payload): + + def command(self, seq, payload): pass def watch(self): - pass \ No newline at end of file + current_door = self.door + current_motor = self.motor + self.door = self.ad0.value() + self.motor = self.ad1.value() + if (current_door != self.door) or (current_motor != self.motor): + self.update = True + else: + self.update = False + if self.door == 0: + if self.motor == 1: + self.moving = 0 + self.barrier_position = 100 + if self.motor == 0: + if self.door == 1: + self.moving = 0 + self.barrier_position = 0 + if self.motor == 0: + if self.door == 0: + if self.barrier_position == 100: + self.barrier_position = 50 + self.moving = 1 + if self.barrier_position == 0: + self.barrier_position = 50 + self.moving = 2 + return self.update diff --git a/com.py b/com.py index b1966f5..e3b2b5f 100644 --- a/com.py +++ b/com.py @@ -5,7 +5,7 @@ def receive(): def fancy_transmit(payload, source_ep, dest_ep, cluster,profile): send = 0 - while send==0: + while send == 0: try: if xbee.transmit(xbee.ADDR_COORDINATOR, payload, source_ep=source_ep, dest_ep=dest_ep, cluster=cluster, profile=profile, tx_options=0) is None: diff --git a/main.py b/main.py index 0f02e6a..8bbb7c0 100644 --- a/main.py +++ b/main.py @@ -40,6 +40,8 @@ print("receiving") diff = 3600000 first_report = False timestamp = time.ticks_ms() +garage = barrier.Barrier() + while 1 != 0: packet = com.receive() if packet is not None: @@ -86,7 +88,7 @@ while 1 != 0: 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, 3, 1,0, 0]) com.fancy_transmit(payload=payload, source_ep=0, dest_ep=0, cluster=32772, profile=0) print("simple descriptor response") @@ -130,7 +132,7 @@ while 1 != 0: zcl_head = bytes([12, 30, 16, 171, 10]) payload = zcl_head + bytes([0,0,10,0]) #for now only return off for state report com.fancy_transmit(payload=payload, source_ep=8, dest_ep=1, cluster=6, profile=260) - barrier.watch() + garage.watch() #print(xbee.receive()) #print("temperature") diff --git a/spec.py b/spec.py index 5f7114b..0f4ad25 100644 --- a/spec.py +++ b/spec.py @@ -527,20 +527,36 @@ CLUSTERS_BY_NAME = { }, { },), 'onoff': (0x0006, { - 'off': (0x00, (),), + 'off': (0x00, (),),#command 'on': (0x01, (),), 'toggle': (0x02, (),), 'off_with_effect': (0x40, ('effect_id:uint8', 'effect_variant:uint8',),), 'on_with_recall_global_scene': (0x41, (),), 'on_with_timed_off': (0x42, ('control:uint8', 'on_time:uint16', 'off_wait_time:uint16',),), + }, { #middle hash is blank, unknown what this is }, { - }, { - 'onoff': (0x0000, 'bool',), + 'onoff': (0x0000, 'bool',),#attribute 'global_scene_control': (0x4000, 'bool',), 'on_time': (0x4001, 'uint16',), 'off_wait_time': (0x4002, 'uint16',), },), - 'barrierControl' + 'barrier_control': (0x0103, { + #commands + 'go_to_percent': (0x0000, ('percentOpen:uint8'),), + 'stop': (0x0001,(),), + }, {#blank middle hash like onoff + }, {#attribute + 'moving_state': (0x0001, 'enum8',), + 'safety_status': (0x0002,'map16',), + 'capabilities': (0x0003, 'map8',), + 'open_events': (0x0004, 'uint16',), + 'close_events': (0x0005, 'uint16',), + 'command_open_events': (0x0006, 'uint16',), + 'command_close_events': (0x0007, 'uint16',), + 'open_perioad': (0x0008, 'uint16',), + 'close_period': (0x0009, 'uint16',), + 'barrier_position': (0x000A, 'uint8',), + },), 'onoff_configuration': (0x0007, { }, { }, {