Skip to content

Commit 959138a

Browse files
committed
docs: update
1 parent 2248fc8 commit 959138a

2 files changed

Lines changed: 76 additions & 0 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ Planned milestones and features:
5252

5353
The library offers several advanced features, especially at websocket and ocpp-j level.
5454

55+
- [x] Automatic message validation
56+
- [x] Verbose logging
57+
- [x] Websocket ping-pong
58+
- [x] Extensive OCPP 1.6 configuration management
59+
5560
#### Automatic message validation
5661

5762
All incoming and outgoing messages are validated by default, using the [validator](gopkg.in/go-playground/validator)

docs/ocpp-1.6.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,74 @@ Then run the following:
303303
```
304304
docker-compose -f example/1.6/docker-compose.tls.yml up charge-point
305305
```
306+
307+
## Configuration management
308+
309+
The configuration management package allows you to manage the configuration keys defined in the OCPP 1.6 specification.
310+
It will automatically check for the validity of the keys and values, and it allows you to register custom key
311+
validators. It will also trigger callbacks when a key is updated, so you can perform custom logic when a key is changed.
312+
313+
Explore more in the [configuration management ](../ocpp1.6/config_manager) package.
314+
315+
```go
316+
package main
317+
318+
import (
319+
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
320+
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
321+
log "github.com/sirupsen/logrus"
322+
configManager "github.com/lorenzodonini/ocpp-go/ocpp1.6/ocpp_v16_config_manager"
323+
)
324+
325+
func main() {
326+
log.SetLevel(log.DebugLevel)
327+
328+
supportedProfiles := []string{core.ProfileName, smartcharging.ProfileName}
329+
defaultConfig, err := configManager.DefaultConfiguration(supportedProfiles...)
330+
if err != nil {
331+
log.Errorf("Error getting default configuration: %v", err)
332+
return
333+
}
334+
335+
manager, err := configManager.NewV16ConfigurationManager(defaultConfig, supportedProfiles...)
336+
337+
// Get value
338+
value, err := manager.GetConfigurationValue(configManager.AuthorizeRemoteTxRequests)
339+
if err != nil {
340+
log.Errorf("Error getting configuration value: %v", err)
341+
return
342+
}
343+
344+
log.Println(*value)
345+
346+
// Update key
347+
val := "false"
348+
err = manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
349+
if err != nil {
350+
log.Errorf("Error updating key: %v", err)
351+
return
352+
}
353+
354+
// Get value
355+
value, err = manager.GetConfigurationValue(configManager.AuthorizeRemoteTxRequests)
356+
if err != nil {
357+
log.Errorf("Error getting configuration value: %v", err)
358+
return
359+
}
360+
361+
log.Println(*value)
362+
363+
// Register custom key validator, which will prevent the key from being updated
364+
manager.RegisterCustomKeyValidator(func(key ocpp_v16.Key, value *string) bool {
365+
return key != ocpp_v16.AuthorizeRemoteTxRequests
366+
})
367+
368+
// Update key
369+
val = "true"
370+
err = manager.UpdateKey(configManager.AuthorizeRemoteTxRequests, &val)
371+
if err != nil {
372+
log.Errorf("Error updating key: %v", err)
373+
return
374+
}
375+
}
376+
```

0 commit comments

Comments
 (0)