-
Notifications
You must be signed in to change notification settings - Fork 192
Setting up v1.6 OCPP J server
Thomas Volden edited this page Sep 9, 2016
·
2 revisions
For version 1.6 OCPP-J (JSON) server.
// The core profile is mandatory
ServerCoreProfile core = new ServerCoreProfile(new ServerCoreEventHandler() {
@Override
public AuthorizeConfirmation handleAuthorizeRequest(int sessionIndex, AuthorizeRequest request) {
System.out.println(request);
// ... handle event
return new AuthorizeConfirmation();
}
@Override
public BootNotificationConfirmation handleBootNotificationRequest(int sessionIndex, BootNotificationRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
@Override
public DataTransferConfirmation handleDataTransferRequest(int sessionIndex, DataTransferRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
@Override
public HeartbeatConfirmation handleHeartbeatRequest(int sessionIndex, HeartbeatRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
@Override
public MeterValuesConfirmation handleMeterValuesRequest(int sessionIndex, MeterValuesRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
@Override
public StartTransactionConfirmation handleStartTransactionRequest(int sessionIndex, StartTransactionRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
@Override
public StatusNotificationConfirmation handleStatusNotificationRequest(int sessionIndex, StatusNotificationRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
@Override
public StopTransactionConfirmation handleStopTransactionRequest(int sessionIndex, StopTransactionRequest request) {
System.out.println(request);
// ... handle event
return null; // returning null means unsupported feature
}
});
server = new JSONServer(core);
server.open("localhost", 8887, new ServerEvents() {
@Override
public void newSession(int sessionIndex) {
// sessionIndex is used to send messages.
System.out.println("New session " + sessionIndex);
}
@Override
public void lostSession(int sessionIndex) {
System.out.println("Session " + sessionIndex + " lost connection");
}
});
public void sendClearCacheRequest() throws Exception {
// Use the feature profile to help create event
ClearCacheRequest request = core.createClearCacheRequest();
// Server returns a promise which will be filled once it receives a confirmation.
// Select the distination client with the sessionIndex integer.
server.send(sessionIndex, request).whenComplete((confirmation, throwable) -> System.out.println(confirmation));
}