retrieving soc from mercedes connector
MODIFY
src/integration/car-connector/CarConnectorIntegration.ts
src/integration/car-connector/CarConnectorIntegration.ts
@@ -16,5 +16,5 @@ export default abstract class CarConnectorIntegration<T extends CarConnectorSett
public abstract createConnection(userID: string, data: unknown): Promise<Connection>;
- public abstract getCurrentSoC(userID: string): Promise<number>;
+ public abstract getCurrentSoC(userID: string, VIN: string): Promise<number>;
}

MODIFY
src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts
src/integration/car-connector/mercedes-connector/MercedesCarConnectorIntegration.ts
@@ -137,10 +137,28 @@ export default class MercedesCarConnectorIntegration extends CarConnectorIntegra
}
}
- public async getCurrentSoC(userID: string): Promise<number> {
- // To be implemented
+ public async getCurrentSoC(userID: string, VIN: string): Promise<number> {
const connection = await this.getRefreshedConnection(userID);
- return 0;
+ const request = `${this.connection.mercedesConnection.apiUrl}/vehicledata/v2/vehicles/${VIN}/resources/soc`;
+ try {
+ // Get consumption
+ const response = await this.axiosInstance.get(
+ request,
+ {
+ headers: { 'Authorization': 'Bearer ' + connection.data.access_token }
+ }
+ );
+ return response.data.soc;
+ } catch (error) {
+ throw new BackendError({
+ source: Constants.CENTRAL_SERVER,
+ module: MODULE_NAME,
+ method: 'getCurrentSoC',
+ action: ServerAction.CAR_CONNECTOR,
+ message: 'Error while retrieving the SOC',
+ detailedMessages: { request, error: error.stack }
+ });
+ }
}
private computeValidUntilAt(response: AxiosResponse) {

MODIFY
src/server/ocpp/services/OCPPService.ts
src/server/ocpp/services/OCPPService.ts
@@ -7,6 +7,8 @@ import Transaction, { InactivityStatus, TransactionAction } from '../../../types
import { Action } from '../../../types/Authorization';
import Authorizations from '../../../authorization/Authorizations';
import BackendError from '../../../exception/BackendError';
+import { CarConnectorConnectionType } from '../../../types/Setting';
+import CarConnectorFactory from '../../../integration/car-connector/CarConnectorFactory';
import CarStorage from '../../../storage/mongodb/CarStorage';
import ChargingStationClientFactory from '../../../client/ocpp/ChargingStationClientFactory';
import ChargingStationConfiguration from '../../../types/configuration/ChargingStationConfiguration';
@@ -447,6 +449,8 @@ export default class OCPPService {
await OCPPUtils.processTransactionBilling(tenant, newTransaction, TransactionAction.START);
// Roaming
await OCPPUtils.processTransactionRoaming(tenant, newTransaction, chargingStation, tag, TransactionAction.START);
+ // Handle current SOC
+ newTransaction.stateOfCharge = await this.getCurrentSOC(tenant, newTransaction, chargingStation);
// Save it
await TransactionStorage.saveTransaction(tenant, newTransaction);
// Clean up
@@ -572,6 +576,8 @@ export default class OCPPService {
await OCPPUtils.processTransactionBilling(tenant, transaction, TransactionAction.STOP);
// Roaming
await OCPPUtils.processTransactionRoaming(tenant, transaction, chargingStation, transaction.tag, TransactionAction.STOP);
+ // Handle current SOC
+ transaction.stop.stateOfCharge = await this.getCurrentSOC(tenant, transaction, chargingStation);
// Save the transaction
await TransactionStorage.saveTransaction(tenant, transaction);
// Notify User
@@ -1659,6 +1665,29 @@ export default class OCPPService {
}
}
+ private async getCurrentSOC(tenant: Tenant, transaction: Transaction, chargingStation: ChargingStation): Promise<number> {
+ if (Utils.isTenantComponentActive(tenant, TenantComponents.CAR_CONNECTOR) && transaction.carID && transaction.carCatalogID &&
+ Utils.getChargingStationCurrentType(chargingStation, null, transaction.connectorId) === CurrentType.AC) {
+ const car = await CarStorage.getCar(tenant, transaction.carID);
+ const carCatalog = await CarStorage.getCarCatalog(car.carCatalogID);
+ let stateOfCharge = 0;
+ switch (carCatalog.vehicleMake) {
+ case 'Mercedes': {
+ const carImplementation = await CarConnectorFactory.getCarConnectorImpl(tenant, CarConnectorConnectionType.MERCEDES);
+ if (carImplementation) {
+ try {
+ stateOfCharge = await carImplementation.getCurrentSoC(transaction.userID, car.vin);
+ } catch {
+ return 0;
+ }
+ return stateOfCharge;
+ }
+ break;
+ }
+ }
+ }
+ }
+
private addChargingStationToException(error: BackendError, chargingStationID: string): void {
if (error.params) {
error.params.source = chargingStationID;

retrieving soc from mercedes connector