Skip to content

Commit 7bb906a

Browse files
committed
docs: initial docs version
1 parent 91b5f05 commit 7bb906a

File tree

2 files changed

+132
-1
lines changed

2 files changed

+132
-1
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Planned milestones and features:
4747
- [x] OCPP 1.6 Security extension (documentation available [here](docs/ocpp1.6-security-extension.md))
4848
- [x] OCPP 2.0.1 (examples working, but will need more real-world testing) (documentation
4949
available [here](docs/ocpp-2.0.1.md))
50+
- [x] OCPP 2.1 (beta) (documentation available [here](docs/ocpp-2.1.md))
5051

5152
### Features
5253

@@ -95,15 +96,18 @@ The websocket package supports configuring ping pong for both endpoints.
9596

9697
By default, the client sends a ping every 54 seconds and waits for a pong for 60 seconds, before timing out.
9798
The values can be configured as follows:
99+
98100
```go
99101
cfg := ws.NewClientTimeoutConfig()
100102
cfg.PingPeriod = 10 * time.Second
101103
cfg.PongWait = 20 * time.Second
102104
websocketClient.SetTimeoutConfig(cfg)
103105
```
104106

105-
By default, the server does not send out any pings and waits for a ping from the client for 60 seconds, before timing out.
107+
By default, the server does not send out any pings and waits for a ping from the client for 60 seconds, before timing
108+
out.
106109
To configure the server to send out pings, the `PingPeriod` and `PongWait` must be set to a value greater than 0:
110+
107111
```go
108112
cfg := ws.NewServerTimeoutConfig()
109113
cfg.PingPeriod = 10 * time.Second

docs/ocpp-2.1.md

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
## OCPP 2.1 Usage
2+
3+
OCPP 2.1 is now supported (experimental) in this library.
4+
5+
Requests and responses in OCPP 2.1 are handled the same way they were in v1.6 and 2.0.1.
6+
There are additional message types on the websocket layer, which are handled automatically by the library.
7+
8+
The notable change is that there are now significantly more supported messages and profiles (feature sets),
9+
which also require their own handlers to be implemented.
10+
11+
Below are very minimal setup code snippets, to get you started.
12+
CSMS is now the equivalent of the Central System,
13+
while the Charging Station is the new equivalent of a Charge Point.
14+
15+
Refer to the [examples folder](../example/2.1) for a full working example.
16+
More in-depth documentation for v2.1 will follow.
17+
18+
### CSMS
19+
20+
To start a CSMS instance, run the following:
21+
22+
```go
23+
import "github.com/lorenzodonini/ocpp-go/ocpp2.1"
24+
25+
csms := ocpp2.NewCSMS(nil, nil)
26+
27+
// Set callback handlers for connect/disconnect
28+
csms.SetNewChargingStationHandler(func (chargingStation ocpp2.ChargingStationConnection) {
29+
log.Printf("new charging station %v connected", chargingStation.ID())
30+
})
31+
csms.SetChargingStationDisconnectedHandler(func (chargingStation ocpp2.ChargingStationConnection) {
32+
log.Printf("charging station %v disconnected", chargingStation.ID())
33+
})
34+
35+
// Set handler for profile callbacks
36+
handler := &CSMSHandler{}
37+
csms.SetAuthorizationHandler(handler)
38+
csms.SetAvailabilityHandler(handler)
39+
csms.SetDiagnosticsHandler(handler)
40+
csms.SetFirmwareHandler(handler)
41+
csms.SetLocalAuthListHandler(handler)
42+
csms.SetMeterHandler(handler)
43+
csms.SetProvisioningHandler(handler)
44+
csms.SetRemoteControlHandler(handler)
45+
csms.SetReservationHandler(handler)
46+
csms.SetTariffCostHandler(handler)
47+
csms.SetTransactionsHandler(handler)
48+
49+
50+
// Start central system
51+
listenPort := 8887
52+
log.Printf("starting CSMS")
53+
csms.Start(listenPort, "/{ws}") // This call starts server in daemon mode and is blocking
54+
log.Println("stopped CSMS")
55+
```
56+
57+
#### Sending requests
58+
59+
Similarly to v2.0.1, you may send requests using the simplified API, e.g.
60+
61+
```go
62+
err := csms.GetLocalListVersion(chargingStationID, myCallback)
63+
if err != nil {
64+
log.Printf("error sending message: %v", err)
65+
}
66+
```
67+
68+
Or you may build requests manually and send them using the asynchronous API.
69+
70+
#### Docker image
71+
72+
There is a Dockerfile and a docker image available upstream.
73+
74+
### Charging Station
75+
76+
To start a charging station instance, simply run the following:
77+
78+
```go
79+
chargingStationID := "cs0001"
80+
csmsUrl = "ws://localhost:8887"
81+
chargingStation := ocpp2.NewChargingStation(chargingStationID, nil, nil)
82+
83+
// Set a handler for all callback functions
84+
handler := &ChargingStationHandler{}
85+
chargingStation.SetAvailabilityHandler(handler)
86+
chargingStation.SetAuthorizationHandler(handler)
87+
chargingStation.SetDataHandler(handler)
88+
chargingStation.SetDiagnosticsHandler(handler)
89+
chargingStation.SetDisplayHandler(handler)
90+
chargingStation.SetFirmwareHandler(handler)
91+
chargingStation.SetISO15118Handler(handler)
92+
chargingStation.SetLocalAuthListHandler(handler)
93+
chargingStation.SetProvisioningHandler(handler)
94+
chargingStation.SetRemoteControlHandler(handler)
95+
chargingStation.SetReservationHandler(handler)
96+
chargingStation.SetSmartChargingHandler(handler)
97+
chargingStation.SetTariffCostHandler(handler)
98+
chargingStation.SetTransactionsHandler(handler)
99+
100+
// Connects to CSMS
101+
err := chargingStation.Start(csmsUrl)
102+
if err != nil {
103+
log.Println(err)
104+
} else {
105+
log.Printf("connected to CSMS at %v", csmsUrl)
106+
mainRoutine() // ... your program logic goes here
107+
}
108+
109+
// Disconnect
110+
chargingStation.Stop()
111+
log.Println("disconnected from CSMS")
112+
```
113+
114+
#### Sending requests
115+
116+
Similarly to v2.0.1 you may send requests using the simplified API (recommended), e.g.
117+
118+
```go
119+
bootResp, err := chargingStation.BootNotification(provisioning.BootReasonPowerUp, "model1", "vendor1")
120+
if err != nil {
121+
log.Printf("error sending message: %v", err)
122+
} else {
123+
log.Printf("status: %v, interval: %v, current time: %v", bootResp.Status, bootResp.Interval, bootResp.CurrentTime.String())
124+
}
125+
```
126+
127+
Or you may build requests manually and send them using either the synchronous or asynchronous API.

0 commit comments

Comments
 (0)