OICP & OCPI remote start improvements
MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOCommandsEndpoint.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/CPOCommandsEndpoint.ts
@@ -140,7 +140,7 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
});
return this.getOCPIResponse(OCPICommandResponseType.REJECTED);
}
- if (connector.status !== ChargePointStatus.AVAILABLE) {
+ if (!(connector.status === ChargePointStatus.AVAILABLE || connector.status === ChargePointStatus.PREPARING)) {
Logging.logDebug({
tenantID: tenant.id,
action: ServerAction.OCPI_STOP_SESSION,
@@ -282,7 +282,7 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
connectorId: connector.connectorId,
idTag: startSession.token.uid
});
- if (result && result.status === OCPPRemoteStartStopStatus.ACCEPTED) {
+ if (result?.status === OCPPRemoteStartStopStatus.ACCEPTED) {
await this.sendCommandResponse(tenant, ServerAction.OCPI_START_SESSION, startSession.response_url, OCPICommandResponseType.ACCEPTED, ocpiEndpoint);
} else {
await this.sendCommandResponse(tenant, ServerAction.OCPI_START_SESSION, startSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint);
@@ -299,7 +299,7 @@ export default class CPOCommandsEndpoint extends AbstractEndpoint {
transactionId: transactionId
});
- if (result && result.status === OCPPRemoteStartStopStatus.ACCEPTED) {
+ if (result?.status === OCPPRemoteStartStopStatus.ACCEPTED) {
await this.sendCommandResponse(tenant, ServerAction.OCPI_STOP_SESSION, stopSession.response_url, OCPICommandResponseType.ACCEPTED, ocpiEndpoint);
} else {
await this.sendCommandResponse(tenant, ServerAction.OCPI_STOP_SESSION, stopSession.response_url, OCPICommandResponseType.REJECTED, ocpiEndpoint);

MODIFY
src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts
src/server/oicp/oicp-services-impl/oicp-2.3.0/CPORemoteAuthorizationsEndpoint.ts
@@ -65,6 +65,15 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
const chargingStationConnector = await OICPUtils.getChargingStationConnectorFromEvseID(tenant, evseID);
const connector = chargingStationConnector.connector;
const chargingStation = chargingStationConnector.chargingStation;
+ if (!chargingStation) {
+ Logging.logDebug({
+ tenantID: tenant.id,
+ action: ServerAction.OICP_AUTHORIZE_REMOTE_START,
+ message: `Charging Station ID '${authorizeRemoteStart.EvseID}' not found`,
+ module: MODULE_NAME, method: 'authorizeRemoteStart'
+ });
+ return OICPUtils.noSuccess(session, `EVSE for EvseID '${authorizeRemoteStart.EvseID}' not found`);
+ }
if (!connector) {
Logging.logDebug({
tenantID: tenant.id,
@@ -83,7 +92,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
});
return OICPUtils.noSuccess(session, `EVSE '${authorizeRemoteStart.EvseID}' cannot be used with OICP`);
}
- if (connector.status !== ChargePointStatus.AVAILABLE) {
+ if (!(connector.status === ChargePointStatus.AVAILABLE || connector.status === ChargePointStatus.PREPARING)) {
Logging.logDebug({
tenantID: tenant.id,
action: ServerAction.OICP_AUTHORIZE_REMOTE_START,
@@ -95,10 +104,15 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
if (!chargingStation.remoteAuthorizations) {
chargingStation.remoteAuthorizations = [];
}
+ // Check if there is already a authorization for this charging station
const existingAuthorization: RemoteAuthorization = chargingStation.remoteAuthorizations.find(
(authorization) => authorization.connectorId === connector.connectorId);
if (existingAuthorization) {
+ // Check if authorization is from same user or different user
+ if (existingAuthorization.oicpIdentification.RemoteIdentification.EvcoID !== authorizeRemoteStart.Identification.RemoteIdentification.EvcoID) {
+ // Check if authorization of different user is valid
if (OICPUtils.isAuthorizationValid(existingAuthorization.timestamp)) {
+ // Current remote authorization fails due to valid remote authorization of different user
Logging.logDebug({
tenantID: tenant.id,
source: chargingStation.id,
@@ -108,6 +122,7 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
});
return OICPUtils.noSuccess(session, `An existing remote authorization exists for Charging Station '${chargingStation.id}' and Connector ID ${connector.connectorId}`);
}
+ }
existingAuthorization.timestamp = moment().toDate();
// No authorization ID available
// Use sessionID instead
@@ -128,10 +143,8 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
// Save Auth
await ChargingStationStorage.saveChargingStation(tenant.id, chargingStation);
// Start the transaction
- const result = await this.remoteStartTransaction(tenant, chargingStation, connector, authorizeRemoteStart).catch((error) => {
- console.log('Error Remote Start: ', error);
- });
- if (result && result.status === OCPPRemoteStartStopStatus.ACCEPTED) {
+ const result = await this.remoteStartTransaction(tenant, chargingStation, connector, authorizeRemoteStart);
+ if (result.status === OCPPRemoteStartStopStatus.ACCEPTED) {
return OICPUtils.success(session);
}
return OICPUtils.noSuccess(session, 'Remote Start rejected by Charging Station');
@@ -197,6 +210,13 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
private async remoteStartTransaction(tenant: Tenant, chargingStation: ChargingStation, connector: Connector, authorizeRemoteStart: OICPAuthorizeRemoteStartCpoReceive): Promise<OCPPRemoteStartTransactionCommandResult> {
const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant.id, chargingStation);
if (!chargingStationClient) {
+ Logging.logError({
+ tenantID: tenant.id,
+ source: chargingStation.id,
+ action: ServerAction.OICP_AUTHORIZE_REMOTE_START,
+ message: `Charging Station '${chargingStation.id}' not found`,
+ module: MODULE_NAME, method: 'remoteStartTransaction'
+ });
return;
}
const result = await chargingStationClient.remoteStartTransaction({
@@ -209,6 +229,13 @@ export default class CPORemoteAuthorizationsEndpoint extends AbstractEndpoint {
private async remoteStopTransaction(tenant: Tenant, chargingStation: ChargingStation, transactionId: number): Promise<OCPPRemoteStopTransactionCommandResult> {
const chargingStationClient = await ChargingStationClientFactory.getChargingStationClient(tenant.id, chargingStation);
if (!chargingStationClient) {
+ Logging.logError({
+ tenantID: tenant.id,
+ source: chargingStation.id,
+ action: ServerAction.OICP_AUTHORIZE_REMOTE_STOP,
+ message: `Charging Station '${chargingStation.id}' not found`,
+ module: MODULE_NAME, method: 'remoteStopTransaction'
+ });
return;
}
const result = await chargingStationClient.remoteStopTransaction({

OICP & OCPI remote start improvements