def feedbuttonclickSmartHome(): try: dateNowObject = datetime.datetime.now() spin = commonTasks.spin_hopper(hopperGPIO, hopperTime) if spin != 'ok': flash('Error! No feed activated! Error Message: ' + str(spin), 'error') return redirect(url_for('home_page')) dbInsert = commonTasks.db_insert_feedtime(dateNowObject, 4) # FeedType 4=Smart Home if dbInsert != 'ok': flash('Warning. Database did not update: ' + str(dbInsert), 'warning') updatescreen = commonTasks.print_to_LCDScreen( commonTasks.get_last_feedtime_string()) if updatescreen != 'ok': flash( 'Warning. Screen feedtime did not update: ' + str(updatescreen), 'warning') flash('Feed success!') return redirect(url_for('home_page')) except Exception as e: return render_template('error.html', resultsSET=e)
def feedbuttonclick(): try: dateNowObject = datetime.datetime.now() spin = commonTasks.spin_hopper(hopperGPIO, hopperTime) if spin <> 'ok': flash( 'Error! The ladies have not been feed! Error Message: ' + spin, 'error') return redirect(url_for('home_page')) dbInsert = commonTasks.db_insert_feedtime(dateNowObject, 2) if dbInsert <> 'ok': flash('Warning. Database did not update: ' + dbInsert, 'warning') updatescreen = commonTasks.print_to_LCDScreen( commonTasks.get_last_feedtime_string()) if updatescreen <> 'ok': flash('Warning. Screen feedtime did not update: ' + updatescreen) flash('Feed success!') return redirect(url_for('home_page')) except Exception, e: return render_template('error.html', resultsSET=e)
def scheduleRepeatingDatetime(): try: scheduleRepeatingTime = [request.form['scheduleRepeatingTime']][0] timeobj = datetime.datetime.strptime(scheduleRepeatingTime, '%H:%M').time() dbInsert = commonTasks.db_insert_feedtime(timeobj, 5) # FeedType 5=Repeat Daily Scheduled Feed if dbInsert != 'ok': flash('Error! The time has not been scheduled! Error Message: ' + str(dbInsert), 'error') return redirect(url_for('home_page')) flash("Time Scheduled") return redirect(url_for('home_page')) except Exception as e: return render_template('error.html', resultsSET=e)
def scheduleDatetime(): try: scheduleDatetime = [request.form['scheduleDatetime']][0] dateobject = datetime.datetime.strptime(scheduleDatetime, '%Y-%m-%dT%H:%M') dbInsert = commonTasks.db_insert_feedtime(dateobject, 0) if dbInsert <> 'ok': flash( 'Error! The time has not been scheduled! Error Message: ' + dbInsert, 'error') return redirect(url_for('home_page')) flash("Time Scheduled!") return redirect(url_for('home_page')) except Exception, e: return render_template('error.html', resultsSET=e)
def scheduleDatetime(): try: scheduleDatetime = [request.form['scheduleDatetime']][0] scheduleTime = [request.form['scheduleTime']][0] dateobj = datetime.datetime.strptime(scheduleDatetime, '%Y-%m-%d') timeobj = datetime.datetime.strptime(scheduleTime, '%H:%M').time() dateobject = datetime.datetime.combine(dateobj, timeobj) dbInsert = commonTasks.db_insert_feedtime(dateobject, 0) # FeedType 0=One Time Scheduled Feed if dbInsert != 'ok': flash('Error! The time has not been scheduled! Error Message: ' + str(dbInsert), 'error') return redirect(url_for('home_page')) flash("Time Scheduled") return redirect(url_for('home_page')) except Exception as e: return render_template('error.html', resultsSET=e)
#logger.info("The counter is now " + str(i)) if GPIO.input(feedButton) == 0: print "-------------------------------------------------------------------------" time.sleep(.1) buttonPressDatetime=datetime.datetime.now() print "Button was pressed at "+str(buttonPressDatetime) lastFeedDateCursor = commonTasks.db_get_last_feedtimes(1) lastFeedDateString = lastFeedDateCursor[0][0] lastFeedDateObject = datetime.datetime.strptime(lastFeedDateString, "%Y-%m-%d %H:%M:%S") print "Last feed time in DB was at " + str(lastFeedDateObject) tdelta = buttonPressDatetime - lastFeedDateObject print "Difference in seconds between two: " + str(tdelta.seconds) if tdelta.seconds < int(delayBetweenButtonPushes): print "Feed times closure than "+str(delayBetweenButtonPushes)+ " seconds. Hold off for now." else: # !!!!!!!!!!!!!!!!!!!!!!!!!put in code to check if return true=completed successfully!!!!!!!!!!!!!!!!!!!!!!!!! spin=commonTasks.spin_hopper(hopperGPIO,hopperTime) print "End Hopper return status: "+spin dblog=commonTasks.db_insert_feedtime(buttonPressDatetime,1) print "End DB Insert return status: "+dblog updatescreen=commonTasks.print_to_LCDScreen(commonTasks.get_last_feedtime_string()) print "End Message Display return status: " + updatescreen print "-------------------------------------------------------------------------" if killer.kill_now:break print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" print "End of the program. I was killed gracefully :)" print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
GPIO.setup(treatButton, GPIO.IN, pull_up_down=GPIO.PUD_UP) print("End Start up. Starting while loop") print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ) while True: if GPIO.input(treatButton) == 0: print( "-------------------------------------------------------------------------" ) time.sleep(.1) if tdelta.seconds < int(delayBetweenButtonPushes): print("Feed times closure than " + str(delayBetweenButtonPushes) + " seconds. Hold off for now.") else: spin = commonTasks.spin_hopper(treatGPIO, hopperTime) print("End Hopper return status: " + str(spin)) dblog = commonTasks.db_insert_feedtime(buttonPressDatetime, 1) print("End DB Insert return status: " + str(dblog)) if killer.kill_now: break print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" ) print("End of the program loop. Killed gracefully") print( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" )
print('Not past due yet') # print present, value, d[0],x if d[0] > 1: print('Scheduled record found past due') print("Current time: " + str(present)) print("Scheduled time: " + str(value)) print("Minutes difference: " + str(d[0])) spin = commonTasks.spin_hopper(hopperGPIO, hopperTime) if spin != 'ok': print('Error! Feeder not activated! Error Message: ' + str(spin)) dbInsert = commonTasks.db_insert_feedtime(value, 3) if dbInsert != 'ok': print('Warning. Database did not update: ' + str(dbInsert)) updatescreen = commonTasks.print_to_LCDScreen( commonTasks.get_last_feedtime_string()) if updatescreen != 'ok': print('Warning. Screen feedtime did not update: ' + str(updatescreen)) print('Auto feed success') # Delete one off scheduled feeds now. Keep reoccuring feed schedules in DB. # Reoccuring daily feed times have date 1900-01-01 as placeholder in DB if str(x[2]) == '5': # Do not delete as scheduled will therefore be deleted. Deleted scheduled times through UI.