Set the proper Tag type
MODIFY
src/client/ocpi/EmspOCPIClient.ts
src/client/ocpi/EmspOCPIClient.ts
@@ -486,7 +486,7 @@ export default class EmspOCPIClient extends OCPIClient {
}
const token: OCPIToken = {
uid: tag.id,
- type: OCPITokenType.RFID,
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
auth_id: tag.user.id,
visual_number: tag.user.id,
issuer: this.tenant.name,
@@ -495,17 +495,19 @@ export default class EmspOCPIClient extends OCPIClient {
last_updated: new Date()
};
const authorizationId = Utils.generateUUID();
- const payload: OCPIStartSession = {
+ // Get the location ID from the Site Area name
+ const locationID = OCPIUtils.getOCPIEmspLocationIDFromSiteAreaName(chargingStation.siteArea.name);
+ const remoteStart: OCPIStartSession = {
response_url: callbackUrl + '/' + authorizationId,
token: token,
- evse_uid: chargingStation.imsi,
- location_id: chargingStation.iccid,
+ evse_uid: chargingStation.id,
+ location_id: locationID,
authorization_id: authorizationId
};
// Call IOP
const response = await this.axiosInstance.post(
commandUrl,
- payload,
+ remoteStart,
{
headers: {
'Authorization': `Token ${this.ocpiEndpoint.token}`,
@@ -518,7 +520,7 @@ export default class EmspOCPIClient extends OCPIClient {
source: chargingStation.id,
message: `Connector ID '${connectorId}' > OCPI Remote Start session response status ${response.status}`,
module: MODULE_NAME, method: 'remoteStartSession',
- detailedMessages: { response: response.data }
+ detailedMessages: { remoteStart, response: response.data }
});
return response.data.data as OCPICommandResponse;
}

MODIFY
src/server/ocpi/OCPIUtils.ts
src/server/ocpi/OCPIUtils.ts
import ChargingStation, { Connector } from '../../types/ChargingStation';
+import { OCPIToken, OCPITokenType } from '../../types/ocpi/OCPIToken';
import AppError from '../../exception/AppError';
+import Constants from '../../utils/Constants';
import { OCPIResponse } from '../../types/ocpi/OCPIResponse';
import { OCPIStatusCode } from '../../types/ocpi/OCPIStatusCode';
-import { OCPIToken } from '../../types/ocpi/OCPIToken';
import { Request } from 'express';
import Utils from '../../utils/Utils';
import moment from 'moment';
-/**
- * OCPI Utils
- */
export default class OCPIUtils {
- /**
- * Return OCPI Success Body Response
- *
- * @param {*} data
- */
public static success(data?: any): OCPIResponse {
return {
data: data,
@@ -27,11 +20,6 @@ export default class OCPIUtils {
};
}
- /**
- * Return OCPI Error Body Response
- *
- * @param {*} error
- */
public static toErrorResponse(error: Error): OCPIResponse {
return {
status_message: error.message,
@@ -41,15 +29,6 @@ export default class OCPIUtils {
};
}
- /**
- * Build Next Url
- *
- * @param {*} req request in order to get url
- * @param {*} baseUrl the baseUrl of the service to get url
- * @param {*} offset offset
- * @param {*} limit limit of query
- * @param {*} total total number of records
- */
public static buildNextUrl(req: Request, baseUrl: string, offset: number, limit: number, total: number): string | undefined {
// Check if next link should be generated
if (offset + limit < total) {
@@ -65,11 +44,6 @@ export default class OCPIUtils {
}
}
- /**
- * Retrieve the next url from the link response header
- *
- * @param {*} link the link header of the response
- */
public static getNextUrl(link: string): string | undefined {
if (link) {
const match = /<(.*)>;rel="next"/.exec(link.replace(/ /g, ''));
@@ -79,64 +53,27 @@ export default class OCPIUtils {
}
}
- /**
- * Build Location Url
- *
- * @param {*} req request in order to get url
- * @param {*} baseUrl the baseUrl of the service to get url
- * @param {*} id the object id to build the location url
- */
public static buildLocationUrl(req: Request, baseUrl: string, id: string): string {
// Build url
return `${baseUrl + req.originalUrl.split('?')[0]}/${id}`;
}
- /**
- * Build Charging Station Id from OCPI location
- *
- * @param {*} locationId id of the location
- * @param {*} evseId id of the evse
- */
public static buildChargingStationId(locationId: string, evseId: string): string {
return `${locationId}-${evseId}`;
}
- /**
- * Build Operator name from OCPI identifiers (country code and party Id)
- *
- * @param {*} countryCode the code of the operator
- * @param {*} partyId the partyId of the operator
- */
public static buildOperatorName(countryCode: string, partyId: string): string {
return `${countryCode}*${partyId}`;
}
- /**
- * Build Site Area name from OCPI location
- *
- * @param {*} countryCode the code of the CPO
- * @param {*} partyId the partyId of the CPO
- * @param {*} locationId id of the location
- */
public static buildSiteAreaName(countryCode: string, partyId: string, locationId: string): string {
return `${countryCode}*${partyId}-${locationId}`;
}
- /**
- * Build evse UID from charging station
- *
- * @param {*} chargingStation the charging station used to build the evse UID
- * @param {*} connector the connector used to build the evse UID
- */
public static buildEvseUID(chargingStation: ChargingStation, connector: Connector): string {
return `${chargingStation.id}*${connector.connectorId}`;
}
- /**
- * Build evse UIDs from charging station
- *
- * @param {*} chargingStation the charging station used to build the evse UIDs
- */
public static buildEvseUIDs(chargingStation: ChargingStation): string[] {
const evseUIDs: string[] = [];
for (const _connector of chargingStation.connectors) {
@@ -147,42 +84,30 @@ export default class OCPIUtils {
return evseUIDs;
}
- /**
- * Build User email from OCPI token, eMSP country code and eMSP partyId
- *
- * @param {*} token the OCPI token of the user
- * @param {*} countryCode the country code of the eMSP
- * @param {*} partyId the party identifier of the eMSP
- */
public static buildEmspEmailFromOCPIToken(token: OCPIToken, countryCode: string, partyId: string): string {
if (token?.issuer) {
return `${token.issuer}@${partyId}.${countryCode}`;
}
}
- /**
- * Convert from base64 back to String.
- *
- * @param {*} base64 base64 encoded string
- */
public static atob(base64: string): string {
return Buffer.from(base64, 'base64').toString('binary');
}
- /**
- * Convert to base64 from String.
- *
- * @param {*} string string to base64 encode
- */
public static btoa(string: string): string {
return Buffer.from(string).toString('base64');
}
- /**
- * Generate a local token for a tenant subdomain
- *
- * @param tenantSubdomain
- */
+ public static getOCPITokenTypeFromID(tagID: string): OCPITokenType {
+ // Virtual badges handling
+ return tagID.length % 8 === 0 ? OCPITokenType.RFID : OCPITokenType.OTHER;
+ }
+
+ public static getOCPIEmspLocationIDFromSiteAreaName(siteAreaName: string): string {
+ const siteParts = siteAreaName.split(Constants.OCPI_SEPARATOR) as string[];
+ return siteParts.pop();
+ }
+
public static generateLocalToken(tenantSubdomain: string): string {
const newToken: any = {};
// Generate random

MODIFY
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
src/server/ocpi/ocpi-services-impl/ocpi-2.1.1/OCPIUtilsService.ts
@@ -161,7 +161,7 @@ export default class OCPIUtilsService {
for (const tag of tags.result) {
tokens.push({
uid: tag.id,
- type: (tag.id.length % 8 === 0) ? OCPITokenType.RFID : OCPITokenType.OTHER, // Virtual badges handling
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
auth_id: tag.userID,
visual_number: tag.userID,
issuer: tenant.name,

MODIFY
src/server/rest/v1/service/TagService.ts
src/server/rest/v1/service/TagService.ts
@@ -21,6 +21,7 @@ import LockingManager from '../../../../locking/LockingManager';
import Logging from '../../../../utils/Logging';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
+import OCPIUtils from '../../../ocpi/OCPIUtils';
import { ServerAction } from '../../../../types/Server';
import { StatusCodes } from 'http-status-codes';
import TagSecurity from './security/TagSecurity';
@@ -190,7 +191,7 @@ export default class TagService {
if (ocpiClient) {
await ocpiClient.pushToken({
uid: tag.id,
- type: OCPITokenType.RFID,
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
auth_id: tag.userID,
visual_number: tag.userID,
issuer: tenant.name,
@@ -298,7 +299,7 @@ export default class TagService {
if (ocpiClient) {
await ocpiClient.pushToken({
uid: newTag.id,
- type: OCPITokenType.RFID,
+ type: OCPIUtils.getOCPITokenTypeFromID(newTag.id),
auth_id: newTag.userID,
visual_number: newTag.userID,
issuer: tenant.name,
@@ -435,7 +436,7 @@ export default class TagService {
if (ocpiClient) {
await ocpiClient.pushToken({
uid: tag.id,
- type: OCPITokenType.RFID,
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
auth_id: tag.userID,
visual_number: tag.userID,
issuer: tenant.name,
@@ -738,7 +739,7 @@ export default class TagService {
if (ocpiClient) {
await ocpiClient.pushToken({
uid: tag.id,
- type: OCPITokenType.RFID,
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
auth_id: tag.userID,
visual_number: tag.userID,
issuer: tenant.name,

MODIFY
src/server/rest/v1/service/UserService.ts
src/server/rest/v1/service/UserService.ts
@@ -30,6 +30,7 @@ import Logging from '../../../../utils/Logging';
import NotificationHandler from '../../../../notification/NotificationHandler';
import OCPIClientFactory from '../../../../client/ocpi/OCPIClientFactory';
import { OCPIRole } from '../../../../types/ocpi/OCPIRole';
+import OCPIUtils from '../../../ocpi/OCPIUtils';
import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
import SiteStorage from '../../../../storage/mongodb/SiteStorage';
@@ -95,12 +96,12 @@ export default class UserService {
// Get the default Tag
let tag = await TagStorage.getDefaultUserTag(req.user.tenantID, userID, {
issuer: true
- }, ['id', 'description']);
+ }, ['id', 'description', 'active']);
if (!tag) {
// Get the first active Tag
tag = await TagStorage.getFirstActiveUserTag(req.user.tenantID, userID, {
issuer: true
- }, ['id', 'description']);
+ }, ['id', 'description', 'active']);
}
// Handle Car
let car: Car;
@@ -383,7 +384,7 @@ export default class UserService {
for (const tag of tags) {
await ocpiClient.pushToken({
uid: tag.id,
- type: OCPITokenType.RFID,
+ type: OCPIUtils.getOCPITokenTypeFromID(tag.id),
auth_id: tag.id,
visual_number: user.id,
issuer: tenant.name,

Set the proper Tag type