Skip to content

Commit 1385dff

Browse files
committed
2023-05-16 OctoPrint adaptation to expected kernel change - master branch - PR 1 of 2
Background: - #690 – Kernel update may remove /dev/ttyAMA0 Changes: 1. Adopts generic syntax for device specification to prompt user to add the relevant key (`OCTOPRINT_DEVICE_PATH`) and path (eg `/dev/ttyUDB0`) to `.env`. Example: ``` $ echo OCTOPRINT_DEVICE_PATH=/dev/ttyUSB0 >>~/IOTstack/.env ``` 2. Adopts `TZ=${TZ:-Etc/UTC}` 3. Corrects YAML "errors" identified by `yamllint`. 4. Rewrites documentation to explain the how-to of device-path setup in various situations. Signed-off-by: Phill Kelley <[email protected]>
1 parent 96f4297 commit 1385dff

File tree

2 files changed

+41
-51
lines changed

2 files changed

+41
-51
lines changed

.templates/octoprint/service.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ octoprint:
33
image: octoprint/octoprint
44
restart: unless-stopped
55
environment:
6-
- TZ=Etc/UTC
7-
# - ENABLE_MJPG_STREAMER=true
8-
# - MJPG_STREAMER_INPUT=-r 640x480 -f 10 -y
9-
# - CAMERA_DEV=/dev/video0
6+
- TZ=${TZ:-Etc/UTC}
7+
# - ENABLE_MJPG_STREAMER=true
8+
# - MJPG_STREAMER_INPUT=-r 640x480 -f 10 -y
9+
# - CAMERA_DEV=/dev/video0
1010
ports:
1111
- "9980:80"
1212
devices:
13-
- /dev/ttyAMA0:/dev/ttyACM0
14-
# - /dev/video0:/dev/video0
13+
- "${OCTOPRINT_DEVICE_PATH:?eg echo OCTOPRINT_DEVICE_PATH=/dev/serial0 >>~/IOTstack/.env}:/dev/ttyACM0"
14+
# - /dev/video0:/dev/video0
1515
volumes:
1616
- ./volumes/octoprint:/octoprint
1717

