https://github.com/connected-hil/ocpp-tools
Open charge point protocol tools. Schema validation, Typescript types, and other helpful utilities.
https://github.com/connected-hil/ocpp-tools
ocpp ocpp16j typescript typescript-library validation
Last synced: about 1 month ago
JSON representation
Open charge point protocol tools. Schema validation, Typescript types, and other helpful utilities.
- Host: GitHub
- URL: https://github.com/connected-hil/ocpp-tools
- Owner: connected-hil
- License: mit
- Created: 2024-03-20T07:22:07.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-29T12:59:01.000Z (5 months ago)
- Last Synced: 2025-08-19T15:26:32.167Z (about 2 months ago)
- Topics: ocpp, ocpp16j, typescript, typescript-library, validation
- Language: TypeScript
- Homepage:
- Size: 936 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ev-charging - connected-hil/ocpp-tools
README
Table of Contents
About The Project
Getting Started
Usage
- Typescript interfaces, types and utilities
- Parse OCPP RPC messages
- Construct a response
- Create a new RPC
- Validating OCPP JSON message payloads
- Get validation errors
- Using OCPP interfaces
- Roadmap
- License
## About The Project
**OCPP tools** is a collection of Open Charge Point Protocol message schemas, validation functions, utility types and typed interfaces for Typescript. Most of the code is generated using the OCPP payload JSON schema files.
**Note**: Things are changing, and backwards compatibility might be broken until all todo items are cleard.
## Getting Started
Add ocpp-tools to your project using any package manager, or by cloning this repository.
### Installation
```sh
npm install @cshil/ocpp-tools
```## Usage
### Typescript interfaces, types and utilities
This project includes
- All OCPP v1.6 payloads have [interfaces](src/types/v16) generated from JSON schema files.
- All OCPP v2.0.1 payloads have [interfaces](src/types/v201/) generated from JSON schema files.
- Types for valid CALL actions, request and response types as well as error code types for [v1.6](src/types/v16/index.ts) and [v2.0.1](src/types/v201/index.ts)
- Utility classes for RPC requests for [CALL](src/message/ocpp-call.ts), [CALL_RESULT](src/message/ocpp-call-result.ts) and [CALL ERROR](src/message/ocpp-call-error.ts).
- Parsers for [OCPP RPC calls](src/validation/index.ts) and OCPP message payload validation for [V1.6](src/validation/v16/index.ts) and [v2.0.1](src/validation/v201/index.ts).### Parse a OCPP RPC message
```typescript
import { ocppVersion, parseOCPPMessage, OCPPCallResult } from "@cshil/ocpp-tools";const authorizeRequest = parseOCPPMessage(
"[2, \"message-abc123\", "Authorize", {\"idTag\": \"abc-def-123\""}]",
{
version: ocppVersion.ocpp16,
validateMessage: true,
validatePayload: true // payload is validated for CALL type RPC messages
}
)
console.log(authorizeRequest)
/*
OCPPCallV16 {
version: 'ocpp1.6',
messageId: 'message-abc123',
messageTypeId: 2,
action: 'Authorize',
payload: { idTag: 'abc-def-123' }
}
*/
```### Construct a response
```typescript
import { parseOCPPMessage, AuthorizeResponseV16, OCPPCall} from "@cshil/ocpp-tools";const request = parseOCPPMessage(
"[2, \"abc123\", \"Authorize\", {\"idTag\": \"abc-123-abc\""}]",
)const callResult = request.toCallResponse({idTagInfo: { status: "Accepted"}})
console.info(callResult).toRPCObject)
// => [3, "abc123", { "status": "Accepted"}]```
## Create a new RPC
using the general ocpp call:
```typescript
import { OCPPCall, OCPPRequestTypeV16, ActionV16, ocppVersion } from "@cshil/ocpp-tools";const call = new OCPPCall({ version: ocppVersion.ocpp16, action: "Authorize", payload: { idTag: "abv123"})
```or using the versioned ocpp call:
```typescript
import { OCPPCallV201 } from "@cshil/ocpp-tools";const call = new OCPPCallV201({
action: "Authorize",
payload: { idToken: { idToken: "abv123", type: "Central" } },
});
```### Validating OCPP JSON message payloads
```typescript
import { isValidHeartbeatRequestV16, HeartbeatV16 } from "@cshil/ocpp-tools";const data = JSON.parse("{}"")
const result = isValidHeartbeatRequestV16(data) // => true```
### Get validation errors
```typescript
import { validationErrors, schemas } from "@cshil/ocpp-tools";const errors = validationErrors(schemas.v16.authorizeRequest, {});
// => ["#/required: must have required property 'idTag'"]
```### Using OCPP interfaces
```typescript
import { AuthorizeResponseV16 } from "@cshil/ocpp-tools";const message: AuthorizeResponseV16 = {
idTagInfo: { status: "Accepted" },
};
```## Roadmap
- [x] Include OCPP v1.6 schemas
- [x] Include OCPP v2.0.1 schemas
- [ ] Proper documentationSee the [open issues](https://github.com/connected-hil/ocpp-tools/issues) for a full list of proposed features (and known issues).
## Contributing
Any contributions you make are **greatly appreciated**.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement".
Don't forget to give the project a star! Thanks again!1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request## License
Distributed under the MIT License. See `LICENSE.txt` for more information.