I plan to build a Rpi box that will sit in a wine cellar. It will perform a number of tasks, and I'm curious as to the feasibility of using a Model B Rpi for this.
- Monitor and log temperature and humidity with a DHT22 sensor
- Log visits by time, date and duration
- Log visits with Raspivid (at 2-4fps) using the Rpi Camera module, triggered on and off by light level/movement(?)
- Log everything to an SQL database
- Run a web server to collate and present statistics and logs graphically, as well as e-mail weekly summaries
- Offer warnings if temperature or humidity go outside given bounds, to twitter or e-mail
- Offer warnings if the light is on for too long
- Be voice controlled (no display or other input) through a microphone and speaker
The web server right now is apache2/php5/mySQL/phpmyadmin and Wordpress. Not the lightest solution, and truthfully, quite slow to use, but I'm familiar enough with php and Wordpress to be able to code something quite usable.
Writing the SQL to log the environmental metrics should be relatively easy, once I've figured out how to pull the data from it (it hasn't arrived yet). The warnings when out of bounds shouldn't present much trouble either. A cron job that checks the DHT22 sensor every minute for rapid change and writes a 15/30 minute average to the SQL dB (I don't expect much change, honestly!) will give me enough data to compile rolling averages (1 day, 1 week, 1 month, 3 months, 6 months, 1 year).
The video recording, however, presents a challenge. Essentially, there will be three sensory inputs on the device: a microphone, a temperature and humidity sensor, and the Rpi camera.
I need to detect whether or not anyone has entered in the last couple of seconds. Two things happen when someone enters: the latch on the lock clacks audibly, and the light is turned on.
Using the microphone to listen for sounds above a certain threshold could work, but runs the risk of causing false alarms: people stomping down the stairs; laundry being done in the adjacent room, etc.
The camera, then, seems to be the most solid alternative. And here there seem to be two alternatives: capture luminance, or movement.
Luminance: Run a script to poll the luminance of a distributed number of pixels in the frame to check whether or not the light is on. Even if someone forgot to turn the light off when leaving, a maximum duration of, say, 15 minutes, would ensure that 99% of all visits are logged correctly. Unfortunately, it is impossible to have two processes that use the camera running at the same time, and terminating the luminance process to do the recording presents the problem of how the recording can then terminate itself based on luminance.
Movement: Apparently, it is possible to use the raw feed of the camera to check for movement and capture individual frames when something moves (or x amount of pixels change position from one frame to the next). This would naturally set off the frame captures (or video recording, perhaps?) once the light is turned on, and stop naturally once things stop moving—and there shouldn't be any movement when the cellar is empty, regardless of whether or not the light is on. If video recording (and the termination thereof, should movement cease) isn't possible, using avconv to compile all the images into an .mp4-wrapped slideshow is possible, but highly inefficient resource wise, compared to raspvid.
A third option would be to add a luminance sensor, but I would prefer to stick to the three inputs I have so far (due to space concerns).
And through all of this, I need a way to record the duration.
Voice control should be manageable through either of the packages available. The device will have constant internet access and a decent, but not fantastic, upload speed.
It should be able to tell the user its IP address, current temperature and humidity, when the visit prior to this was, and so on and so forth—as well as a few easter eggs!
This is my current equipment list:
- Raspberry Pi Model B
- Raspberry Pi Camera
- Breadboard, wires and resistors
- DHT22 sensor
- Small, USB-powered speaker
- Microphone (jack)
- USB sound card
- USB Wi-fi dongle
- 5V 2A power adapter
- Unpowered USB hub (for positional flexibility)
- 16GB class 10 SD card
—Any idea how the cellar entry/exit could be triggered? It is a very static environment, and the camera/device will be at a fixed point.
—How would I go about generating a graph as a .png file and overlaying that onto a requested snapshot of the cellar?
—Should I be concerned about the humidity in the cellar as far as the electronic components are concerned?
