Пример #1
0
 def get(self, led,  ledGreen, ledRed):
     myLedControl = ledcontrol()
 
     myLedControl.getStatus()
     myLedControl.setWeatherGreen(ledGreen)
     myLedControl.setWeatherRed(ledRed)
 
     returnString = {'ledStateGreen':  str(ledGreen),  'ledStateRed': str(ledRed)}
 
     return returnString,  200
Пример #2
0
def ledStateWrite(led, ledGreen, ledRed):
    myLedControl = ledcontrol()
    myLedControl.getStatus()

    myLedControl.setWeatherGreen(ledGreen)
    myLedControl.setWeatherRed(ledRed)

    returnString = {'ledStateGreen': str(ledGreen), 'ledStateRed': str(ledRed)}

    return json.dumps(returnString)
Пример #3
0
 def get(self):
     myLedControl = ledcontrol()
 
     myLedControl.getStatus()
 
     return 'Code to be completed',  404
Пример #4
0
def main():
    gpio.setmode(gpio.BCM)
    gpio.setup([irrigationPin,  hosePin,  powerPin],  gpio.OUT)
    gpio.output([irrigationPin,  hosePin],  gpio.LOW)
    gpio.output([powerPin],  gpio.HIGH)
    
    #mqMessage = ""
    state = -2 # Startup state
    myWeather  = weather()
    myLedControl = ledcontrol() # init remote led control
    mySensor = sensorComm()
    #myMqSensor = mqSensor()
    #myMqControl = mqControl()
    mySettings = settingsClass() # get settings from db
    #mySettings.resetSettings()
    
    #automationhat.is_automation_hat()
    
    #if automationhat.is_automation_hat():
        # init local automation hat
        #automationhat.light.power.write(1)
    
    #automationhat.light.comms.write(1)
    
    #  setup pwm
    #pwmLow = mySettings.settings['pwmLow']
    pwmMid = mySettings.settings['pwmMid']
    pwmHigh = mySettings.settings['pwmHigh']
    
    # Start pwm
    # serial comm to the Arduino to set/get sensor data.
    mySensor.pumpPWM = pwmMid
    mySensor.setValues()
    #mqMessage = mySensor.setValues()
    #myMqControl.sendMQ(mqMessage)
    mySensor.refresh()
    #mqMessage = mySensor.refresh()
    #myMqSensor.sendMQ(mqMessage)
    
    # Set sunrise sunset vars
    dayRollover = -1 # get new sunrise sunset times only once!
    mySunrise = sunRiseSet() # Get sunrise and sunset from DB
    
    # Config the display
    #scrollphathd.set_brightness(0.5)
    
    myTimeNow = datetime.datetime.now()
    currTime = myTimeNow.hour + myTimeNow.minute
    lastTime = currTime
    currHour = -1
    lastHour = -2
    
    myWeather.getWeather()
    #automationhat.light.comms.write(0)
    
    while True:
        myTimeNow = datetime.datetime.now()
        currTime = myTimeNow.hour + myTimeNow.minute
        currHour = myTimeNow.hour
        
        # Update the time string for the display every minute
        if (currTime != lastTime and state == -1):
            lastTime = currTime
        
        # Update the weather trend (last 24 hours) every hour
        if (currHour != lastHour):
            lastHour = currHour
            myWeather.getWeather()
            myWeather.getRecentTrend()
        
        # get new sunrise and sunset times
        rollTime = myTimeNow.hour + myTimeNow.minute
        if (rollTime == 0 and dayRollover == -1):
            mySunrise = sunRiseSet()
            
            dayRollover = 0
        elif (rollTime == 0 and dayRollover == 0):
            dayRollover = 0
        else:
            dayRollover = -1
        
        numStartTime = (myTimeNow.hour * 3600) + (myTimeNow.minute * 60) + myTimeNow.second
        
        #automationhat.light.comms.write(1) # Comm light on to show activity.

        mySensor.refresh()
        #mqMessage = mySensor.refresh()
        #myMqSensor.sendMQ(mqMessage)
        #automationhat.light.comms.write(0) # Comm light on to show activity.
        
        # complex if conditions so I pulled them into variables
        ifWeatherTrend = ((myWeather.isTrend('Rain') or myWeather.isTrend('Snow')) and state != 5)
        ifSunrise = ((numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 1)
        ifSunset = ((numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 4)
        
        ifIrrigationButton = (str(mySensor.settings['irrigationButton']) =='1');
        ifHose = (str(mySensor.settings['hoseButton']) =='1') ;
        
        ifBauFromSunrise = (not(numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 1) 
        ifBauFromSunset = (not(numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 4)
        ifBauFromIrrigationButton = (ifIrrigationButton == False and state == 3)
        ifBauFromHoseButton = (ifHose == False and state == 2)
        ifBauFromStartup = ((ifIrrigationButton or ifHose) and state == -2)
        
        if (ifWeatherTrend == True and (ifHose == False and state != 2)):
            state = 5 # Weather is rain or snow 
            #automationhat.light.comms.write(1) # Comm light on to show activity.
            
            mySensor.hose = 0
            mySensor.irrigation = 0
            mySensor.pumpPWM = pwmMid
            mySensor.setValues()
            gpio.output([irrigationPin,  hosePin],  gpio.LOW)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(0) # update remote display            
            
            #automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifIrrigationButton and ifHose):
            #Fail
            #automationhat.light.comms.write(1) # Comm light on to show activity.
            
            mySensor.hose = 0
            mySensor.irrigation = 0
            mySensor.pumpPWM = pwmHigh
            mySensor.setValues()
            gpio.output([irrigationPin,  hosePin],  gpio.LOW)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(0) # update remote display            
            
            #automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifSunrise):
            # sunrise irrigation requested
            state = 1 # Sunrise state
            #automationhat.light.comms.write(1) # Comm light on to show activity.
            
            mySensor.hose = 0
            mySensor.irrigation = 1
            mySensor.pumpPWM = pwmHigh
            mySensor.setValues()
            gpio.output([irrigationPin],  gpio.HIGH)
            gpio.output([hosePin],  gpio.LOW)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(1) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            #automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifSunset):
            # sunrise irrigation requested
            state = 4 # Sunset state
            #automationhat.light.comms.write(1) # Comm light on to show activity.
            
            mySensor.hose = 0
            mySensor.irrigation = 1
            mySensor.pumpPWM = pwmHigh
            mySensor.setValues()
            gpio.output([irrigationPin],  gpio.HIGH)
            gpio.output([hosePin],  gpio.LOW)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(1) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            #automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifIrrigationButton and state != 3):
            # sunrise irrigation requested
            state = 3 # Sunrise state
            #automationhat.light.comms.write(1) # Comm light on to show activity.
            
            mySensor.hose = 0
            mySensor.irrigation = 1
            mySensor.pumpPWM = pwmHigh
            mySensor.setValues()
            gpio.output([irrigationPin],  gpio.HIGH)
            gpio.output([hosePin],  gpio.LOW)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(1) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            #automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifHose and state != 2):
            # hose requested on
            state = 2 # Hose state
            #automationhat.light.comms.write(1) # Comm light  on to show activity.
            
            mySensor.hose = 1
            mySensor.irrigation = 0
            mySensor.pumpPWM = pwmHigh
            mySensor.setValues()
            gpio.output([irrigationPin],  gpio.LOW)
            gpio.output([hosePin],  gpio.HIGH)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(1) # update remote display
            
            #automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifBauFromSunrise or ifBauFromSunset or ifBauFromStartup or ifBauFromIrrigationButton or ifBauFromHoseButton):
            # BAU state
            state = -1
            #automationhat.light.comms.write(1) # Comm light  on to show activity.
            
            mySensor.hose = 0
            mySensor.irrigation = 0
            mySensor.pumpPWM = pwmMid
            mySensor.setValues()
            gpio.output([irrigationPin,  hosePin],  gpio.LOW)
            #mqMessage = mySensor.setValues()
            #myMqControl.sendMQ(mqMessage)
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
Пример #5
0
def main():
    # i2c
    bus = smbus.SMBus(1) # send works on bus 1
    DEVICE_ADDRESS = 0x14
    DEVICE_REG_MODE1 = 0x00
    bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x01)
    #bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
    
    #displayBrightness = 0.5
    state = -2 # Startup state
    myWeather  = weather()
    myLedControl = ledcontrol() # init remote led control
    
    if automationhat.is_automation_hat():
        # init local automation hat
        automationhat.light.power.write(1)
    
    automationhat.light.comms.write(1)
    
    #time.sleep(0.05) # sleep to give the system time to set the LEDs
    
    mySettings = settingsClass() # get settings from db
    #mySettings.resetSettings()
    
    #  setup pwm
    #outpin = mySettings.settings['pwmPin']
    #pwmLow = mySettings.settings['pwmLow']
    #pwmMid = mySettings.settings['pwmMid']
    #pwmHigh = mySettings.settings['pwmHigh']
    
    # Start pwm
    #gpio.setmode(gpio.BCM)
    #gpio.setup(outpin,  gpio.OUT)
    #myPwm = gpio.PWM(outpin, mySettings.settings['pwmFrequency'])
    #myPwm.start(pwmMid) # pump init
    
    # Set sunrise sunset vars
    dayRollover = -1 # get new sunrise sunset times only once!
    mySunrise = sunRiseSet() # Get sunrise and sunset from DB
    
    # Config the display
    #scrollphathd.set_brightness(0.5)
    
    automationhat.light.comms.write(0)
    
    myTimeNow = datetime.datetime.now()
    currTime = myTimeNow.hour + myTimeNow.minute
    lastTime = currTime
    currHour = -1
    lastHour = -2
    
    while True:
        myTimeNow = datetime.datetime.now()
        currTime = myTimeNow.hour + myTimeNow.minute
        currHour = myTimeNow.hour
        
        # Update the time string for the display every minute
        if (currTime != lastTime and state == -1):
            lastTime = currTime
            #scrollphathd.clear()
            #scrollphathd.write_string(getStatusText(str(mySunrise.sunrise),  str(mySunrise.sunset)) , x=0, y=0, font=font5x7, brightness=0.5)
        
        # Update the weather trend (last 24 hours) every hour
        if (currHour != lastHour):
            lastHour = currHour
            myWeather.getWeather()
            myWeather.getRecentTrend()
        
        # get new sunrise and sunset times
        rollTime = myTimeNow.hour + myTimeNow.minute
        if (rollTime == 0 and dayRollover == -1):
            mySunrise = sunRiseSet()
            dayRollover = 0
        elif (rollTime == 0 and dayRollover == 0):
            dayRollover = 0
        else:
            dayRollover = -1
        
        numStartTime = (myTimeNow.hour * 3600) + (myTimeNow.minute * 60) + myTimeNow.second
        
        # i2c read
        #time.sleep(1)
        i2cRead = bus.read_byte_data(DEVICE_ADDRESS, 0)
        
        # complex if conditions so I pulled them into variables
        ifWeatherTrend = ((myWeather.isTrend('Rain') or myWeather.isTrend('Snow')) and state != 5)
        ifSunrise = ((numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 1)
        ifSunset = ((numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state != 4)
        ifIrrigationButton = (i2cRead == 12 and state != 3)
        ifHose = (i2cRead == 10 and state != 2)
        #ifIrrigationAndHose = (automationhat.input.one.read() == True and automationhat.input.two.read() == True)
        ifBauFromSunrise = (not(numStartTime >= mySunrise.numSunriseSeconds and numStartTime <= (mySunrise.numSunriseSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 1) 
        ifBauFromSunset = (not(numStartTime >= mySunrise.numSunsetSeconds and numStartTime <= (mySunrise.numSunsetSeconds + (mySettings.settings["pumpduration"] * 60))) and state == 4)
        ifBauFromIrrigationButton = (automationhat.input.two.read() == False and state == 3)
        ifBauFromStartup = ((automationhat.input.one.read() == False and state == 2) or state == -2)
        
        if (ifWeatherTrend == True and (ifHose == False and state != 2)):
            state = 5 # Sunrise state
            automationhat.light.comms.write(1) # Comm light on to show activity.
            
            automationhat.output.one.write(0) # irrigation solenoid on
            automationhat.output.two.write(0) # hose solenoid off
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(0) # update remote display            
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (automationhat.input.one.read() == True and automationhat.input.two.read() == True):
            #Fail
            automationhat.light.comms.write(1) # Comm light on to show activity.
            
            automationhat.output.one.write(0) # irrigation solenoid on
            automationhat.output.two.write(0) # hose solenoid off
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(0) # update remote display            
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifSunrise):
            # sunrise irrigation requested
            state = 1 # Sunrise state
            automationhat.light.comms.write(1) # Comm light on to show activity.
            
            #scrollphathd.clear()
            #scrollphathd.write_string('  irrigation on: ' + str(mySettings.settings["pumpduration"]) + ' mins', x=0, y=0, font=font5x7, brightness = displayBrightness)
            
            # action the water solenoid and pump
            automationhat.output.one.write(1) # irrigation solenoid on
            automationhat.output.two.write(0) # hose solenoid off
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
            
            myLedControl.setIrrigationGreen(1) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifSunset):
            # sunrise irrigation requested
            state = 4 # Sunset state
            automationhat.light.comms.write(1) # Comm light on to show activity.
            
            #scrollphathd.clear()
            #scrollphathd.write_string('  irrigation on: ' + str(mySettings.settings["pumpduration"]) + ' mins', x=0, y=0, font=font5x7, brightness = displayBrightness)
            
            # action the water solenoid and pump
            automationhat.output.one.write(1) # irrigation solenoid on
            automationhat.output.two.write(0) # hose solenoid off
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
            
            myLedControl.setIrrigationGreen(1) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifIrrigationButton):
            # sunrise irrigation requested
            state = 3 # Sunrise state
            automationhat.light.comms.write(1) # Comm light on to show activity.
            
            #scrollphathd.clear()
            #scrollphathd.write_string('  irrigation on: ' + str(mySettings.settings["pumpduration"]) + ' mins', x=0, y=0, font=font5x7, brightness = displayBrightness)
            
            automationhat.output.one.write(1) # irrigation solenoid on
            automationhat.output.two.write(0) # hose solenoid off
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
            
            myLedControl.setIrrigationGreen(1) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifHose):
            # hose requested on
            state = 2 # Hose state
            automationhat.light.comms.write(1) # Comm light  on to show activity.
            
            #scrollphathd.clear()
            #scrollphathd.write_string(' hose On', x=0, y=0, font=font5x7, brightness = displayBrightness)
            
            # action the water solenoid and pump
            automationhat.output.two.write(0) # irrigation solenoid off
            automationhat.output.two.write(1) # hose solenoid on
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x02) # pwm high
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(1) # update remote display
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
        elif (ifBauFromSunrise or ifBauFromSunset or ifBauFromStartup or ifBauFromIrrigationButton):
            # BAU state
            state = -1
            automationhat.light.comms.write(1) # Comm light  on to show activity.
            
            #scrollphathd.clear()
            #scrollphathd.write_string(getStatusText(str(mySunrise.sunrise),  str(mySunrise.sunset)) , x=0, y=0, font=font5x7, brightness = displayBrightness)
            
            # action the water solenoid and pump
            automationhat.output.one.write(0) # irrigation led off
            automationhat.output.two.write(0) # hose led off
            bus.write_byte_data(DEVICE_ADDRESS,  DEVICE_REG_MODE1,  0x01) # pwm mid
            
            myLedControl.setIrrigationGreen(0) # update remote display
            myLedControl.setHoseGreen(0) # update remote display
            
            automationhat.light.comms.write(0) # Comm light off to show activity.
Пример #6
0
def ledStateRead():
    myLedControl = ledcontrol()
    myLedControl.getStatus()

    return 'Code to be completed'