Skip to content

feat: protocol multiplexing support for OCPP 1.6 and 2.0.1#419

Draft
andig wants to merge 2 commits intolorenzodonini:masterfrom
evcc-io:feat/protocol-multiplexing
Draft

feat: protocol multiplexing support for OCPP 1.6 and 2.0.1#419
andig wants to merge 2 commits intolorenzodonini:masterfrom
evcc-io:feat/protocol-multiplexing

Conversation

@andig
Copy link
Copy Markdown
Contributor

@andig andig commented Apr 17, 2026

Summary

  • Enable running both OCPP 1.6 and OCPP 2.0.1 servers on a single WebSocket port
  • Add subprotocol-based message routing in ws.Server
  • New multiplex package with MultiProtocolServer for unified API
  • Make ws.Server.Start() idempotent for shared server instances

Changes

ws package:

  • SetMessageHandlerForSubprotocol() - register handlers per WebSocket subprotocol
  • SetSubprotocolSelector() - custom subprotocol negotiation callback
  • Idempotent Start() to allow multiple OCPP servers sharing one ws.Server

ocppj package:

  • SetSubprotocol() - configure which subprotocol the server handles
  • Uses per-subprotocol handler registration when subprotocol is set

ocpp1.6 / ocpp2.0.1:

  • Constructors auto-set the appropriate subprotocol

multiplex package (new):

  • MultiProtocolServer interface and implementation
  • Protocol version tracking per client
  • Example usage in example/multiplex/

Test plan

  • Existing test suites pass (make test)
  • New TestSubprotocolSelector and TestSubprotocolSelectorDefaultBehavior tests
  • Manual testing with multi-protocol clients

Fixes #417, depends on #230

🤖 Generated with Claude Code

Comment thread ocpp1.6/types/types.go Outdated
Comment thread ocpp1.6/core/get_configuration.go Outdated
Comment thread ocpp1.6/types/types.go Outdated
@andig andig force-pushed the feat/protocol-multiplexing branch from d48673c to cbe5154 Compare April 17, 2026 11:07
andig and others added 2 commits April 17, 2026 13:10
Enable running both OCPP 1.6 and OCPP 2.0.1 servers on a single WebSocket
port using subprotocol-based message routing.

Changes:
- ws.Server: Add SetMessageHandlerForSubprotocol for per-subprotocol routing
- ws.Server: Make Start() idempotent for shared server instances
- ocppj.Server: Add SetSubprotocol to register protocol-specific handlers
- ocpp1.6/ocpp2.0.1: Auto-set subprotocol in constructors
- New multiplex package with MultiProtocolServer for unified API

Fixes lorenzodonini#417

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…register

Instead of hardcoding both OCPP 1.6 and 2.0.1 servers, the multiplex package
now provides a shared WebSocket server that users can use to create their own
OCPP servers. This gives full flexibility over which protocols to support.

Before:
  server := multiplex.NewMultiProtocolServer()
  server.OCPP16Server().SetCoreHandler(...)

After:
  mux := multiplex.NewServer()
  cs := ocpp16.NewCentralSystem(nil, mux.WebSocketServer())
  cs.SetCoreHandler(...)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@andig andig force-pushed the feat/protocol-multiplexing branch from cbe5154 to f1d5f94 Compare April 17, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🚀 Feature: support protocol multiplexing

1 participant