diff --git a/.github/workflows/3dprinter-remote.yml b/.github/workflows/3dprinter-remote.yml new file mode 100644 index 0000000..68bff1c --- /dev/null +++ b/.github/workflows/3dprinter-remote.yml @@ -0,0 +1,54 @@ +name: 3DPrinter-Remote manual build + +on: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + name: Build ${{ matrix.arch }} ${{ matrix.addon }} add-on + strategy: + matrix: + addon: ["3dprinter-remote"] + arch: ["aarch64", "amd64", "armhf", "armv7", "i386"] + steps: + - name: Check out the repository + uses: actions/checkout@v3 + + - name: Get information + id: info + uses: home-assistant/actions/helpers/info@master + with: + path: "./${{ matrix.addon }}" + + - name: Check if add-on should be built + id: check + run: | + if [[ "${{ steps.info.outputs.architectures }}" =~ ${{ matrix.arch }} ]]; then + echo "::set-output name=build_arch::true"; + echo "::set-output name=image::$(echo ${{ steps.info.outputs.image }} | cut -d'/' -f3)"; + else + echo "${{ matrix.arch }} is not a valid arch for ${{ matrix.addon }}, skipping build"; + echo "::set-output name=build_arch::false"; + fi + + - name: Login to GitHub Container Registry + if: env.BUILD_ARGS != '--test' + uses: docker/login-action@v2.1.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build ${{ matrix.addon }} add-on + if: steps.check.outputs.build_arch == 'true' + uses: home-assistant/builder@2022.11.0 + with: + args: | + ${{ env.BUILD_ARGS }} \ + --${{ matrix.arch }} \ + --target /data/${{ matrix.addon }} \ + --image "${{ steps.check.outputs.image }}" \ + --docker-hub "ghcr.io/${{ github.repository_owner }}" \ + --addon \ + --docker-hub-check diff --git a/3dprinter-remote/Dockerfile b/3dprinter-remote/Dockerfile new file mode 100644 index 0000000..54bc39d --- /dev/null +++ b/3dprinter-remote/Dockerfile @@ -0,0 +1,14 @@ +ARG BUILD_FROM="ghcr.io/home-assistant/amd64-base" + +FROM ${BUILD_FROM} AS final + +ENV LANG C.UTF-8 + +RUN echo "Install base requirements." \ + && apk add --no-cache ser2net +COPY rootfs/ / +WORKDIR / + +# Make files executable +RUN chmod +x /etc/cont-init.d/*.sh +RUN chmod +x /etc/services.d/*/* diff --git a/3dprinter-remote/README.md b/3dprinter-remote/README.md new file mode 100644 index 0000000..f1a061b --- /dev/null +++ b/3dprinter-remote/README.md @@ -0,0 +1,11 @@ +# 3DPrinter-Remote + +Provides remote access to 3DPrinter. Add-on runs ser2net and can be connected to by e.g. socat. + +## Usage + +On the machine connected to the printer (`remote machine`): +* Setup the add-on. At minimum you will need to specify `printer_path` and verify that `baud_rate` is correct. + +On the machine with OctoPrint: +* Go to Settings --> Serial Connection, section __Additional serial ports__. Add : `socket://:9999`. For example, use the IP for `remote machine`. \ No newline at end of file diff --git a/3dprinter-remote/config.yaml b/3dprinter-remote/config.yaml new file mode 100644 index 0000000..4904cb6 --- /dev/null +++ b/3dprinter-remote/config.yaml @@ -0,0 +1,29 @@ +name: "3DPrinter-Remote" +version: "2023.03.0" +slug: "3dprinter-remote" +description: "Add-on for accessing 3DPrinter remotely using socat" +url: "https://github.com/fredrikbaberg/ha-3dprinter-addons/tree/main/3dprinter-remote" +arch: + - armv7 + - amd64 + - armhf + - aarch64 + - i386 +stage: experimental +init: false +gpio: true +usb: true +uart: true +ports: + 9999/tcp: 9999 +ports_description: + 9999/tcp: Port for access to ser2net +options: + printer_path: "/dev/null" + printer_baudrate: "115200" + ser2net_args: "" +schema: + printer_path: "str" + printer_baudrate: "int" + ser2net_args: "str?" +image: ghcr.io/fredrikbaberg/ha-addon-3dprinter-remote-{arch} diff --git a/3dprinter-remote/rootfs/etc/cont-init.d/ser2net.sh b/3dprinter-remote/rootfs/etc/cont-init.d/ser2net.sh new file mode 100644 index 0000000..96456b3 --- /dev/null +++ b/3dprinter-remote/rootfs/etc/cont-init.d/ser2net.sh @@ -0,0 +1,14 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Add-on: 3dprinter-remote +# Setup ser2net.conf +# ============================================================================== + +# Generate ser2net configuration +bashio::var.json \ + printer_path "$(bashio::config 'printer_path')" \ + printer_baudrate "$(bashio::config 'printer_baudrate')" \ + ser2net_args "$(bashio::config 'ser2net_args')" \ + | tempio \ + -template /usr/share/tempio/ser2net/ser2net.conf.gtpl \ + -out /etc/ser2net.conf diff --git a/3dprinter-remote/rootfs/etc/services.d/ser2net/finish b/3dprinter-remote/rootfs/etc/services.d/ser2net/finish new file mode 100644 index 0000000..1ecc5e9 --- /dev/null +++ b/3dprinter-remote/rootfs/etc/services.d/ser2net/finish @@ -0,0 +1,9 @@ +#!/usr/bin/execlineb -S0 +# ============================================================================== +# Add-on: mjpg-streamer +# Take down the S6 supervision tree when mjpg-streamer fails +# ============================================================================== +if -n { s6-test $# -ne 0 } +if -n { s6-test ${1} -eq 256 } + +s6-svscanctl -t /var/run/s6/services diff --git a/3dprinter-remote/rootfs/etc/services.d/ser2net/run b/3dprinter-remote/rootfs/etc/services.d/ser2net/run new file mode 100644 index 0000000..acfbd63 --- /dev/null +++ b/3dprinter-remote/rootfs/etc/services.d/ser2net/run @@ -0,0 +1,9 @@ +#!/usr/bin/with-contenv bashio +# ============================================================================== +# Add-on: 3dprinter-remote +# Runs ser2net +# ============================================================================== + +bashio::log.info "Starting ser2net.." + +exec ser2net -d diff --git a/3dprinter-remote/rootfs/usr/share/tempio/ser2net/ser2net.conf.gtpl b/3dprinter-remote/rootfs/usr/share/tempio/ser2net/ser2net.conf.gtpl new file mode 100644 index 0000000..9fbc5bb --- /dev/null +++ b/3dprinter-remote/rootfs/usr/share/tempio/ser2net/ser2net.conf.gtpl @@ -0,0 +1,2 @@ +9999:raw:0:{{ .printer_path }}:{{ .printer_baudrate }} {{ .ser2net_args }} +BANNER:banner1:Welcome to ser2net \rTCP port \p device \d\r