package
0.3.0
Repository: https://github.com/codersergiy/ocpp16-go.git
Documentation: pkg.go.dev

# README

ocpp1.6-go

Open Charge Point Protocol (OCPP) version 1.6 in Go.

Example

Example shows implementation ocppj version 1.6 for central system.

Folder structure

  • callbacks.go - Includes handlers for each OCPP request (Implementation DB logic)
  • configs.json - File to specify list of chargers for the demo in JSON format
  • simplequeue.go - Simple messages queue and charger objects for the demo only
  • api.go - Handlers for the client API requests
  • README.md - this file

Docker

To spin contaienr on docker, please use commands below:

docker build -t ocpp16:latest -f Dockerfile .
docker run --rm --name ocpp16-example -p "9033:8080" ocpp16:latest

Endpoint for the chargers

ws://localhost:9033/ocppj/1.6/{chargerName}

Central System Example

To use library in your project, you must implement the callbacks with your business logic, as shown below:

import (
	"time"
	"net/http"
	"github.com/CoderSergiy/golib/logging"
	"github.com/CoderSergiy/ocpp16-go/core"
	"github.com/CoderSergiy/ocpp16-go/messages"
)

type OCPPHandlers struct {
    // ... Add required variables for your implementation
}

func (cs *OCPPHandlers) BootNotificationRequestHandler (callMessage messages.CallMessage) (string, error, bool) {

    // ... Implement your business logic

	// Create CallResult message
	callMessageResponse := messages.CallResultMessageWithParam (
		callMessage.UniqueID,
		bootNotificationResp.GetPayload(),
	)

	return callMessageResponse.ToString(), nil, WEBSOCKET_KEEP_OPEN
}

// further callbacks... 

Requirements for the design

Name of the methods for the call requests has to in in the format: action + "RequestHandler", as example "HeartbeatRequestHandler".

For the responses handlers have to be in the formar: action + "ResponseHandler", as example "AuthorizeResponseHandler".

The error handler named "OCPPErrorHandler".

API to work with server

Get status of the charger

Charger needs to be add to the connfigs.json Example:

curl --request GET 'http://localhost:9033/charger/{chargerName}/status'

Get status of the message

All messages are using unique ID. Please, use it to inquire status from the server Example:

curl --request GET 'http://localhost:9033/message/{messageUniqueID}/status'

Initiate the TriggerAction by server (from CS to CP)

API to inject message for the charger, to make possible for Central System trigger Charge Point-initiated message. In response for successful created message server will returns 'uniqueid' which you can use to obtain status using Get Message Satatus API. Example:

curl --request POST 'http://localhost:9033/command/{chargerName}/triggeraction/{action}'

Permitted values for the 'action' parameter, regarding OCPP document you can find in the list below:

  • BootNotification
  • DiagnosticsStatusNotification
  • FirmwareStatusNotification
  • Heartbeat
  • MeterValues
  • StatusNotification

# Functions

*************************************************************************************** * * Function : ChargerConstructor (Constructor) * * Purpose : Creates a new instance of the Charger * * Input : Nothing * * Return : Charger object */.
*************************************************************************************** * * Function : CreateFailResponse * * Purpose : Create Failed API response in json format * * Input : description string - description of the failed status * * Return : string - json format of the APIResponse */.
*************************************************************************************** * * Function : CreateSuccessResponse * * Purpose : Create Successfull API response in json format * * Input : reference string - reference for the response * * Return : []byte - json format of the APIResponse */.
*************************************************************************************** * * Function : GetMessageStatusAPI * * Purpose : Get message from the queue and send to the client by http * * Input : chargerName string - charger name * serverConfigs *Configs - pointer to the chargers arrays * log *logging.Log - pointer to the log * w http.ResponseWriter - http response * * Return : Nothing */.
*************************************************************************************** * * Function : GetMessageStatusAPI * * Purpose : Get message from the queue and send to the client by http * * Input : reference string - unique reference * MQueue *SimpleMessageQueue - pointer to the Message Queue * log *logging.Log - pointer to the log * w http.ResponseWriter - http response * * Return : Nothing */.
*************************************************************************************** * * Function : OCPPHandlersConstructor (Constructor) * * Purpose : Creates a new instance of the OCPPHandlers * * Input : Nothing * * Return : OCPPHandlers object */.
*************************************************************************************** * * Function : ServerConfigsConstructor (Constructor) * * Purpose : Creates a new instance of the Configs * * Input : Nothing * * Return : Configs object */.
*************************************************************************************** * * Function : SetConfigsFromFile (Constructor) * * Purpose : Set configs struct from the file * * Input : fileName string - filename with settings for the test server * * Return : Configs - Configs object * error - error if happened */.
*************************************************************************************** * * Function : SimpleMessageQueue (Constructor) * * Purpose : Creates a new instance of the SimpleMessageQueue * * Input : Nothing * * Return : SimpleMessageQueue object */.
*************************************************************************************** * * Function : TriggerActionAPI * * Purpose : Handles TriggerAction API request * * Input : serverConfigs *Configs - pointer to the chargers arrays * MQueue *SimpleMessageQueue - pointer to the Message Queue * log *logging.Log - pointer to the log * ps httprouter.Params - router parameters * w http.ResponseWriter - http response * * Return : Nothing */.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

*************************************************************************************** * Struct : APIResponse * * Purpose : Object handles API response parameters * *****************************************************************************************/.
*************************************************************************************** * Struct : Charger * * Purpose : Struct handles charger parameters in the gorutines * *****************************************************************************************/.
*************************************************************************************** * Struct : ChargerFromFile * * Purpose : Struct handles charger's parameters from config file * *****************************************************************************************/.
*************************************************************************************** * Struct : Configs * * Purpose : Object handles configurations from the file * *****************************************************************************************/.
*************************************************************************************** * Struct : FileConfigs * * Purpose : Struct handles configurations from file * *****************************************************************************************/.
*************************************************************************************** * Struct : Message * * Purpose : Struct handles message's parameters * *****************************************************************************************/.
*************************************************************************************** * Struct : OCPPHandlers * * Purpose : Handles struct for each connected charger * *****************************************************************************************/.
*************************************************************************************** * Struct : SimpleMessageQueue * * Purpose : Struct handles messages queue routines * *****************************************************************************************/.

# Type aliases

No description provided by the author