A library for managing OCPP variables in Go. It provides a simple way to manage OCPP configuration variables, including getting and setting values, validating values, and enforcing mandatory keys.
- Configuration versioning
- Mandatory key enforcement
- Custom value validation
- Provides sane default values
- Configuration versioning
- Custom value validation
- Mandatory key enforcement
- Support for OCPP 1.6
- Support for OCPP 2.0.1
go get github.com/ChargePi/ocpp-manager@latestCheck out the full OCPP 1.6 example.
package main
import (
"github.com/ChargePi/ocpp-manager/ocpp_v16""github.com/lorenzodonini/ocpp-go/ocpp1.6/core""github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
log "github.com/sirupsen/logrus"
)
funcmain() {
log.SetLevel(log.DebugLevel)
supportedProfiles:= []string{core.ProfileName, smartcharging.ProfileName}
defaultConfig, err:=ocpp_v16.DefaultConfiguration(supportedProfiles...)
iferr!=nil {
log.Errorf("Error getting default configuration: %v", err)
return
}
manager, err:=ocpp_v16.NewV16ConfigurationManager(defaultConfig, supportedProfiles...)
// Get valuevalue, err:=manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
iferr!=nil {
log.Errorf("Error getting configuration value: %v", err)
return
}
log.Println(*value)
// Update keyval:="false"err=manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
iferr!=nil {
log.Errorf("Error updating key: %v", err)
return
}
// Get valuevalue, err=manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
iferr!=nil {
log.Errorf("Error getting configuration value: %v", err)
return
}
log.Println(*value)
// Register custom key validator, which will prevent the key from being updatedmanager.RegisterCustomKeyValidator(func(key ocpp_v16.Key, value*string) bool {
returnkey!=ocpp_v16.AuthorizeRemoteTxRequests
})
// Update keyval="true"err=manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
iferr!=nil {
log.Errorf("Error updating key: %v", err)
return
}
}- This library is still in development, and the API might change in the future.
- Storing the configuration is not part of this library. You can use a database, a file, or any other storage mechanism to store the configuration by getting the configuration as a map and storing it in your preferred way.
This project is licensed under the MIT License - see the LICENSE file for details.
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.