|
1 | 1 | # Ser2tcp |
2 | 2 |
|
3 | | -Simple proxy for connecting over TCP, TELNET, SSL or Unix socket to serial port |
| 3 | +Simple proxy for connecting over TCP, TELNET, SSL, WebSocket or Unix socket to serial port |
4 | 4 |
|
5 | 5 | https://github.com/cortexm/ser2tcp |
6 | 6 |
|
7 | 7 | ## Features |
8 | 8 |
|
9 | 9 | - can serve multiple serial ports using pyserial library |
10 | 10 | - each serial port can have multiple servers |
11 | | -- server can use TCP, TELNET, SSL or SOCKET protocol |
| 11 | +- server can use TCP, TELNET, SSL, WebSocket or SOCKET protocol |
12 | 12 | - TCP protocol just bridge whole RAW serial stream to TCP |
13 | 13 | - TELNET protocol will send every character immediately and not wait for ENTER, it is useful to use standard `telnet` as serial terminal |
14 | 14 | - SSL protocol provides encrypted TCP connection with optional mutual TLS (mTLS) client certificate verification |
| 15 | + - WebSocket protocol connects through the HTTP server with binary frames for data and JSON text frames for signal control |
15 | 16 | - SOCKET protocol uses Unix domain socket for local IPC |
16 | 17 | - servers accepts multiple connections at one time |
17 | 18 | - each connected client can sent to serial port |
18 | 19 | - serial port send received data to all connected clients |
19 | 20 | - non-blocking send with configurable timeout and buffer limit |
| 21 | +- serial signal control (RTS, DTR, CTS, DSR, RI, CD) via escape protocol or WebSocket JSON |
20 | 22 | - built-in HTTP server with REST API for status monitoring |
21 | 23 | - web interface for viewing configured ports and connections |
| 24 | +- web terminal clients (xterm.js VT100 terminal and raw colored view) |
22 | 25 | - authentication with session management and API tokens |
| 26 | +- light/dark mode web UI (follows system preference) |
23 | 27 |
|
24 | 28 | ## Installation |
25 | 29 |
|
@@ -137,13 +141,42 @@ Match attributes: `vid`, `pid`, `serial_number`, `manufacturer`, `product`, `loc |
137 | 141 |
|
138 | 142 | | Parameter | Description | Default | |
139 | 143 | |-----------|-------------|---------| |
140 | | -| `address` | Bind address (IP for tcp/telnet/ssl, path for socket) | required | |
141 | | -| `port` | TCP port (not used for socket) | required | |
142 | | -| `protocol` | `tcp`, `telnet`, `ssl` or `socket` | required | |
| 144 | +| `address` | Bind address (IP for tcp/telnet/ssl, path for socket) | required* | |
| 145 | +| `port` | TCP port (not used for socket/websocket) | required* | |
| 146 | +| `protocol` | `tcp`, `telnet`, `ssl`, `websocket` or `socket` | required | |
| 147 | +| `endpoint` | WebSocket URL path (websocket only), must be unique | required* | |
| 148 | +| `token` | Per-server auth token (websocket only) | - | |
143 | 149 | | `ssl` | SSL configuration (required for `ssl` protocol) | - | |
| 150 | +| `data` | Forward serial data (default true), `false` = control-only | true | |
| 151 | +| `control` | Signal control configuration | - | |
144 | 152 | | `send_timeout` | Disconnect client if data cannot be sent within this time (seconds) | 5.0 | |
145 | 153 | | `buffer_limit` | Maximum send buffer size per client (bytes), `null` for unlimited | null | |
146 | 154 |
|
| 155 | +\* `address`/`port` required for tcp/telnet/ssl; `address` for socket; `endpoint` for websocket |
| 156 | + |
| 157 | +#### WebSocket configuration |
| 158 | + |
| 159 | +WebSocket connections go through the HTTP server — no separate listening port needed: |
| 160 | + |
| 161 | +```json |
| 162 | +{ |
| 163 | + "protocol": "websocket", |
| 164 | + "endpoint": "my-device", |
| 165 | + "control": { |
| 166 | + "rts": true, |
| 167 | + "signals": ["rts", "dtr", "cts", "dsr"] |
| 168 | + } |
| 169 | +} |
| 170 | +``` |
| 171 | + |
| 172 | +- Accessible at `ws://host:port/ws/my-device` (or `wss://` for HTTPS) |
| 173 | +- Available on all configured HTTP servers |
| 174 | +- Binary frames carry raw serial data (bidirectional) |
| 175 | +- Text frames carry JSON control messages: `{"rts": true}`, `{"signals": {...}}` |
| 176 | +- Signal state sent automatically on connect, then only on change |
| 177 | +- Auth: per-server `token`, global user session, or both accepted |
| 178 | +- Web terminals available at `/xterm/<endpoint>` (VT100) and `/raw/<endpoint>` (colored hex) |
| 179 | + |
147 | 180 | #### Socket configuration |
148 | 181 |
|
149 | 182 | For `socket` protocol, `address` is the path to the Unix domain socket: |
@@ -289,7 +322,19 @@ HTTPS with SSL: |
289 | 322 | | POST | `/api/login` | no | Authenticate, returns session token | |
290 | 323 | | POST | `/api/logout` | no | Invalidate session | |
291 | 324 | | GET | `/api/status` | yes | Runtime status (serial ports, servers, connections) | |
292 | | -| GET | `/api/ports` | yes | Available serial ports with USB/device attributes | |
| 325 | +| GET | `/api/detect` | yes | Available serial ports with USB/device attributes | |
| 326 | +| POST | `/api/ports` | admin | Add new port configuration | |
| 327 | +| PUT | `/api/ports/<index>` | admin | Update port configuration | |
| 328 | +| DELETE | `/api/ports/<index>` | admin | Delete port configuration | |
| 329 | +| DELETE | `/api/ports/<p>/connections/<s>/<c>` | admin | Disconnect client | |
| 330 | +| PUT | `/api/ports/<index>/signals` | admin | Set RTS/DTR signals | |
| 331 | +| GET | `/api/signals` | yes | Signal states for all ports | |
| 332 | +| GET | `/api/users` | yes | List users | |
| 333 | +| POST | `/api/users` | admin | Add user | |
| 334 | +| PUT | `/api/users/<login>` | admin | Update user | |
| 335 | +| DELETE | `/api/users/<login>` | admin | Delete user | |
| 336 | +| GET | `/xterm/<endpoint>` | no | WebSocket VT100 terminal | |
| 337 | +| GET | `/raw/<endpoint>` | no | WebSocket raw terminal | |
293 | 338 |
|
294 | 339 | Authentication: `Authorization: Bearer <token>` header or `?token=<token>` query parameter. Without `auth` configuration, all endpoints are accessible without authentication. |
295 | 340 |
|
@@ -374,7 +419,7 @@ For system service, use `sudo systemctl` instead of `systemctl --user`. |
374 | 419 |
|
375 | 420 | - Python 3.8+ |
376 | 421 | - pyserial 3.0+ |
377 | | -- uhttp-server 2.3.0+ (for HTTP/API) |
| 422 | +- uhttp-server 2.3.2+ (for HTTP/API and WebSocket) |
378 | 423 |
|
379 | 424 | ### Running on |
380 | 425 |
|
|
0 commit comments