Installing HKCam on a Raspberry Pi with one of the good old ribbon camera modules works well... if you come over some hiccups.
Here is how I get it to work:
Setup a fresh RaspbianLite and install HKCam by following the instructions on: https://github.com/brutella/hkcam
Enable legacy camera support:
$ sudo raspi-config nonint get_legacy
$ sudo raspi-config nonint do_legacy 0
$ sudo reboot
Afterwards, you should get output similar to the following:
$ vcgencmd get_camera
supported=1 detected=1, libcamera interfaces=0
https://github.com/brutella/hkcam/issues/141#issuecomment-1687316736
Create a new systemd service file:
$ sudo nano /etc/systemd/system/hkcam.service
Add the following content to the file:
[Unit]
Description=HKCam HomeKit Camera Service
After=network.target
[Service]
ExecStart=/home/user/hkcam -data_dir=/var/lib/hkcam/data -multi_stream=true -port=8080
Restart=always
User=user
[Install]
WantedBy=multi-user.target
modify ExecStart=/home/user/hkcam
and User=user
according to your HKCam location and user.
$ sudo chmod 644 /etc/systemd/system/hkcam.service
Reload the systemd daemon:
$ sudo systemctl daemon-reload
Enable the HKCam service to start at boot:
$ sudo systemctl enable hkcam.service
Start the service
You can start the service immediately without rebooting:
$ sudo systemctl start hkcam.service
Verify the service
Check the status of the service:
$ sudo systemctl status hkcam.service
If you encounter any issues, you can check the system logs for more information:
$ journalctl -u hkcam.service
This should work now but the image quality is terrible. Can we fix this?
Check video resolution of connected camera:
$ v4l2-ctl --list-formats-ext
Then you can create and edit the file /etc/sv/hkcam/run
to fiddle around with some settings:
pi@raspberrypi:~ $ cat /etc/sv/hkcam/run
#!/bin/sh -e
exec 2>&1
v4l2-ctl --set-ctrl=rotate=90
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=YU12
v4l2-ctl -c video_bitrate=1000000
exec hkcam --data_dir=/var/lib/hkcam/data --verbose=true
Make it unable with $ sudo chmod +x /etc/sv/hkcam/run
.