예제 #1
0
def return_state():
    global g_pingStarted, g_pingFailCount, g_buttonsConnected, g_gpioHandler
    fields = 0;
    if relayExp.readChannel(g_relayAddress, 0) == 1:
        fields = 1 << 0
    if relayExp.readChannel(g_relayAddress, 1) == 1:
        fields = 1 << 1
    if g_gpioHandler.getValue() == 1:
        fields = 1 << 2
        
    relaystate = str(fields).encode('ascii')
    print("Sending state of " + relaystate)
    client.publish("aquarium/state", relaystate, 1, True)
    g_pingStarted = True
    g_buttonsConnected = True
예제 #2
0
def turn_pump_on():
    print("Turning pump on")
    global g_relayAddress
    if relayExp.readChannel(g_relayAddress, 0) == 0:
        if relayExp.setChannel(g_relayAddress, 0, 1) == 0:
            client.publish("aquarium/pump/on")
    print_status()
예제 #3
0
def print_relay2_status():
    global g_relayAddress
    oledExp.setCursor(5, 0)
    if relayExp.readChannel(g_relayAddress, 1) == 0:
        oledExp.write("Valve : closed")
    else:
        oledExp.write("Valve : open  ")
예제 #4
0
def print_relay1_status():
    global g_relayAddress
    oledExp.setCursor(4, 0)
    if relayExp.readChannel(g_relayAddress, 0) == 0:
        oledExp.write("Pump  : off")
    else:
        oledExp.write("Pump  : on ")
예제 #5
0
def close_valve():
    print ("Closing Valve")
    global g_relayAddress
    if relayExp.readChannel(g_relayAddress, 0) == 1:
        turn_pump_off()

    if relayExp.setChannel(g_relayAddress, 1, 1) == 0:
        client.publish("aquarium/valve/close")
    print_status()
예제 #6
0
def initial_setup():
        status_oled = oledExp.driverInit()
        status_relay = relayExp.driverInit(7)	# 7 is the address of the Relay Expansion; 7 is when all relay switches are switched OFF
        check = relayExp.readChannel(7, 0)	# (7, 0) - again 7 is the address and 0 is the relay channel
        if check == 1:
                close_lock()
        with open('data.json') as json_file:	# Your UIDs could be different, make changes to the data.json file according to your settings
                data = json.load(json_file)
                return data['accepted']
        return None
예제 #7
0
def checkStatus(light):

    led = int2Addr(light)

    status = relayExp.readChannel(led[0], led[1])

    if status == 1:
        print 'Relay ON'

    elif status == 0:
        print 'Relay OFF '
    else:
        print 'Error: Bad status.'

    return status
예제 #8
0
# check initialization
#	should return 1 since the Expansion was initialized above
ret 	= relayExp.checkInit(addr)
print "checking if initialized: ", ret
time.sleep(1)


# set channel 0 to on
ret 	= relayExp.setChannel(addr, 0, 1)
print "Result from relaySetChannel: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# read channel 0 value
value 	= relayExp.readChannel(addr, 0)
print "Channel 0 value: ", value
time.sleep(2)

# set both channels to on
ret 	= relayExp.setAllChannels(addr, 1)
print "Result from relaySetAllChannels: ", ret
if (ret != 0):
	exit()
time.sleep(2)

# set channel 0 to off
ret 	= relayExp.setChannel(addr, 0, 0)
print "Result from relaySetChannel: ", ret
if (ret != 0):
	exit()
예제 #9
0
# check initialization
#	should return 1 since the Expansion was initialized above
ret = relayExp.checkInit(addr)
print "checking if initialized: ", ret
time.sleep(1)

# set channel 0 to on
ret = relayExp.setChannel(addr, 0, 1)
print "Result from relaySetChannel: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# read channel 0 value
value = relayExp.readChannel(addr, 0)
print "Channel 0 value: ", value
time.sleep(2)

# set both channels to on
ret = relayExp.setAllChannels(addr, 1)
print "Result from relaySetAllChannels: ", ret
if (ret != 0):
    exit()
time.sleep(2)

# set channel 0 to off
ret = relayExp.setChannel(addr, 0, 0)
print "Result from relaySetChannel: ", ret
if (ret != 0):
    exit()
The first iteration will be just to run 14h per day, 0500-1900
Intended implementation on omega2 with relay expansion
"""
import time
from OmegaExpansion import relayExp

led1 = 7
init = 0

#intiialize relay
status = relayExp.driverInit(led1)
print status
led1Init = relayExp.checkInit(1)
#check initialization
if led1Init == 0:
    print 'Initialization unsuccessful'
    led1Init = relayExp.driverInit(led1)
else:
    print 'Initialization successful'
while 1:
    #read current relay state
    state1 = relayExp.readChannel(led1, 1)
    if state1 == 1:
        output1 = 0
        print 'Relay found ON'
    else:
        output1 = 1
        print 'Relay found OFF'

    status1 = relayExp.setChannel(led1, 1, output1)
    time.sleep(2)
예제 #11
0
 def read(self, channel):
     return relayExp.readChannel(self.defaultAddress, channel)