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 treatbuttonclickSmartHome(): try: dateNowObject = datetime.datetime.now() spin = commonTasks.spin_hopper(treatGPIO, hopperTime) if spin != 'ok': flash('Error! No feed activated! Error Message: ' + str(spin), 'error') return redirect(url_for('home_page')) flash('Treat success!') 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( ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" )
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 "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"