Table of Contents
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.
Add ocpp-tools to your project using any package manager, or by cloning this repository.
npm install @cshil/ocpp-tools
This project includes
- All OCPP v1.6 payloads have interfaces generated from JSON schema files.
- All OCPP v2.0.1 payloads have interfaces generated from JSON schema files.
- Types for valid CALL actions, request and response types as well as error code types for v1.6 and v2.0.1
- Utility classes for RPC requests for CALL, CALL_RESULT and CALL ERROR.
- Parsers for OCPP RPC calls and OCPP message payload validation for V1.6 and v2.0.1.
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' }
}
*/
import { parseOCPPMessage, AuthorizeResponseV16, OCPPCall} from "@cshil/ocpp-tools";
const request = parseOCPPMessage(
"[2, \"abc123\", \"Authorize\", {\"idTag\": \"abc-123-abc\""}]",
)
const callResult = request.toCallResponse<AuthorizeResponseV16>({idTagInfo: { status: "Accepted"}})
console.info(callResult).toRPCObject)
// => [3, "abc123", { "status": "Accepted"}]
using the general ocpp call:
import { OCPPCall, OCPPRequestTypeV16, ActionV16, ocppVersion } from "@cshil/ocpp-tools";
const call = new OCPPCall<OCPPRequestTypeV16, ActionV16>({ version: ocppVersion.ocpp16, action: "Authorize", payload: { idTag: "abv123"})
or using the versioned ocpp call:
import { OCPPCallV201 } from "@cshil/ocpp-tools";
const call = new OCPPCallV201({
action: "Authorize",
payload: { idToken: { idToken: "abv123", type: "Central" } },
});
import { isValidHeartbeatRequestV16, HeartbeatV16 } from "@cshil/ocpp-tools";
const data = JSON.parse("{}"")
const result = isValidHeartbeatRequestV16(data) // => true
import { validationErrors, schemas } from "@cshil/ocpp-tools";
const errors = validationErrors(schemas.v16.authorizeRequest, {});
// => ["#/required: must have required property 'idTag'"]
import { AuthorizeResponseV16 } from "@cshil/ocpp-tools";
const message: AuthorizeResponseV16 = {
idTagInfo: { status: "Accepted" },
};
- Include OCPP v1.6 schemas
- Include OCPP v2.0.1 schemas
- Proper documentation
See the open issues for a full list of proposed features (and known issues).
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!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.