|
| 1 | +# Docker Setup for Z-Wave Stack on Windows CI |
| 2 | + |
| 3 | +This setup allows you to run Linux Z-Wave binaries in Docker containers on Windows and connect to them via TCP from CTT-Remote or other tools. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Docker Desktop for Windows installed and running |
| 8 | +- Ensure Docker is configured to use Linux containers (not Windows containers) |
| 9 | + |
| 10 | +## Architecture |
| 11 | + |
| 12 | +The Z-Wave binaries run in TCP server mode inside Docker containers with ports exposed to Windows: |
| 13 | + |
| 14 | +``` |
| 15 | +Linux Binary (TCP server in container) → Docker port mapping → Windows Host |
| 16 | +``` |
| 17 | + |
| 18 | +All 5 Z-Wave binaries run in a single Docker container with the following port mappings: |
| 19 | + |
| 20 | +- **Controller 1** (Z-Wave JS FirstController): `localhost:5000` |
| 21 | +- **Controller 2** (CTT SecondController): `localhost:5001` |
| 22 | +- **Controller 3** (CTT ThirdController): `localhost:5002` |
| 23 | +- **End Device 1** (CTT FirstEndDevice): `localhost:5003` |
| 24 | +- **End Device 2** (CTT SecondEndDevice): `localhost:5004` |
| 25 | + |
| 26 | +## Quick Start |
| 27 | + |
| 28 | +### 1. Build and Start Containers |
| 29 | + |
| 30 | +```bash |
| 31 | +docker-compose up --build |
| 32 | +``` |
| 33 | + |
| 34 | +This will: |
| 35 | +- Build the Docker image with 32-bit Debian Linux |
| 36 | +- Start a single container running all 5 Z-Wave binaries (3 controllers + 2 end devices) |
| 37 | +- Expose ports 5000-5004 for all devices |
| 38 | +- Each binary runs in its own process within the container |
| 39 | + |
| 40 | +### 2. Configure CTT-Remote to Use Docker Containers |
| 41 | + |
| 42 | +In your CTT project, configure the serial devices to use TCP/IP mode. Use the `setupSerialDevices` JSON-RPC method: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "jsonrpc": "2.0", |
| 47 | + "method": "setupSerialDevices", |
| 48 | + "params": { |
| 49 | + "serialDevices": { |
| 50 | + "FirstController": { |
| 51 | + "DevType": "Controller", |
| 52 | + "SName": "localhost", |
| 53 | + "SPort": 5001, |
| 54 | + "SType": "TCP", |
| 55 | + "ChipSeries": "ZW070x", |
| 56 | + "Library": "ControllerBridgeLib", |
| 57 | + "VersionNumbers": "7.18", |
| 58 | + "ZnifferChipType": 0, |
| 59 | + "SnifferVersion": 0, |
| 60 | + "SnifferRevision": 0 |
| 61 | + }, |
| 62 | + "SecondController": null, |
| 63 | + "ThirdController": { |
| 64 | + "DevType": "Controller", |
| 65 | + "SName": "localhost", |
| 66 | + "SPort": 5002, |
| 67 | + "SType": "TCP", |
| 68 | + "ChipSeries": "ZW070x", |
| 69 | + "Library": "ControllerBridgeLib", |
| 70 | + "VersionNumbers": "7.18", |
| 71 | + "ZnifferChipType": 0, |
| 72 | + "SnifferVersion": 0, |
| 73 | + "SnifferRevision": 0 |
| 74 | + }, |
| 75 | + "FirstEndDevice": { |
| 76 | + "DevType": "EndDevice", |
| 77 | + "SName": "localhost", |
| 78 | + "SPort": 5003, |
| 79 | + "SType": "TCP", |
| 80 | + "ChipSeries": "ZW070x", |
| 81 | + "Library": "EndDeviceLib", |
| 82 | + "VersionNumbers": "7.18", |
| 83 | + "ZnifferChipType": 0, |
| 84 | + "SnifferVersion": 0, |
| 85 | + "SnifferRevision": 0 |
| 86 | + }, |
| 87 | + "SecondEndDevice": { |
| 88 | + "DevType": "EndDevice", |
| 89 | + "SName": "localhost", |
| 90 | + "SPort": 5004, |
| 91 | + "SType": "TCP", |
| 92 | + "ChipSeries": "ZW070x", |
| 93 | + "Library": "EndDeviceLib", |
| 94 | + "VersionNumbers": "7.18", |
| 95 | + "ZnifferChipType": 0, |
| 96 | + "SnifferVersion": 0, |
| 97 | + "SnifferRevision": 0 |
| 98 | + }, |
| 99 | + "RfRegion": "EU", |
| 100 | + "LRChannel": "Undefined" |
| 101 | + }, |
| 102 | + "configureDevices": false |
| 103 | + }, |
| 104 | + "id": 0 |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +Key configuration: |
| 109 | +- `SType: "TCP"` - Use TCP connection instead of COM port |
| 110 | +- `SName: "localhost"` - Connect to Docker container on localhost |
| 111 | +- `SPort: 5001, 5002` - Port numbers for CTT controllers |
| 112 | +- `SPort: 5003, 5004` - Port numbers for CTT end devices |
| 113 | +- `SecondController: null` - Not used by CTT (reserved for Z-Wave JS) |
| 114 | + |
| 115 | +### 3. Configure Z-Wave JS to Use Controller 1 |
| 116 | + |
| 117 | +For Z-Wave JS, connect to `localhost:5000` (FirstController in the Docker setup). This controller is dedicated for Z-Wave JS use. |
| 118 | + |
| 119 | +## Managing Containers |
| 120 | + |
| 121 | +### Start containers (detached mode) |
| 122 | + |
| 123 | +```bash |
| 124 | +docker-compose up -d |
| 125 | +``` |
| 126 | + |
| 127 | +### Stop containers |
| 128 | + |
| 129 | +```bash |
| 130 | +docker-compose down |
| 131 | +``` |
| 132 | + |
| 133 | +### View logs |
| 134 | + |
| 135 | +```bash |
| 136 | +# All containers |
| 137 | +docker-compose logs -f |
| 138 | + |
| 139 | +# Specific container |
| 140 | +docker-compose logs -f zwave-controller-1 |
| 141 | +docker-compose logs -f zwave-controller-2 |
| 142 | +docker-compose logs -f zwave-end-device-1 |
| 143 | +``` |
| 144 | + |
| 145 | +### Restart the container |
| 146 | + |
| 147 | +```bash |
| 148 | +docker-compose restart |
| 149 | +``` |
| 150 | + |
| 151 | +## Advanced Usage |
| 152 | + |
| 153 | +### Custom Port Mapping |
| 154 | + |
| 155 | +Edit [docker-compose.yml](docker-compose.yml) to change port mappings: |
| 156 | + |
| 157 | +```yaml |
| 158 | +ports: |
| 159 | + - "YOUR_PORT:5000" # Change YOUR_PORT to desired Windows port |
| 160 | +``` |
| 161 | +
|
| 162 | +### Interactive Shell Access |
| 163 | +
|
| 164 | +To access the container's shell: |
| 165 | +
|
| 166 | +```bash |
| 167 | +docker exec -it zwave-stack bash |
| 168 | +``` |
| 169 | + |
| 170 | +Once inside, you can check running processes: |
| 171 | + |
| 172 | +```bash |
| 173 | +ps aux | grep ZW_zwave |
| 174 | +``` |
| 175 | + |
| 176 | +### Testing TCP Connection |
| 177 | + |
| 178 | +You can test the connection using telnet or PowerShell: |
| 179 | + |
| 180 | +```bash |
| 181 | +# Test from Windows |
| 182 | +telnet localhost 5000 # Controller 1 (Z-Wave JS) |
| 183 | +telnet localhost 5001 # Controller 2 (CTT) |
| 184 | +telnet localhost 5002 # Controller 3 (CTT) |
| 185 | +telnet localhost 5003 # End Device 1 (CTT) |
| 186 | +telnet localhost 5004 # End Device 2 (CTT) |
| 187 | + |
| 188 | +# Or using PowerShell |
| 189 | +Test-NetConnection -ComputerName localhost -Port 5000 |
| 190 | +Test-NetConnection -ComputerName localhost -Port 5001 |
| 191 | +Test-NetConnection -ComputerName localhost -Port 5002 |
| 192 | +Test-NetConnection -ComputerName localhost -Port 5003 |
| 193 | +Test-NetConnection -ComputerName localhost -Port 5004 |
| 194 | +``` |
| 195 | + |
| 196 | +## CI/CD Integration |
| 197 | + |
| 198 | +### GitHub Actions Example |
| 199 | + |
| 200 | +```yaml |
| 201 | +jobs: |
| 202 | + test: |
| 203 | + runs-on: windows-latest |
| 204 | + steps: |
| 205 | + - uses: actions/checkout@v3 |
| 206 | + |
| 207 | + - name: Start Z-Wave containers |
| 208 | + run: docker-compose up -d |
| 209 | + |
| 210 | + - name: Wait for containers to be ready |
| 211 | + run: | |
| 212 | + Start-Sleep -Seconds 5 |
| 213 | + docker ps |
| 214 | +
|
| 215 | + - name: Run tests |
| 216 | + run: npm test |
| 217 | + |
| 218 | + - name: Stop containers |
| 219 | + if: always() |
| 220 | + run: docker-compose down |
| 221 | +``` |
| 222 | +
|
| 223 | +## Troubleshooting |
| 224 | +
|
| 225 | +### Container won't start |
| 226 | +
|
| 227 | +Check if ports are already in use: |
| 228 | +
|
| 229 | +```cmd |
| 230 | +netstat -ano | findstr :5000 |
| 231 | +netstat -ano | findstr :5001 |
| 232 | +netstat -ano | findstr :5002 |
| 233 | +netstat -ano | findstr :5003 |
| 234 | +netstat -ano | findstr :5004 |
| 235 | +``` |
| 236 | + |
| 237 | +### Can't connect to TCP port |
| 238 | + |
| 239 | +1. Verify containers are running: |
| 240 | + ```bash |
| 241 | + docker ps |
| 242 | + ``` |
| 243 | + |
| 244 | +2. Check container logs: |
| 245 | + ```bash |
| 246 | + docker-compose logs |
| 247 | + ``` |
| 248 | + |
| 249 | +3. Verify port is accessible: |
| 250 | + ```powershell |
| 251 | + Test-NetConnection -ComputerName localhost -Port 5000 |
| 252 | + ``` |
| 253 | + |
| 254 | +### Binary crashes immediately |
| 255 | + |
| 256 | +Check the logs for errors: |
| 257 | +```bash |
| 258 | +docker-compose logs -f |
| 259 | +``` |
| 260 | + |
| 261 | +Common issues: |
| 262 | +- Missing shared libraries (check with `docker exec -it zwave-stack ldd /app/*.elf`) |
| 263 | +- Port already in use (check with `netstat -ano | findstr :5000`) |
| 264 | +- Binary failed to start in TCP mode (check logs with `docker-compose logs`) |
| 265 | +- Processes not running (check with `docker exec -it zwave-stack ps aux | grep ZW_zwave`) |
| 266 | + |
| 267 | +## Network Access from Other Machines |
| 268 | + |
| 269 | +To access the PTY ports from other machines on your network: |
| 270 | + |
| 271 | +1. Update [docker-compose.yml](docker-compose.yml) to bind to all interfaces: |
| 272 | + ```yaml |
| 273 | + ports: |
| 274 | + - "0.0.0.0:5000:5000" |
| 275 | + ``` |
| 276 | +
|
| 277 | +2. Connect from remote machine: |
| 278 | + ```cmd |
| 279 | + telnet <windows-ci-server-ip> 5000 |
| 280 | + ``` |
| 281 | + |
| 282 | +3. Ensure Windows Firewall allows incoming connections on these ports. |
| 283 | + |
| 284 | +## Binary Command-Line Options |
| 285 | + |
| 286 | +The Z-Wave binaries support the following options: |
| 287 | + |
| 288 | +``` |
| 289 | + -d, --debug Don't fork process |
| 290 | + -f, --fifo Use FIFO based communication |
| 291 | + -i, --id=ID Use routed ZNE with ID |
| 292 | + -m, --tmp-path=PATH Node TMP path |
| 293 | + -p, --port=PORT Port for TCP server mode of UART module |
| 294 | + -r, --region=REGION Radio region |
| 295 | + -s, --storage=PATH Storage PATH |
| 296 | + -t, --pty Use PTY mode of UART module |
| 297 | + -z, --zne-port=PORT Port for routed ZNE |
| 298 | +``` |
| 299 | + |
| 300 | +This setup uses `--port` to run in TCP server mode. |
| 301 | + |
| 302 | +## Files Created |
| 303 | + |
| 304 | +- [Dockerfile](Dockerfile) - Container definition for 32-bit Debian with required dependencies |
| 305 | +- [docker-compose.yml](docker-compose.yml) - Single container orchestration with all 5 devices |
| 306 | +- [start-zwave-stack.sh](start-zwave-stack.sh) - Startup script that launches all 5 binaries |
0 commit comments