Skip to content

Setting up v1.6 OCPP J client

Thomas Volden edited this page Sep 9, 2016 · 2 revisions

Setting up v1.6 OCPP J client

For version 1.6 OCPP-J (JSON) client.

Instantiating client and connecting to server

    // The core profile is mandatory
    core = new CoreProfile(new ClientCoreEventHandler() {
        @Override
        public ChangeAvailabilityConfirmation handleChangeAvailabilityRequest(ChangeAvailabilityRequest request) {

            System.out.println(request);
            // ... handle event

            return new ChangeAvailabilityConfirmation(AvailabilityStatus.Accepted);
        }

        @Override
        public GetConfigurationConfirmation handleGetConfigurationRequest(GetConfigurationRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public ChangeConfigurationConfirmation handleChangeConfigurationRequest(ChangeConfigurationRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public ClearCacheConfirmation handleClearCacheRequest(ClearCacheRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public DataTransferConfirmation handleDataTransferRequest(DataTransferRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public RemoteStartTransactionConfirmation handleRemoteStartTransactionRequest(RemoteStartTransactionRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public RemoteStopTransactionConfirmation handleRemoteStopTransactionRequest(RemoteStopTransactionRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public ResetConfirmation handleResetRequest(ResetRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }

        @Override
        public UnlockConnectorConfirmation handleUnlockConnectorRequest(UnlockConnectorRequest request) {

            System.out.println(request);
            // ... handle event

            return null; // returning null means unsupported feature
        }
    });
    client = new JSONClient(core);
    client.connect("ws://hostname:8887");

Sending request

    // Use the feature profile to help create event
    Request request = core.createBootNotificationRequest("some vendor", "some model");

    // Client returns a promise which will be filled once it receives a confirmation.
    client.send(request).whenComplete((s, ex) -> System.out.println(s));