Open Charge Point Protocol implementation in Go.
The library targets modern charge points and central systems, running OCPP version 1.6+.
Given that SOAP will no longer be supported in future versions of OCPP, only OCPP-J is supported in this library. There are currently no plans of supporting OCPP-S.
Go version 1.13+ is required.
go get github.com/lorenzodonini/ocpp-go
You will also need to fetch some dependencies:
cd <path-to-ocpp-go>
export GO111MODULE=on
go mod download
Your application may either act as a Central System (server) or as a Charge Point (client).
Note: Releases 0.10.0 introduced breaking changes in some API, due to refactoring. The functionality remains the same, but naming changed.
Planned milestones and features:
- Dedicated package for configuration management
- OCPP 1.6 (documentation available here)
- OCPP 1.6 Security extension (documentation available here)
- OCPP 2.0.1 (examples working, but will need more real-world testing) (documentation available here)
The library offers several advanced features, especially at websocket and ocpp-j level.
All incoming and outgoing messages are validated by default, using the validator package. Constraints are defined on every request/response struct, as per OCPP specs.
Validation may be disabled at a package level if needed:
ocppj.SetMessageValidation(false)
Use at your own risk, as this will disable validation for all messages!
I will be evaluating the possibility to selectively disable validation for a specific message, e.g. by passing message options.
The ws
and ocppj
packages offer the possibility to enable verbose logs, via your logger of choice, e.g.:
// Setup your own logger
log = logrus.New()
log.SetFormatter(&logrus.TextFormatter{FullTimestamp: true})
log.SetLevel(logrus.DebugLevel) // Debug level needed to see all logs
// Pass own logger to ws and ocppj packages
ws.SetLogger(log.WithField("logger", "websocket"))
ocppj.SetLogger(log.WithField("logger", "ocppj"))
The logger you pass needs to conform to the logging.Logger
interface.
Commonly used logging libraries, such as zap or logrus, adhere to this interface out-of-the-box.
If you are using a logger, that isn't conform, you can simply write an adapter between the Logger
interface and your
own logging system.
The websocket package supports configuring ping pong for both endpoints.
By default, the client sends a ping every 54 seconds and waits for a pong for 60 seconds, before timing out. The values can be configured as follows:
cfg := ws.NewClientTimeoutConfig()
cfg.PingPeriod = 10 * time.Second
cfg.PongWait = 20 * time.Second
websocketClient.SetTimeoutConfig(cfg)
By default, the server does not send out any pings and waits for a ping from the client for 60 seconds, before timing out.
To configure the server to send out pings, the PingPeriod
and PongWait
must be set to a value greater than 0:
cfg := ws.NewServerTimeoutConfig()
cfg.PingPeriod = 10 * time.Second
cfg.PongWait = 20 * time.Second
websocketServer.SetTimeoutConfig(cfg)
To disable sending ping messages, set the PingPeriod
value to 0
.
Contributions are welcome! Please refer to the testing guide for instructions on how to run the tests.