A simple python class that controls a petfeeder. Features include:
See the full writeup at Hackster.io
If you want to use Alexa app or view data via the web site sign up here https://onlineservicehub.azurewebsites.net/ (beta)
https://github.com/editter/PetFeeder/
TOKEN = "<Token>"
DEVICE_ID = "<Device-Id>"
DEVICE_KEY = "<Device-Key>"
FEEDER = PetFeeder(TOKEN,
{"SERVO": 18,
"BUTTON": 19,
"DISTANCE_IN": 23,
"DISTANCE_OUT": 24})
FEEDER.init_schedule()
FEEDER.init_listener(DEVICE_ID, DEVICE_KEY)
FEEDER.loop_forever()
Default constructor
token - string Used for authentication to post data to the website
options - json [Default: None] Options that are used in the class. Use get_config() to view view available options and their defaults
number - Pin for connecting to a servonumber - Pin for connecting to a buttonnumber - Pin for connecting to a distance sensor (in)number - Pin for connecting to a distance sensor (out)string - Location of the file that will be used as a comparison for a full dishstring - Location of the file that will be taken when CHECK_DISH is runstring - Location where log files will be stored reletave to running directoryboolean - Allows logging to be enabled/disablednumber - The number of seconds that a servo will run when feeding occursGets the current configuration information
stringFolder relative to running directory
Runs a servo for a specified amount of time
number [Default: 5]Time the servo will run (default) = 5
Check”s how full the dish is. Comparison is done by looking at config[“FULL_DISH_IMAGE”] and config[“COMPARE_DISH_IMAGE”]
Returns - number
Percent of how full the dish is
Check the hoppers current percent full
Returns - number
Percent of how full the hopper is
Sends an update to the server
jsonArguments that will be passed to the server
file [Default: None]Image of the dish that will be uploaded
Callback from IOT Hub event trigger
objectJSON string containing command instructions
numberTime the servo will run (default) = 5
Initiates a connection to receive messages from the web site
stringDevice Id that was created via the web site sign up
stringDevice Key that was created via the web site sign up
Initiates a the schedule that the feeder will automatically feed
array<string> [Default: ["08:00", "20:00"]] The times that the feeder will call run_servo()Check if anything is happening such as button presses, schedules, etc. and run those features
Will keep the application running indefinately and call run_events()