def manual():
    # the ON manual button was pressed
    print("Manual override button pressed")
    gpio.output(valve_pin, gpio.LOW)
    # post ON time to Azure Queue
    postdata = {'ON':''}
    postdata['ON'] = time.time()
    print(postazq.postazq(postdata))
    while (gWateringStatus == True):
      updateSched()
      sleep(1)
    gpio.output(valve_pin, gpio.HIGH)
    # post OFF time to Azure Queue
    postdata = {'OFF':''}
    postdata['OFF'] = time.time()
    print(postazq.postazq(postdata))
def waterCycle(t):
    global gWateringStatus
    now = time.time()
    # check soil moisture
    if ( gpio.input(moisture_pin) == gpio.LOW ):
        print("Soil above moisture threshhold, skip watering")
        gWateringStatus = False
        # wait a minute before return
        then = time.time() + 60
        while ( time.time() < then ):
           updateSched()
           sleep(1)
        return
    print("watering, gpio on at " + str(now))
    gpio.output(valve_pin, gpio.LOW)
    # post ON time to Azure Queue
    postdata = {'ON':''}
    postdata['ON'] = now
    print(postazq.postazq(postdata))
    gWateringStatus = True
    # get weather forecast 
    jfc = weather.weather()
    # adjust duration down by prediction of rain
    duration = t * (1. - jfc["hourly"]["data"][0]["precipProbability"])
    print("watering for " + str(duration) + " seconds")
    then = time.time() + duration
    while ( (gWateringStatus == True) and (time.time() < then ) ):      # in case watering is canceled by the STOP button
      updateSched()
      sleep(1)
    now = time.time()
    print("Done watering, gpio off " + str(now))
    gpio.output(valve_pin, gpio.HIGH)
    # post OFF time to Azure Queue
    postdata = {'OFF':''}
    postdata['OFF'] = now
    print(postazq.postazq(postdata))
    if ( gWateringStatus == "Canceled" ):	# if canceled, wait a minute before resuming normal so another cycle doesn't kick off 
        then = time.time() + 60
        while ( time.time() < then ):
           updateSched()
           sleep(1)
    gWateringStatus = False