docs/Containers/Octoprint.md

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,33 @@ title: Octoprint
1010
* DockerHub [octoprint/octoprint](https://hub.docker.com/r/octoprint/octoprint)
1111
* GitHub [OctoPrint/octoprint-docker](https://github.com/OctoPrint/octoprint-docker)
1212

13-
## Device mappings
13+
## 3D Printer device mapping
1414

15-
When you select "OctoPrint" in the IOTstack menu, the service definition in your `docker-compose.yml`, contains the following under the `devices:` heading:
15+
The first time you try to bring up the OctoPrint container, you should expect to see the following error:
1616

17-
``` yaml
18-
devices:
19-
- /dev/ttyAMA0:/dev/ttyACM0
20-
# - /dev/video0:/dev/video0
17+
```
18+
parsing ~/IOTstack/docker-compose.yml: error while interpolating services.octoprint.devices.[]: required variable OCTOPRINT_DEVICE_PATH is missing a value: eg echo OCTOPRINT_DEVICE_PATH=/dev/serial0 >>~/IOTstack/.env
2119
```
2220

23-
### *the `/dev/ttyAMA0:/dev/ttyACM0` mapping*
24-
25-
The `/dev/ttyAMA0:/dev/ttyACM0` mapping should be read as saying "the physical Raspberry Pi device `/dev/ttyAMA0` is mapped to the logical OctoPrint container device `/dev/ttyACM0`".
26-
27-
The `/dev/ttyAMA0` device is used as a default because it is always present on Raspbian. If you bring up your container like that, the mapping will succeed and the container is unlikely to go into a restart loop.
21+
The message is telling you that you need to define the device path to your 3D Printer.
2822

29-
However, the OctoPrint container is unlikely to be able to connect to your 3D printer via `/dev/ttyAMA0` for the very simple reason that that is not how 3D printers usually appear on the Raspberry Pi. You need to work out *how* your printer presents itself and change the device mapping accordingly.
23+
You need to work out *how* your printer presents itself and define the external device accordingly.
3024

31-
#### option 1 - `/dev/ttyUSBn`
25+
### option 1 - `/dev/ttyUSBn`
3226

3327
Using "ttyUSBn" will "work" but, because of the inherent variability in the name, this approach is not recommended.
3428

3529
The "n" in the "ttyUSBn" can vary depending on which USB devices are attached to your Raspberry Pi and the order in which they are attached. The "n" may also change as you add and remove devices.
3630

3731
If the OctoPrint container is up when the device number changes, the container will crash, and it will either go into a restart loop if you try to bring it up when the expected device is not "there", or will try to communicate with a device that isn't your 3D printer.
3832

39-
#### option 2 - `/dev/serial/by-id/xxxxxxxx`
33+
Suppose you choose this method and your 3D Printer mounts as `/dev/ttyUSB0`, you would define your printer like this:
34+
35+
```console
36+
$ echo OCTOPRINT_DEVICE_PATH=/dev/ttyUSB0 >>~/IOTstack/.env
37+
```
38+
39+
### option 2 - `/dev/serial/by-id/xxxxxxxx`
4040

4141
The "xxxxxxxx" is (usually) unique to your 3D printer. To find it, connect your printer to your Raspberry Pi, then run the command:
4242

@@ -50,24 +50,20 @@ You will get an answer like this:
5050
usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_3b14eaa48a154d5e87032d59459d5206-if00-port0
5151
```
5252

53-
Note:
54-
55-
* If you have multiple serial devices attached, you will get multiple lines in the output. It is up to you to sort out which one belongs to your 3D printer, possibly by disconnecting and re-attaching the printer and observing how the list changes.
56-
* The uniqueness of device IDs is under the control of the device manufacturer. Each manufacturer *should* ensure their devices are unique but some manufacturers are more diligent than others.
57-
58-
Assuming the above example output was the answer, edit `docker-compose.yml` to look like this:
53+
Suppose you choose this method and your 3D Printer mounts as shown above. You would define your printer like this:
5954

60-
``` yaml
61-
devices:
62-
- /dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_3b14eaa48a154d5e87032d59459d5206-if00-port0:/dev/ttyACM0
55+
```console
56+
$ echo OCTOPRINT_DEVICE_PATH=/dev/serial/by-id/usb-Silicon_Labs_CP2102N_USB_to_UART_Bridge_Controller_3b14eaa48a154d5e87032d59459d5206-if00-port0 >>~/IOTstack/.env
6357
```
6458

65-
Notes:
59+
Note:
6660

61+
* If you have multiple serial devices attached, you will get multiple lines in the output. It is up to you to sort out which one belongs to your 3D printer, possibly by disconnecting and re-attaching the printer and observing how the list changes.
62+
* The uniqueness of device IDs is under the control of the device manufacturer. Each manufacturer *should* ensure their devices are unique but some manufacturers are more diligent than others.
6763
* device *by-id* names follow the device. In other words, if you have two or more Raspberry Pis and a collection of serial devices (3D printers, Zigbee adapters, UARTs, and so on), a 3D printer will always get the same by-id name, irrespective of which Raspberry Pi it is attached to.
6864
* device *by-id* names do not persist if the physical device is disconnected. If you switch off your 3D printer or disconnect the USB cable while the OctoPrint container is running, the container will crash.
6965

70-
#### option 3 - `/dev/humanReadableName`
66+
### option 3 - `/dev/humanReadableName`
7167

7268
Suppose your 3D printer is a MasterDisaster5000Pro, and that you would like to be able to set up the device to use a human-readable name like:
7369

@@ -134,21 +130,22 @@ Check your work by disconnecting, then re-connecting your 3D printer, and then r
134130
$ ls /dev
135131
```
136132

137-
You should expect to see the human-readable name you chose in the list of devices. You can then edit `docker-compose.yml` to use the name in the device mapping.
133+
You should expect to see the human-readable name you chose in the list of devices.
138134

139-
``` yaml
140-
devices:
141-
- /dev/MasterDisaster5000Pro:/dev/ttyACM0
135+
You would then define your printer like this:
136+
137+
```console
138+
$ echo OCTOPRINT_DEVICE_PATH=/dev/MasterDisaster5000Pro >>~/IOTstack/.env
142139
```
143140

144141
Notes:
145142

146143
* device names follow the device. In other words, if you have two or more Raspberry Pis and a collection of serial devices (3D printers, Zigbee adapters, UARTs, and so on), you can build a single `99-usb-serial.rules` file that you install on *all* of your Raspberry Pis. Then, you can attach a named device to any of your Raspberry Pis and it will always get the same name.
147144
* device names do not persist if the physical device is disconnected. If you switch off your 3D printer or disconnect the USB cable while the OctoPrint container is running, the container will crash.
148145

149-
### *the `/dev/video0:/dev/video0` mapping*
146+
## the `/dev/video0:/dev/video0` mapping
150147

151-
The `/dev/video0` device is assumed to be an official Raspberry Pi camera attached via ribbon cable.
148+
By default, video camera support is disabled. This is because it is unsafe to assume a camera is present on `/dev/video0`.
152149

153150
> See the [Webcams topic of the Octoprint Community Forum](https://community.octoprint.org/c/support/support-webcams/18) for help configuring other kinds of cameras.
154151
@@ -161,27 +158,19 @@ To activate a Raspberry Pi camera attached via ribbon cable:
161158
3. Edit `docker-compose.yml` and uncomment **all** of the commented-out lines in the following:
162159

163160
``` yaml
164-
devices:
165-
# - /dev/video0:/dev/video0
166161
environment:
167-
# - ENABLE_MJPG_STREAMER=true
168-
# - MJPG_STREAMER_INPUT=-r 640x480 -f 10 -y
169-
# - CAMERA_DEV=/dev/video0
162+
# - ENABLE_MJPG_STREAMER=true
163+
# - MJPG_STREAMER_INPUT=-r 640x480 -f 10 -y
164+
# - CAMERA_DEV=/dev/video0
165+
166+
devices:
167+
# - /dev/video0:/dev/video0
170168
```
171169

172170
Note:
173171

174172
* The device path on the right hand side of the `CAMERA_DEV` environment variable corresponds with the right hand side (ie *after* the colon) of the device mapping. There should be no reason to change either.
175173

176-
The three environment variables are required:
177-
178-
``` yaml
179-
environment:
180-
- ENABLE_MJPG_STREAMER=true
181-
- MJPG_STREAMER_INPUT=-r 640x480 -f 10 -y
182-
- CAMERA_DEV=/dev/video0
183-
```
184-
185174
The "640x480" `MJPG_STREAMER_INPUT` settings will probably result in your camera feed being "letterboxed" but they will get you started. A full list of options is at [mjpg-streamer-configuration-options](https://community.octoprint.org/t/available-mjpg-streamer-configuration-options/1106).
186175

187176
The typical specs for a baseline Raspberry Pi camera are:
@@ -478,3 +467,4 @@ $ docker-compose up -d octoprint
478467
```
479468

480469
The OctoPrint container is well-behaved and will re-initialise its persistent storage area correctly. OctoPrint will adopt "first run" behaviour and display the Setup Wizard.
470+
bbedit

0 commit comments

Comments
 (0)