Skip to content

Serial bridging: expose a remote serial port as a local virtual port #3

Description

@richlegrand

Program an ESP32 or Arduino remotely, or connect two physical serial ports together over BitBang. Linux only for now.

bitbang serve serial /dev/ttyUSB0     # where the device is plugged in
bitbang connect <url> --serial        # local endpoint

Two local endpoints, because no single one covers every tool:

RFC2217 -- no install. esptool and idf.py speak it natively (--port rfc2217://localhost:4000), and it carries baud, DTR, and RTS by design. Espressif ships a reference server worth reading.

Virtual serial port -- needs a kernel module (below). Required for tools with no network-serial support: Arduino IDE, PlatformIO, minicom.

The crux: DTR and RTS. A data-only bridge won't flash. esptool enters the ROM bootloader by toggling control lines (DTR→GPIO0, RTS→EN), so the bridge has to carry modem control state, not just bytes.

A plain PTY can't do this -- its README puts it plainly: "PTY does not support setting modem lines on the slave." Two out-of-tree modules can:

  • vtty — emulates baud and modem lines. The master side reads packetized events (TAG_SET_MODEM for DTR/RTS, TAG_SET_TERMIOS for baud), which is exactly what we'd relay to the remote port. Its README lists "write an RFC2217 client exposing a native-looking serial port" as an intended use. Not battle-tested: flow control untested, TIOCMIWAIT/TIOCGICOUNT unsupported.
  • tty0tty — modem lines emulated, termios not.

vtty looks like the better fit, since the local app's baud setting needs to reach the remote physical port. It's a separate install and we'd only talk to its device nodes, so its license doesn't affect bitbang.

Open:

  • Ship RFC2217 first, treat vtty as opt-in for Arduino users? (leaning yes)
  • Throughput degrades with RTT — the ROM protocol is chunked-and-acked, so a 2MB image takes minutes over a 150ms link. Acceptable, or worth optimizing?
  • Any driverless path for Arduino IDE? CUSE might allow a userspace character device answering the modem ioctls, but it's unclear whether tools would accept it as a tty.

Write it against a generic byte-stream interface rather than the WebRTC API directly — shared with TCP port forwarding.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions