示例#1
0
    def __init__(self, address=None):

        if address is None:
            raise ValueError("An Address must be passed into the constructor.")

        self.defaultAddress = address
        relayExp.driverInit(address)
        self.setAllOff()
示例#2
0
def turnOFF():
    relayAddr = 7
    initRelay = relayExp.driverInit(relayAddr)
    if relayExp.checkInit(relayAddr):
        logData('relay is init')
    else:
        logData('ERR relay not init')
        exit()
示例#3
0
def turnON():
    relayAddr = 7
    initRelay = relayExp.driverInit(relayAddr)
    if relayExp.checkInit(relayAddr):
        logData('relay is init')
    else:
        logData('ERR relay not init')
        exit()
    relayExp.setChannel(relayAddr, 0, 1)
示例#4
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
示例#5
0
def main(argv):
    global g_relayAddress, g_pingStarted, g_pingSuccess, g_pingFailCount, g_buttonsConnected
    g_relayAddress = int(argv[1])
    get_ip_address()
    print("g_relayAddress is " + str(g_relayAddress))
    oledExp.driverInit()
    client.on_message = on_message
    client.on_connect = on_connect
    client.on_disconnect = on_disconnect
    client.connect(broker)
    oledExp.setDisplayPower(1)
    relayExp.driverInit(g_relayAddress)
    g_gpioHandler.setOutputDirection(0)
 
    try:
        client.subscribe("control/#")
        client.loop_start()
        while True:
            time.sleep(1);
            if g_pingStarted:
                if g_pingSuccess:
                    g_pingSuccess = False
                elif g_pingSuccess == False:
                    g_pingFailCount += 1
                    if g_pingFailCount > 5:
                        turn_pump_off()
                        g_buttonsConnected = False
                        print_status()
                        g_pingStarted = False
                        g_pingFailCount = 0


    except KeyboardInterrupt:
        print("exiting on ctrl-c")
        client.disconnect() #disconnect
        client.loop_stop() #stop loop
        g_buttonsConnected = False
        relayExp.setChannel(g_relayAddress, 0, 0)
        relayExp.setChannel(g_relayAddress, 1, 0)
        time.sleep(2)
        sys.exit(0)
示例#6
0
def turnOFF():
	relayAddr = 7
	initRelay = relayExp.driverInit(relayAddr)
	if relayExp.checkInit(relayAddr):
		logData('relay is init')
	else:
		logData('ERR relay not init')
		exit()
	#when you init the relay it turns it off
	#relayExp.setChannel(relayAddr, 0, 0)

	'''   only on pro model   '''
示例#7
0
def relayBoardInit():
    status = relayExp.driverInit(relay_sw_addr)
    errorValue = True
    if status == 0:
        errorValue = False
    print_line('* relay driver init=[{}]'.format(status),
               debug=True,
               error=errorValue)

    bInit = relayExp.checkInit(relay_sw_addr)
    errorValue = True
    if bInit != 0:
        errorValue = False
    print_line('* relay driver checkInit=[{}]'.format(status),
               debug=True,
               error=errorValue)

    # force all relays to off
    relayExp.setAllChannels(relay_sw_addr, relay_off)
def confirmInit(light):

    #get address
    led = int2Addr(light)
    ledAddr = led[0]
    ledChannel = led[1]

    led1Init = 0
    cnt = 0  #timer, 5 cycles and exit with failure.

    while led1Init == 0 or cnt < 5:
        #check initialization
        led1Init = relayExp.checkInit(ledAddr)  #confirm successful init.
        if led1Init == 0:
            print 'Initialization unsuccessful'
            led1Init = relayExp.driverInit(ledAddr)
            time.sleep(.5)
            cnt = cnt + 1
        else:
            return led1Init
            print 'Initialization confirmed'

        return 0
示例#9
0
# dictPins is a dictionary that translates the button numbers to the actual 
# Omega pin that needs to be changed. button numbers come from the client side.
dictPins = {
              0:15,
              1:16,
              2:17
}

# The for loop sets the direction for the pins(always output for this)
for x in range(0, pins):
	omega_gpio.initpin(dictPins[x],'out')

# Initialize the relay. If more than one expansion then this will need to use
# a for loop to do multiple units.
relayStatus = relayExp.driverInit(7)
if (relayStatus == 0):
	print('Relay is initialized')
else:
	print('Relay is NOT initialized')

# This sets all pins to off and all relays to open
for x in range(0, pins):
	omega_gpio.setoutput(dictPins[x], 1)
for x in range(0, relays):
	relayExp.setChannel(7,0,x)

# This allows use of files in the static directory
@route('/static/<filename>')
def server_static(filename):
    return static_file(filename, root = './static/')
示例#10
0
    print sys.argv[0], "<addr offset>"
    exit()

addr = int(sys.argv[1])

print "Starting to use relay-exp functions on addr offset", addr

relayExp.setVerbosity(0)

# check initialization
# 	should return 0 if the Expansion has just been plugged in
ret = relayExp.checkInit(addr)
print "checking if initialized: ", ret

# initialize the relay-exp
ret = relayExp.driverInit(addr)
print "Result from relayDriverInit: ", ret
if ret != 0:
    exit()

# 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:
示例#11
0
import time

from OmegaExpansion import AdcExp
from OmegaExpansion import relayExp

adc = AdcExp.AdcExp(address=0x48)

relayExp.driverInit(7)
relayExp.setAllChannels(7, 0)


def setRelay(num, state):
  relayExp.setChannel(defaultChannel, num, state)



print(dir(time))
GAIN = 2/3

adc.start_adc(3, gain=GAIN)

print('Reading ADC expansion channel 3 for 5 seconds')

while 1:

  value = adc.get_last_voltage()
  rPhoto = 5.0 / value * 1000 - 1000
  lux = 500/(rPhoto/1000)
  # print('Channel 3: %.02f V'%(lux))

    print sys.argv[0], '<addr offset>'
    exit()

addr = int(sys.argv[1])

print 'Starting to use relay-exp functions on addr offset', addr

relayExp.setVerbosity(0)

# check initialization
#	should return 0 if the Expansion has just been plugged in
ret = relayExp.checkInit(addr)
print "checking if initialized: ", ret

# initialize the relay-exp
ret = relayExp.driverInit(addr)
print "Result from relayDriverInit: ", ret
if (ret != 0):
    exit()

# 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()
"""
lightScheduler.py
This file contains the functionality to run grow lights in the garden
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'
示例#14
0
from OmegaExpansion import relayExp
from OmegaExpansion import onionI2C
import time
import sys

if len (sys.argv) != 2:
	print "Need offset"
	exit()

# Initialize relay board
addr = int(sys.argv[1])
relayExp.driverInit(addr)

# Initialize I2C
i2c = onionI2C.OnionI2C()

# Define movement functions
# Relay0 = right motor
# Relay1 = left motor

def turnRight90():
	relayExp.setChannel(addr, 1, 1)
	time.sleep(0.25)
	relayExp.setChannel(addr, 1, 0)
	return

def turnLeft90():
	relayExp.setChannel(addr, 0, 1)
	time.sleep(0.25)
	relayExp.setChannel(addr, 0, 0)
	return