Skip to content

Latest commit

 

History

History
95 lines (70 loc) · 2.56 KB

README.md

File metadata and controls

95 lines (70 loc) · 2.56 KB

OCPP variable manager

A library for managing OCPP 1.6 variables, with versioning, mandatory keys and custom value validation. It also includes sane defaults for the required configuration keys.

In the future, this library will be extended to support OCPP 2.0.1 as well.

Installing

  go get github.com/ChargePi/ocppManager-go

⚡ Usage

Check out the full example. It also contains a sample configuration file.

package main

import (
	"github.com/ChargePi/ocppManager-go/ocpp_v16"
	"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
	"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
	log "github.com/sirupsen/logrus"
)

func main() {
	log.SetLevel(log.DebugLevel)

	supportedProfiles := []string{core.ProfileName, smartcharging.ProfileName}
	defaultConfig, err := ocpp_v16.DefaultConfiguration(supportedProfiles...)
	if err != nil {
		log.Errorf("Error getting default configuration: %v", err)
		return
	}

	manager, err := ocpp_v16.NewV16ConfigurationManager(defaultConfig, supportedProfiles...)

	// Get value
	value, err := manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
	if err != nil {
		log.Errorf("Error getting configuration value: %v", err)
		return
	}

	log.Println(*value)

	// Update key
	val := "false"
	err = manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
	if err != nil {
		log.Errorf("Error updating key: %v", err)
		return
	}

	// Get value
	value, err = manager.GetConfigurationValue(ocpp_v16.AuthorizeRemoteTxRequests)
	if err != nil {
		log.Errorf("Error getting configuration value: %v", err)
		return
	}

	log.Println(*value)

	// Register custom key validator, which will prevent the key from being updated
	manager.RegisterCustomKeyValidator(func(key ocpp_v16.Key, value *string) bool {
		return key != ocpp_v16.AuthorizeRemoteTxRequests
	})

	// Update key
	val = "true"
	err = manager.UpdateKey(ocpp_v16.AuthorizeRemoteTxRequests, &val)
	if err != nil {
		log.Errorf("Error updating key: %v", err)
		return
	}
}

Notes

  1. This library is still in development, and the API might change in the future.
  2. 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.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.