Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*.o
/bambucam
.env
*.so
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM debian:bookworm-slim

ENV DEBIAN_FRONTEND=noninteractive

ENV DEVICE_IP="printer-ip"
ENV DEVICE_ID="printer-serial-number"
ENV ACCESS_CODE="printer-access-code"
ENV PORT=8082

# true = retry to reach printer if its offline, false = shutdown
ENV KEEP_ALIVE=true

# the interval (seconds) the printer is checked until available
ENV PING_INTERVAL=10

RUN apt-get update && apt-get install -y --no-install-recommends \
libmicrohttpd12 \
libjpeg62-turbo \
netcat-openbsd \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /app

RUN mkdir plugins

# copy the executable and plugins
COPY ./bambucam .
COPY ./plugins ./plugins

# set plugin path
ENV PLUGIN_PATH=/app/plugins

EXPOSE ${PORT}


COPY start.sh .
RUN chmod +x start.sh
ENTRYPOINT ["./start.sh"]
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,38 @@ flag. The supported video stream types are:
- `HTTP`: Multipart JPEG stream using microhttpd
- `RTP`: RTP video stream using FFmpeg

## Docker Usage
Use the following docker-compose.yaml to spawn a video-server:
````yaml
version: "3.8"

services:
bambucam:
image: dockersilas/bambucam:1.0.0
container_name: bambucam

ports:
- "8082:8082" # the port number mapping where the video stream is serviced

environment:
- DEVICE_IP="192.168.1.123" # your printers ip
- DEVICE_ID="1A2B3C12345678" # your printer serial number (tho check if its the right device)
- ACCESS_CODE="12345678" # your printer access code
- PORT=8082 # the port number where the video stream should be serviced
- KEEP_ALIVE=true # true = run infinitly retrying if printer is offline, false = shutdown if printer offline
- PING_INTERVAL=10 # the interval (seconds) the printer is checked until available

restart: no
````

## Building the Image
If you want to build the docker image by yourself, follow those steps:
- clone this repo
- create a folder "plugins"
- put your "libBambuStudio.so" in there which is made available by Bambulab Software
- follow the building steps of jtessler´s repo (building the bambucam executeable in the repo root directory)
- build using the Dockerfile

## Build instructions

Prepare the necessary `ffmpeg` and `libmicrohttpd` dependencies:
Expand Down
16 changes: 16 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: "3.8"

services:
bambucam:
image: dockersilas/bambucam:1.0.0
container_name: bambucam

ports:
- "8082:8082" # the port number mapping where the video stream is serviced

env_file:
- .env

restart: no


56 changes: 56 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/sh
set -e

# ENV defaults
DEVICE_IP="${DEVICE_IP}"
DEVICE_ID="${DEVICE_ID}"
ACCESS_CODE="${ACCESS_CODE}"
PORT="${PORT}"
KEEP_ALIVE="${KEEP_ALIVE}" # true = bleibt an, false = Container exit bei Fehler
PING_INTERVAL="${PING_INTERVAL}" # Sekunden zwischen Pings


# Funktion zum Maskieren, nur letzte 2 Zeichen anzeigen
# mask() {
# local val="$1"
# local len=${#val}
# if [ $len -le 2 ]; then
# echo "$val"
# else
# mask_len=$((len-2))
# masked=$(printf '%*s' "$mask_len" '' | tr ' ' '*')
# echo "${masked}${val: -2}"
# fi
# }

# Ausgabe aller ENV-Werte beim Start
echo "=== STARTING bambucam container ==="
echo "DEVICE_IP = $DEVICE_IP"
echo "DEVICE_ID = $DEVICE_ID"
echo "ACCESS_CODE = $ACCESS_CODE"
echo "PORT = $PORT"
echo "KEEP_ALIVE = $KEEP_ALIVE"
echo "PING_INTERVAL = $PING_INTERVAL"
echo "=================================="

while true; do
# Prüfen, ob der Printer erreichbar ist
if nc -z -w2 "$DEVICE_IP" "6000"; then
echo "$(date '+%F %T') - printer available, starting bambucam"
# Bambucam starten und auf Exit warten
./bambucam "$DEVICE_IP" "$DEVICE_ID" "$ACCESS_CODE" "$PORT" || true
EXIT_CODE=$?
echo "$(date '+%F %T') - bambucam exited with code $EXIT_CODE"
else
echo "$(date '+%F %T') - Printer not reachable (offline?)"
EXIT_CODE=1
fi

if [ "$KEEP_ALIVE" != "true" ]; then
echo "KEEP_ALIVE=false → Shutdown container"
exit $EXIT_CODE
fi

echo "Waiting $PING_INTERVAL seconds before retrying..."
sleep $PING_INTERVAL
done