An automated door for our chicken coop, plus a Raspberry Pi that livestreams two cameras to the browser using WebRTC.
The main goal of this project is to automatically open the door in the morning (using a gear motor), and to close it at night.
In the controller, a combination of RTC and ambient light sensor is used:
- In the morning, the door will open if the
OPENING_LUX_THRESHOLD
is passed, but not beforeEARLIEST_OPENING_TIME
. - If
LATEST_OPENING_TIME
is reached, the door will open even if theOPENING_LUX_THRESHOLD
has not yet been reached. - Once the door is open, it will not close again before
EARLIEST_CLOSING_TIME
is reached. - After
EARLIEST_CLOSING_TIME
, the door will close once the ambient light falls below the specifiedCLOSING_LUX_THRESHOLD
. - If the
CLOSING_LUX_THRESHOLD
is not reached atLATEST_CLOSING_TIME
, the door will close anyways.
To detect an open or closed door, reed switches are used.
The controller is connected via USB / serial to a Raspberry Pi. This Raspberry Pi is used for streaming two webcams to a website (an outdoor webcam and an indoor infrared night-sight webcam).
Additionally, the Raspberry Pi sends out Threema notifications whenever the
door status changes (or if an error occurs). For this, the observer-service
is used.
┌───────┐ ┌─────┐
│Initial├────────────────────┐ │Error│
└───────┘ │ └─────┘
│ │
▼ │
┌──────┐ ┌──────────┐ │
│Closed├────►│PreOpening│ │
└──────┘ └───────┬──┘ │
▲ │ │
│ ▼ │
┌──┴───────┐ ┌────┐ │
│PreClosing│◄──────┤Open│◄───┘
└──────────┘ └────┘
Initial
: The state when turned on. The controller will transition to the "Open" or "Closed" state depending on the sensor readings.Closed
: Waiting forEARLIEST_OPENING_TIME
PreOpening
: Waiting for eitherOPENING_LUX_THRESHOLD
orLATEST_OPENING_TIME
Open
: Waiting forEARLIEST_CLOSING_TIME
PreClosing
: Waiting forCLOSING_LUX_THRESHOLD
orLATEST_CLOSING_TIME
Error
: Reachable from any state when something goes wrong (e.g. reading a sensor)
If the firmware is in non-error state, the blue LED will toggle every second. If it's in error state, the LED will remain on.
To run unit tests:
cargo test --target x86_64-unknown-linux-gnu --tests
cd firmware
cargo flash --connect-under-reset --chip STM32F411CEUx --release
To open a serial connection:
python -m serial.tools.miniterm /dev/ttyACM0 9600
Then type ?
to see the help.
In addition, the rpi-image
directory contains a buildroot based Linux and all
configuration necessary to livestream two cameras (an USB webcam and a raspi
cam) to the web browser using WebRTC (backed by Janus as streaming server).
To build the Raspberry Pi image:
cd rpi-image
./build.sh