{"id":13634654,"url":"https://github.com/voltbras/go-ocpp","last_synced_at":"2025-04-18T23:32:37.486Z","repository":{"uuid":"171716245","full_name":"voltbras/go-ocpp","owner":"voltbras","description":"v1.5 and v1.6 OCPP implementation in Golang","archived":false,"fork":false,"pushed_at":"2022-02-16T10:02:22.000Z","size":191,"stargazers_count":46,"open_issues_count":4,"forks_count":7,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-04-14T09:03:58.953Z","etag":null,"topics":["charging-stations","chargingstation","electric-vehicles","emobility","ocpp"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/voltbras.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-20T17:11:54.000Z","updated_at":"2024-04-13T17:13:47.000Z","dependencies_parsed_at":"2022-09-26T21:51:16.800Z","dependency_job_id":null,"html_url":"https://github.com/voltbras/go-ocpp","commit_stats":null,"previous_names":["eduhenke/go-ocpp"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voltbras%2Fgo-ocpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voltbras%2Fgo-ocpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voltbras%2Fgo-ocpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/voltbras%2Fgo-ocpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/voltbras","download_url":"https://codeload.github.com/voltbras/go-ocpp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":196289661,"owners_count":13214548,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["charging-stations","chargingstation","electric-vehicles","emobility","ocpp"],"created_at":"2024-08-02T00:00:28.778Z","updated_at":"2024-08-02T00:01:34.877Z","avatar_url":"https://github.com/voltbras.png","language":"Go","funding_links":[],"categories":["Tools and Resources","Consumption"],"sub_categories":["OCPP","Mobility and Transportation"],"readme":"# go-ocpp\n\nOCPP(1.5/1.6) implementation in Golang.\n\n- v1.5, it's assumed it is SOAP\n- v1.6, it's assumed it is JSON\n\n## Usage\n\n### Central System\n\nJust pass a handler that takes in a `cpreq.ChargePointRequest` and returns a `(cpresp.ChargePointResponse, error)`.\n\nIn SOAP, error messages will be sent back via Fault, as specified in OCPP v1.5\n\nIn Websockets, error messages will be sent back as specified in OCPP-J v1.6\n\n```go\ncsys := cs.New()\ngo csys.Run(\":12811\", func(req cpreq.ChargePointRequest, metadata cs.ChargePointRequestMetadata) (cpresp.ChargePointResponse, error) {\n    // Return an error to the Station communicating to the Central System\n    //\n    // station, isAuthorized := getStation(metadata.ChargePointID)\n    // if !isAuthorized {\n    //   return nil, errors.New(\"charger not authorized to join network\")\n    // }\n    // ---\n    // Or check some specific header in the underlying HTTP request:\n    // \n    // if shouldBlock(metadata.HTTPRequest) {\n    //   return nil, errors.New(\"charger should send appropriate headers\")\n    // }\n\n    switch req := req.(type) {\n    case *cpreq.BootNotification:\n        // accept chargepoint in the network\n        return \u0026cpresp.BootNotification{\n            Status:      \"Accepted\",\n            CurrentTime: time.Now(),\n            Interval:    60,\n        }, nil\n\n    case *cpreq.Heartbeat:\n        return \u0026cpresp.Heartbeat{CurrentTime: time.Now()}, nil\n\n    case *cpreq.StatusNotification:\n        if req.Status != \"Available\" {\n            // chargepoint is unavailable\n        }\n        return \u0026cpresp.StatusNotification{}, nil\n\n    default:\n        return nil, errors.New(\"Response not supported\")\n    }\n}\n```\n\n### Charge Point\n\nPass the required parameters to the constructor function, and then just send any request(`cpreq.*`).\n\nTODO: assertion of the response type should be done inside the `.Send`?\n\n```go\nstationID := \"id01\"\ncentralSystemURL := \"ws://localhost:12811\"\nst, err := cp.NewChargePoint(stationID, centralSystemURL, ocpp.V16, ocpp.JSON, nil, handler) // or ocpp.SOAP\nif err != nil {\n    fmt.Println(\"could not create charge point:\", err)\n    return\n}\nrawResp, err := st.Send(\u0026cpreq.Heartbeat{})\nif err != nil {\n    fmt.Println(\"could't send heartbeat:\", err)\n    return\n}\nresp, ok := rawResp.(*cpresp.Heartbeat)\nif !ok {\n    fmt.Println(\"response is not a heartbeat response\")\n    return\n}\nfmt.Println(\"got reply:\", resp)\n```\n\n### Logs\n\nFor more useful logging, do:\n\n```go\nocpp.SetDebugLogger(log.New(os.Stdout, \"DEBUG:\", log.Ltime))\nocpp.SetErrorLogger(log.New(os.Stderr, \"ERROR:\", log.Ltime))\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoltbras%2Fgo-ocpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvoltbras%2Fgo-ocpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvoltbras%2Fgo-ocpp/lists"}