Skip to content
Permalink
Browse files

restructure layout for easy multi-file update

  • Loading branch information...
DavidVentura committed Jul 11, 2019
1 parent 5a59852 commit 1a9328954642efa5a89d1ae4cef5594bb0f53b19
@@ -0,0 +1 @@
ALL_CURTAINS
@@ -1,25 +1,14 @@
import common
import time
from machine import Pin
from rfsocket import RFSocket

CLIENT_ID = 'ALL_CURTAINS'
TOPIC_PREFIX = "%s/set" % CLIENT_ID
SUBTOPICS = [b"ALL_CURTAINS/set/#" % TOPIC_PREFIX, b"RFPOWER/set/#"]
CLIENT_ID = common.get_client_id()
SUBTOPIC = b"%s/set/#" % CLIENT_ID

relay_up = Pin(16, Pin.OUT) # D0
relay_down = Pin(4, Pin.OUT) # D2

p = Pin(0, Pin.OUT)
s = RFSocket(p, remote_id=41203711, chann=RFSocket.NEXA)

def set_channel_state(channel, state):
if state:
s.on(channel)
else:
s.off(channel)
common.publish(PUBTOPIC+b"/%s" % channel, str(state))


def set_pin(pin, state):
PUBTOPIC = b"%s/state/pin_%s" % (CLIENT_ID, str(pin))
@@ -49,28 +38,20 @@ def sub_cb(topic, msg):
common.log(topic)
return

if stopic[0] == 'ALL_CURTAINS':
try:
_time = int(msg.decode())
_time = min(_time, 20)
except Exception as e:
common.log(e)
return
move_curtains(stopic[2], _time)
elif stopic[0] == 'RFPOWER':
channel = int(stopic[2])
print(stopic[2], channel)
if msg in (b'0', b'1'):
set_channel_state(channel, int(msg))
else:
common.log(msg.decode('ascii'))
try:
_time = int(msg.decode())
_time = min(_time, 20)
except Exception as e:
common.log(e)
return
move_curtains(stopic[2], _time)

def setup():
set_pin(relay_down, True)
set_pin(relay_up, True)

def main():
setup()
common.loop(setup_fn=None, loop_fn=[], callback=sub_cb, subtopic=SUBTOPICS)
common.loop(setup_fn=None, loop_fn=[], callback=sub_cb, subtopic=[SUBTOPIC])

main()
@@ -0,0 +1 @@
RFPOWER
File renamed without changes.
@@ -0,0 +1 @@
NIGHTLAMP
@@ -47,6 +47,7 @@ def handle_button(pin):
def setup():
button.irq(handler=handle_button, trigger=Pin.IRQ_RISING),
led(1) # Turn off LED, it is inverted

def main():
common.loop(setup_fn=setup, loop_fn=[read_dht], callback=sub_cb, subtopic=[SUBTOPIC])

This file was deleted.

0 comments on commit 1a93289

Please sign in to comment.
You can’t perform that action at this time.