Now that I have a Raspberry Pi that can take pictures and turn electrical sockets on and off, as well as a trained image classifier that knows my cats, it was time to stitch everything together.
The Lola Detector
The following steps were taken to construct a small program that would scan an image on demand and identify Lola (or not):- Install TensorFlow on the Raspberry Pi as a Python library.
- Refactor the example image label Python script to start TensorFlow, load the model, and wait.
- Use Flask to create a URL that would kick off the image analysis function, and return a JSON object with the Lola/Maddie label probabilities.
- Keep this program running.
The Lola Feeder
Rather than use Python for the whole app (like a sane person), I opted for Node to do the rest of the stuff. A big, convoluted Node script does the following:- Takes a picture with raspistill and saves it as rpicam.jpg.
- Sends an http request to the Lola Detector service, and waits for a response.
- Checks the response for a high Lola probability.
- If Lola is NOT found, go back to step 1.
- If Lola is found, send a signal via the FM transmitter to power on the cat feeder.
- Send a tweet with the recently taken picture to a hidden Twitter account.
- Send a message to IFTTT which sends me a push notification.
- Wait 60 seconds and send another signal to power off the feeder.
- Wait 90 minutes and go back to step 1.