Chili Plant Monitor
After moving desks around the turn of the year into a new room with windows, a bit of a rarity at CriticalBlue, a colleague and I decided it was time to add some greenery to our, at this point, boring corner office. The obvious thing to grow was a bunch of chili plants! Amazon provided me with a pack of easy to grow Apache F1 seeds, some pots and a bag of compost. After covering my desk, the floor and myself in soil I had some lifeless pots of soil. Weeks passed and some growth was observed! However, I couldn’t help but wonder whether it was warm enough on my draughty window sill for life to flourish? What happened at the weekend when the office was empty, did the heating go off dropping the temperature to unbearable levels? It was February in Edinburgh after all. The answer to these questions lay in an unused Raspberry Pi I had at home!
I brought in my Raspberry Pi, a DS18B20+ Temperature sensor and some bread board. You can see how I linked it all up below and visit modmypi for a step by step guide on how to get started. A simple example of how to read the temperature in Python can be found here.
Now I could ask my sensor the temperature at any time and get a reading back, progress! Asking it repeatedly myself was fine but I really wanted something to monitor stuff when I wasn’t there, after all that’s when it’s going to be coldest. As part of some other (actual) work I was doing I’d been playing about with the Highcharts graphing library. Wouldn’t it be great to graph the last 24 hours of temperature readings! I could see highs and lows then decide if there were any trends worth acting on.
You can see an example of the chart produced below. It turns out that the temperature in the office was fine, it never really dropped much below 18°c. This didn’t stop me wanting to extend the monitoring though!
The obvious next step was to take pictures of the plants as they grew. I scrounged an old Android phone which was hanging about in the office and set it up in the very professional looking holster you can see below. I wrote a script which runs as a cron job every 10 minutes on my workstation which instructs the phone to take a picture using ADB then pulls it across to the host machine. It then overlays the current time and temperature on the image and sends it to another machine to be displayed on our company intranet. This script is here.
What do you do with a bunch of images taken over a period of time of a subject which is constantly changing? You make a timelapse! I amended the script from above to store every image taken between 12 and 1pm each day, hoping that’s when there would be most light.
Making a timelapse from a bunch of images in Linux is really easy. Make sure your images are sequentially numbered from oldest to newest.
ls -tr | cat -n | while read n f; do mv "$f" "$n.jpeg"; done
Then allow ffmpeg to do its stuff to turn this into a video. This video might play too quickly, you can use mencoder to fix this. See Google, mine turned ok without tweaking.
ffmpeg -i %d.jpg -r 25 -s 1280x960 -b:v 30000k Flapse_25fps.mp4
This produces a pretty big file, about 75MB for 600 images. I turned this into a webm for display on internet.
avconv -i Flapse_25fps.mp4 -acodec libvorbis -aq 5 -ac 2 -qmax 25 -threads 8 timelapse.webm