A curated list of open technology projects to sustain a stable climate, energy supply, biodiversity and natural resources.

go-ocpp

v1.5 and v1.6 Open Charge Point Protocol implementation in Golang.
https://github.com/voltbras/go-ocpp

Category: Consumption
Sub Category: Mobility and Transportation

Keywords

charging-stations chargingstation electric-vehicles emobility ocpp

Last synced: about 2 hours ago
JSON representation

Repository metadata

v1.5 and v1.6 OCPP implementation in Golang

README.md

go-ocpp

OCPP(1.5/1.6) implementation in Golang.

  • v1.5, it's assumed it is SOAP
  • v1.6, it's assumed it is JSON

Usage

Central System

Just pass a handler that takes in a cpreq.ChargePointRequest and returns a (cpresp.ChargePointResponse, error).

In SOAP, error messages will be sent back via Fault, as specified in OCPP v1.5

In Websockets, error messages will be sent back as specified in OCPP-J v1.6

csys := cs.New()
go csys.Run(":12811", func(req cpreq.ChargePointRequest, metadata cs.ChargePointRequestMetadata) (cpresp.ChargePointResponse, error) {
    // Return an error to the Station communicating to the Central System
    //
    // station, isAuthorized := getStation(metadata.ChargePointID)
    // if !isAuthorized {
    //   return nil, errors.New("charger not authorized to join network")
    // }
    // ---
    // Or check some specific header in the underlying HTTP request:
    // 
    // if shouldBlock(metadata.HTTPRequest) {
    //   return nil, errors.New("charger should send appropriate headers")
    // }

    switch req := req.(type) {
    case *cpreq.BootNotification:
        // accept chargepoint in the network
        return &cpresp.BootNotification{
            Status:      "Accepted",
            CurrentTime: time.Now(),
            Interval:    60,
        }, nil

    case *cpreq.Heartbeat:
        return &cpresp.Heartbeat{CurrentTime: time.Now()}, nil

    case *cpreq.StatusNotification:
        if req.Status != "Available" {
            // chargepoint is unavailable
        }
        return &cpresp.StatusNotification{}, nil

    default:
        return nil, errors.New("Response not supported")
    }
}

Charge Point

Pass the required parameters to the constructor function, and then just send any request(cpreq.*).

TODO: assertion of the response type should be done inside the .Send?

stationID := "id01"
centralSystemURL := "ws://localhost:12811"
st, err := cp.NewChargePoint(stationID, centralSystemURL, ocpp.V16, ocpp.JSON, nil, handler) // or ocpp.SOAP
if err != nil {
    fmt.Println("could not create charge point:", err)
    return
}
rawResp, err := st.Send(&cpreq.Heartbeat{})
if err != nil {
    fmt.Println("could't send heartbeat:", err)
    return
}
resp, ok := rawResp.(*cpresp.Heartbeat)
if !ok {
    fmt.Println("response is not a heartbeat response")
    return
}
fmt.Println("got reply:", resp)

Logs

For more useful logging, do:

ocpp.SetDebugLogger(log.New(os.Stdout, "DEBUG:", log.Ltime))
ocpp.SetErrorLogger(log.New(os.Stderr, "ERROR:", log.Ltime))

Owner metadata


GitHub Events

Total
Last Year

Committers metadata

Last synced: 6 days ago

Total Commits: 50
Total Committers: 1
Avg Commits per committer: 50.0
Development Distribution Score (DDS): 0.0

Commits in past year: 0
Committers in past year: 0
Avg Commits per committer in past year: 0.0
Development Distribution Score (DDS) in past year: 0.0

Name Email Commits
eduhenke e****e@h****m 50

Committer domains:


Issue and Pull Request metadata

Last synced: 1 day ago

Total issues: 10
Total pull requests: 5
Average time to close issues: 3 months
Average time to close pull requests: 4 months
Total issue authors: 8
Total pull request authors: 2
Average comments per issue: 1.8
Average comments per pull request: 0.0
Merged pull request: 4
Bot issues: 0
Bot pull requests: 0

Past year issues: 0
Past year pull requests: 0
Past year average time to close issues: N/A
Past year average time to close pull requests: N/A
Past year issue authors: 0
Past year pull request authors: 0
Past year average comments per issue: 0
Past year average comments per pull request: 0
Past year merged pull request: 0
Past year bot issues: 0
Past year bot pull requests: 0

More stats: https://issues.ecosyste.ms/repositories/lookup?url=https://github.com/voltbras/go-ocpp

Top Issue Authors

  • oscarjairIT (2)
  • eduhenke (2)
  • darkrain (1)
  • AlexMartSch (1)
  • FlorishL (1)
  • EstoyAburrido (1)
  • solanu (1)
  • michaelbironneau (1)

Top Pull Request Authors

  • eduhenke (4)
  • hevanto (1)

Top Issue Labels

Top Pull Request Labels


Package metadata

proxy.golang.org: github.com/voltbras/go-ocpp

  • Homepage: https://github.com/voltbras/go-ocpp
  • Documentation: https://pkg.go.dev/github.com/voltbras/go-ocpp#section-documentation
  • Licenses: GPL-3.0
  • Latest release: v1.1.0 (published about 4 years ago)
  • Last Synced: 2025-04-26T13:00:55.646Z (1 day ago)
  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Rankings:
    • Stargazers count: 3.646%
    • Forks count: 4.268%
    • Average: 6.065%
    • Dependent packages count: 6.999%
    • Dependent repos count: 9.346%

Dependencies

go.mod go
  • github.com/google/uuid v1.1.0
  • github.com/gorilla/websocket v1.4.1
  • github.com/stretchr/testify v1.6.1
go.sum go
  • github.com/davecgh/go-spew v1.1.0
  • github.com/google/uuid v1.1.0
  • github.com/gorilla/websocket v1.4.1
  • github.com/pmezard/go-difflib v1.0.0
  • github.com/stretchr/objx v0.1.0
  • github.com/stretchr/testify v1.6.1
  • gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405
  • gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c

Score: -Infinity