All Projects → voltbras → go-ocpp

voltbras / go-ocpp

Licence: GPL-3.0 license
v1.5 and v1.6 OCPP implementation in Golang

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to go-ocpp

ocpp
Open Charge Point Protocol
Stars: ✭ 164 (+331.58%)
Mutual labels:  ocpp, emobility, chargingstation, electric-vehicles, charging-stations
OCPP-1.6-CP-Simulator
Hacky but it works for testing purposes
Stars: ✭ 35 (-7.89%)
Mutual labels:  ocpp, emobility, chargingstation
OCPP-2.0-CP-Simulator
OCPP 2.0 Charge Point Simulator | From: https://github.com/nenecmrf/OCPP-J-CP-Simulator
Stars: ✭ 36 (-5.26%)
Mutual labels:  ocpp, emobility, chargingstation
docile-charge-point
Scriptable OCPP charge point simulator and test tool
Stars: ✭ 60 (+57.89%)
Mutual labels:  ocpp, emobility
cpd-ocpp
Open Charge Point Protocol
Stars: ✭ 53 (+39.47%)
Mutual labels:  ocpp, electric-vehicles
WWCP OCPP
Connectivity between the World Wide Charging Protocol (WWCP) and the Open Charge Point Protocol (OCPP v1.6/v2.0).
Stars: ✭ 24 (-36.84%)
Mutual labels:  ocpp, chargingstation
IDDataLogger
A DataLogger for Volkwagen ID vehicles. Includes an iOS Widget. Works with VW ID.3 and ID.4 vehicles.
Stars: ✭ 76 (+100%)
Mutual labels:  electric-vehicles
ArduinoOcpp
OCPP 1.6 client for microcontrollers
Stars: ✭ 139 (+265.79%)
Mutual labels:  ocpp
mobivoc
A vocabulary for future-oriented mobility solutions and value-added services supporting them.
Stars: ✭ 27 (-28.95%)
Mutual labels:  charging-stations
ocpp
Home Assistant integration for electric vehicle chargers that support the Open Charge Point Protocol (OCPP).
Stars: ✭ 82 (+115.79%)
Mutual labels:  ocpp
awesome-sustainability-jobs
Dev jobs in the sustainability sector
Stars: ✭ 149 (+292.11%)
Mutual labels:  emobility
ev chargingcoordination2017
Optimal Scheduling of Electric Vehicle Charging in Distribution Networks
Stars: ✭ 51 (+34.21%)
Mutual labels:  emobility
FleetSim
Event-based Simulation for Electric Vehicle Fleets
Stars: ✭ 21 (-44.74%)
Mutual labels:  electric-vehicles
EVMap
Android app to find electric vehicle charging stations - compatible with community databases such as GoingElectric.de and OpenChargeMap.org.
Stars: ✭ 89 (+134.21%)
Mutual labels:  charging-stations

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))
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].