Software to run a humane mouse trap, written and built in Python 3.8 on a Raspberry Pi 4.
- Clone this repository to your local machine.
- cd to the cloned directory and intialise a venv by running the command below
python -m venv ./venv- Use this venv while developing. You can activate the venv using the command below.
# mac/linux
source ./venv/bin/activate
# windows
venv\Scripts\activate.bat- Install the dependencies from the requirements.txt file using pip.
pip install gpiozero
pip install pigpio
pip install RPi.GPIO- Start the service
python main.pyThe input_service.py file defines the configuration for the Raspberry Pi GPIO and executes "handlers" when an input is detected. It is currently configured to read button input from the GPIO18 pin, and call an email handler on button press.
To test this functionality, you will have to:
- Wire up a Pi4 with the button at GPIO18 (or change the value in
input_service.pyto read from another pin) - Add a recipient email address in
main.py - Add a valid gmail username/app key to act as the sender. More information on app keys can be found here.
- Start the service & press the button!
This service was built with some extensibility in mind. For example, if you also wanted to publish an event to a messaging queue on button press, you would simply write a function to publish a suitable message and register that function as a handler, as shown in main.py#run(). This pattern also confines the configuration details of the service to main.py.
If this service were to grow in size, an OOP approach could also be considered in which handlers could inherit from a base class & implement their own handler function to be executed when the base class detects input.