Skip to content

Commit

Permalink
Restructure docs a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
nvtkaszpir committed Apr 28, 2024
1 parent 762c78d commit 03c4886
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 17 deletions.
13 changes: 10 additions & 3 deletions docs/config.for.camera.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
# Create config for prusa-connect-camera-script env vars

Notice that each camera should have different fingerprint and token.
## Prusa Camera Token

`PRUSA_CONNECT_CAMERA_TOKEN` should be taken from [earlier step](./prusa.connect.md).

## Fingerprint

`PRUSA_CONNECT_CAMERA_FINGERPRINT` should be uniqe and set only once for each camera.

Fingerprint can be easily generated using command:

```shell
uuidgen
```

or via [online website](https://www.uuidgenerator.net/version4),
just copy/paste the output as fingerprint value into the config.

## Note

**Do not** change fingerprint after launching the script - thus camera is registered
and you may need to revert the change or delete and readd camera again and start
from scratch.

## Example devices

Other env vars are set depending on the camera device we want to use.

### Locally connected

- [Raspberry Pi CSI camera](./config.for.camera.csi.libcamera.md) - libcamera (recommended)
Expand Down
75 changes: 75 additions & 0 deletions docs/configuration.env.full.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Configuration Env Vars

Config for camera is to the script as environment variables (env vars).

* `SLEEP` - sleep time in seconds between image captures,
notice that PrusaConnect accepts images at most every 10s or slower.
Default value `10`.

* `PRINTER_ADDRESS` - Printer address to ping, if address is unreachable there
is no point in sending an image. Set to `127.0.0.1` to always send images.
Set to empty value to disable ping check and always send images.
Default value `127.0.0.1`

* `PRUSA_CONNECT_CAMERA_TOKEN` - required, PrusaConnect API key

* `PRUSA_CONNECT_CAMERA_FINGERPRINT` - required, PrusaConnect camera fingerprint,
use for example cli `uuidgen` or [web](https://www.uuidgenerator.net/version4)
to generate it, it must be at least 16 alphanumeric chars, 40 max.
Remember not to change this if it was already set, otherwise you need to
remove and add the camera again.

* `CAMERA_DEVICE` - camera device to use, if you use Raspberry Pi camera
attached to the CSI via camera ribbon then leave as is
Default `/dev/video0` which points to first detected camera.

* `CAMERA_SETUP_COMMAND` - camera setup command and params executed before
taking image, default value is empty, because some cameras do not support it,
in general you want to use something like v4l2-ctl parameters, so
so for example
`setup_command=v4l2-ctl --set-ctrl brightness=10,gamma=120 -d $CAMERA_DEVICE`
will translate to:
`v4l2-ctl --set-ctrl brightness=10,gamma=120 -d /dev/video0`

* `CAMERA_COMMAND` - command used to invoke image capture,
default is `rpicam-still`
available options:
* rpicam-still - using CSI camera + modern Raspberry Pi operating systems since
Debian 11 Bullseye
* raspistill - using CSI camera + older Raspberry Pi operating systems
* fswebcam - using USB camera + custom package 'fswebcam'
* anything else will be processed directly, so for example you could use
'ffmpeg' in here

* `CAMERA_COMMAND_EXTRA_PARAMS` -extra params passed to the camera program,
passed directly as `<command> <extra-params> <output_file>`
example values per specific camera:
<!-- markdownlint-disable line_length -->

* libcamera (rpicam-still)
`--immediate --nopreview --mode 2592:1944:12:P --lores-width 0 --lores-height 0 --thumb none -o`
* raspistill
`--nopreview --mode 2592:1944:12:P -o`
* fswebcam
`--resolution 1280x960 --no-banner`
* ffmpeg, in this case CAMERA_DEVICE is ignored, use it directly in the extra params
`-f v4l2 -y -i /dev/video0 -f image2 -vframes 1 -pix_fmt yuvj420p`

<!-- markdownlint-enable line_length -->

* `TARGET_DIR` - directory where to save camera images, image per camera will
be overwritten per image capture,
default value `/dev/shm` so that we do not write to microSD cards or read only
filesystems/containers. `/dev/shm` is a shared memory space. if you have more
printers you may need to increase this value on system level.

* `CURL_EXTRA_PARAMS` - extra params to curl when pushing an image,
default empty value, but you could for example add additional params if needed
such as `-k` if using tls proxy with self-signed certificate

* `PRUSA_CONNECT_URL` - Prusa Connect endpoint where to post images,
default value `https://webcam.connect.prusa3d.com/c/snapshot`
You could put here Prusa Connect Proxy if you use one.

For more in-depth details (no need to repeat them here) please see the top of
the [prusa-connect-camera.sh](https://github.com/nvtkaszpir/prusa-connect-camera-script/blob/master/prusa-connect-camera.sh).
16 changes: 16 additions & 0 deletions docs/configuration.env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Configuration Env Vars

## Minimum required env vars

Config for camera is to the script as environment variables (env vars).

The most important env vars are:

* `PRUSA_CONNECT_CAMERA_TOKEN`
* `PRUSA_CONNECT_CAMERA_FINGERPRINT`
* `CAMERA_COMMAND`
* `CAMERA_COMMAND_EXTRA_PARAMS`

Those env vars will be filled in in the next steps.

Full list of env vars can be seen [here](./configuration.env.full.md)
19 changes: 8 additions & 11 deletions docs/configuration.overview.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
# Configuration

Configs for devices are passed to the script as environment variables.

For more in-depth details (no need to repeat them here) please see the top of
the [prusa-connect-camera.sh](https://github.com/nvtkaszpir/prusa-connect-camera-script/blob/master/prusa-connect-camera.sh).
# Configuration Overview

Short overview of actions:

- ensure printer is up and running and sending status to Prusa Connect
* ensure printer is up and running and sending status to Prusa Connect
(otherwise images will be discarded)
- add new camera to the existing printer in Prusa Connect, obtain token
- create config for prusa-connect-camera-script env vars
- test the config
- install script as service
* [add new camera](./prusa.connect.md) to the existing printer in Prusa Connect,
obtain token and generate fingerprint
* create config for prusa-connect-camera-script [env vars](./config.for.camera.md)
* [test the config](./test.config.md)
* install script as systemd [service](./service.systemd.md)
* [tuning config](./configuration.tuning.md)
3 changes: 2 additions & 1 deletion docs/prusa.connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- select `Printer`
- select `Camera`
- on the bottom click `Add new other camera`
- new camera is created, copy `Token`, this is needed later
- new camera is created, copy `Token`, this is needed later as
`PRUSA_CONNECT_CAMERA_TOKEN` env var
7 changes: 7 additions & 0 deletions docs/service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Install script as service

Depending on the distro there are various options to configure scripts as service.

* [systemd](./service.systemd.md) - most common service on Linux systems

Other - not implemented, do it on your own.
16 changes: 16 additions & 0 deletions docs/service.systemd.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,19 @@ sudo systemctl status prusa-connect-camera@esphome1.service
```

I hope you get the idea...

## Uninstall systemd service

Just run two commands per camera (where `csi` is a camera config):

```shell
sudo systemctl stop prusa-connect-camera@csi.service
sudo systemctl disable prusa-connect-camera@csi.service
```

After removing all cameras remove systemd service definition and reload daemon:

```shell
sudo rm -f /etc/systemd/system/prusa-connect-camera@.service
sudo systemctl daemon-reload
```
2 changes: 1 addition & 1 deletion docs/test.config.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ and get the outputs from the command, and also it should write an image.
Check for errors, if any, if everything is ok you should see a lot of `204`
every 10s.

If not, well, raise an issue on GitHub.
If not, well, raise an [issue on GitHub](https://github.com/nvtkaszpir/prusa-connect-camera-script/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc).
7 changes: 6 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ nav:
- Preparation:
- Requirements: requirements.md
- Installation: installation.md
- Configuration Overview: configuration.overview.md
- Configuration:
- Overview: configuration.overview.md
- Env vars: configuration.env.md
- Prusa Connect:
- Add camera to Prusa Connect: prusa.connect.md

Expand All @@ -67,9 +69,12 @@ nav:
- Test:
- Test Config: test.config.md
- Service:
- Overview: service.md
- Systemd: service.systemd.md

- Configuration Tuning: configuration.tuning.md
- Configuration all env vars: configuration.env.full.md

- Performance: performance.md

- Advanced:
Expand Down

0 comments on commit 03c4886

Please sign in to comment.