Simple rust program that captures images on a Raspberry Pi.
Note: This was tested using a Raspberry Pi 4 Model B Rev 1.4 and Ardu Camera
- Clone repo to Raspberry Pi
git clone https://github.com/software-trizzey/simple_auto_camera_raspberrypi.git
- Navigate to project
cd simple_auto_camera_raspberrypi
- Build program
cargo build --release
- Run production version
./release/simple_auto_camera_raspberrypi.bin
Assuming the camera is set up correctly and no errors are encountered, a new image should appear in the static
directory.
Run command below on host machine:
scp -r [pi_username]@[raspberrypi_ip_address]:[path_to_program_on_pi]/simple_auto_camera_raspberrypi/static [directory_on_host_machine]
Example:
scp -r pi@[ip-address-redacted]:/home/pi/Projects/simple_auto_camera_raspberrypi/static ~/Desktop/pi-images/
Note: This will run the program every 30 minutes. Adjust the OnCalendar
value (ex. OnCalendar=hourly or every minute: OnCalendar=*:0/1) in the timer file for a different interval.
- Build the Rust Program
cargo build --release
sudo cp target/release/simple_auto_camera_raspberrypi /usr/local/bin/simple_auto_camera_raspberrypi
- Create the Service File
sudo nano /etc/systemd/system/run_camera.service
File Content:
[Unit]
Description=Run Raspberry Pi Camera
After=network.target
[Service]
ExecStart=/usr/local/bin/simple_auto_camera_raspberrypi
Restart=on-failure
Environment="DISCORD_URL=<your_discord_server_url"
WorkingDirectory=/home/pi/Projects/simple_auto_camera_raspberrypi
[Install]
WantedBy=multi-user.target
- Create the Timer File
sudo nano /etc/systemd/system/run_camera.timer
File Content:
[Unit]
Description=Run Raspberry Pi Camera Every 30 minutes
[Timer]
OnCalendar=*:0/30
Persistent=true
[Install]
WantedBy=timers.target
- Start and Enable the Timer
sudo systemctl daemon-reload
sudo systemctl enable run_camera.timer
sudo systemctl start run_camera.timer
Note: You can manully test the service using sudo systemctl start run_camera.service
- Verify the Timer
systemctl list-timers --all
- Check Service Logs
journalctl -u run_camera.service
- This project provides an API for our program to interact with the raspberry pi camera.