Skip to content

Commit

Permalink
Use zwave js
Browse files Browse the repository at this point in the history
  • Loading branch information
macbury committed Jan 23, 2022
1 parent a7bc7f6 commit 68b016e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 12 deletions.
18 changes: 6 additions & 12 deletions docker-compose.zwave.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
version: '3'
services:
ozwd:
image: openzwave/ozwdaemon:latest
zwave:
build:
context: ./zwave
dockerfile: Dockerfile
network_mode: host
security_opt:
- seccomp:unconfined
devices:
- "/dev/ttyACM0"
volumes:
- .docker/data/ozwd/:/opt/ozw/config
- .docker/data/zwavejs/cache:/cache
ports:
- "1983:1983"
- "9312:3000"
restart: unless-stopped
env_file:
- '.env.zwave'
mqtt:
restart: unless-stopped
image: eclipse-mosquitto:latest
network_mode: host
volumes:
- .docker/data/mosquitto:/mosquitto/data
#- .docker/log/mosquitto.log:/mosquitto/log/mosquitto.log
- ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
49 changes: 49 additions & 0 deletions zwave/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
FROM alpine:3.13

WORKDIR /app

RUN apk add --no-cache \
nodejs

# Build tools required to install serialport, a zwave-js dependency
RUN apk add --no-cache \
g++ \
git \
linux-headers \
make \
npm \
python3

RUN npm install npm@latest -g

WORKDIR /app

ARG [email protected]
ARG ZWAVE_JS_SERVER_PACKAGE=@zwave-js/[email protected]
ARG NPM_INSTALL_FLAGS=

RUN npm install ${NPM_INSTALL_FLAGS} ${ZWAVE_JS_SERVER_PACKAGE} ${ZWAVE_JS_PACKAGE}

RUN apk add --no-cache \
jq

WORKDIR /app

ENV NODE_ENV=production

COPY docker-entrypoint.sh /usr/local/bin/
COPY options.js .
RUN mkdir -p /cache/config /cache/db /logs

VOLUME "/cache"
EXPOSE 3000

ENV PATH=/app/node_modules/.bin:$PATH

ENV USB_PATH=/dev/zwave
ENV LOGFILENAME=/logs/zwave_%DATE%.log
# Path to persistent device configuration DB
ENV ZWAVEJS_EXTERNAL_CONFIG=/cache/db

RUN ls
ENTRYPOINT ["docker-entrypoint.sh"]
24 changes: 24 additions & 0 deletions zwave/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
set -e

if [ -z "$1" ]; then
if [ ! -c "$USB_PATH" ]; then
echo "USB path \"$USB_PATH\" does not exist or is not a character device"
exit 1
fi

if [ -n "$NETWORK_KEY" ]; then
echo "NETWORK_KEY is deprecated, use S0_LEGACY_KEY instead"
fi

set -- zwave-server --config options.js "$USB_PATH"
echo "Starting zwave-server:" "$@"
elif [ "$1" = "server" ]; then
shift
set -- zwave-server "$@"
elif [ "$1" = "client" ]; then
shift
set -- zwave-client "$@"
fi

exec "$@"
42 changes: 42 additions & 0 deletions zwave/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
function getLogConfig() {
config = {
forceConsole: true,
};

if (process.env.LOGFILENAME) {
config.filename = process.env.LOGFILENAME;
}

return config;
}

// Obtain the security keys from the environment variables.
// The server and driver don't allow blank or undefined keys,
// so skip any unset/blank environment variables. The server checks
// the key lengths and converts to a Buffer for us.
function getSecurityKeys() {
const env_keys = {
S2_AccessControl: process.env.S2_ACCESS_CONTROL_KEY,
S2_Authenticated: process.env.S2_AUTHENTICATED_KEY,
S2_Unauthenticated: process.env.S2_UNAUTHENTICATED_KEY,
S0_Legacy: process.env.S0_LEGACY_KEY || process.env.NETWORK_KEY,
};

keys = {};
for (const [name, key] of Object.entries(env_keys)) {
if (key) {
keys[name] = key;
}
}

return keys;
}

module.exports = {
logConfig: getLogConfig(),
storage: {
cacheDir: "/cache",
deviceConfigPriorityDir: "/cache/config",
},
securityKeys: getSecurityKeys(),
};

0 comments on commit 68b016e

Please sign in to comment.