Skip to content

Commit

Permalink
README. Add details to the readme files
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiy.safronov committed Jul 26, 2022
1 parent d5cb414 commit f821873
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 89 deletions.
38 changes: 38 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# OCPP 1.6 example

# =================================================
# Build container
# =================================================
FROM golang:1.18-alpine3.15 AS builder

ENV GO111MODULE on
# Create folder for project
WORKDIR $GOPATH/src/github.com/CoderSergiy/ocpp16-go
# Copy branch to the container
COPY . .
# Fetch dependencies.
RUN go get -v -t ./...
# Build the binary.
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /go/bin/server server.go


# =================================================
# Launch server on the small container
# =================================================
FROM alpine

COPY --from=builder /go/bin/server /bin/server

# Add CA certificates
# It currently throws a warning on alpine: WARNING: ca-certificates.crt does not contain exactly one certificate or CRL: skipping.
# Ignore the warning.
RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* && update-ca-certificates
# Copy configs file to the container
COPY example/configs.json /tmp
# Create folder for the log files in the container
RUN mkdir /tmp/logs
# Since running as a non-root user, port bindings < 1024 is not possible
# 8000 for HTTP; 8443 for HTTPS;
EXPOSE 8080

CMD ["/bin/server"]
80 changes: 0 additions & 80 deletions Makefile

This file was deleted.

49 changes: 47 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,47 @@
# ocpp-go
OCPP code to build back-end
ocpp1.6-go
=================
![License](https://img.shields.io/dub/l/vibe-d.svg)

Open Charge Point Protocol (OCPP) is a standard open protocol for communication between Charge Points and Central System and is designed to accommodate any type of charging technique.

The library is representing implementation of OCPP version 1.6 in Go.
Code in branch is based on JSON type communication (OCPP-J) as SOAP will no longer be supported in future versions.

## Status & Roadmap

Planned milestones and features:

- [x] OCPP 1.6 repo structure
- [x] Example of OCPP implementation as Central Sysytem (3 actions)
- [ ] OCPP 1.6 Core
- [ ] Add test cases for library

## OCPP 1.6 Usage

Go version 1.18+ is required.

Installation
------------

Use go get.

go get github.com/CoderSergiy/ocpp16-go

Then import the validator package into your own code.

import "github.com/CoderSergiy/ocpp16-go"


How to Contribute
------

Make a pull request...

License
-------
Distributed under MIT License, please see license file within the code for more details.

Maintainers
-----------
This project mantained by one person at this point.
If you are interested in project please reach out to me https://github.com/CoderSergiy
7 changes: 0 additions & 7 deletions example/Dockerfile

This file was deleted.

58 changes: 58 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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
- README.md - this file

#### Docker
To spin contaienr on docker, please use commands below:
```bash
docker build -t ocpp16:latest -f Dockerfile .
docker run --rm --name ocpp16-example -p "9033:8080" ocpp16:latest
```


## Central System Example

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

```go
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".

0 comments on commit f821873

Please sign in to comment.