Call the right cloud instance in production
MODIFY
docker/config-standalone.json
docker/config-standalone.json
"OCPIEndpoint": {
"baseUrl": "http://server-standalone:9090"
},
- "WSClient": {
- "autoReconnectMaxRetries": 10,
- "autoReconnectTimeout": 60
- },
"AsyncTask": {
"active": true,
"nbrTasksInParallel": 4

MODIFY
docker/config.json
docker/config.json
"OCPIEndpoint": {
"baseUrl": "http://server:9090"
},
- "WSClient": {
- "autoReconnectMaxRetries": 10,
- "autoReconnectTimeout": 60
- },
"AsyncTask": {
"active": true,
"nbrTasksInParallel": 4

MODIFY
src/assets/config-template-http.json
src/assets/config-template-http.json
"OCPIEndpoint": {
"baseUrl": ""
},
- "WSClient": {
- "autoReconnectMaxRetries": 10,
- "autoReconnectTimeout": 60
- },
"AsyncTask": {
"active": true,
"nbrTasksInParallel": 4

MODIFY
src/client/ocpp/json/JsonRestChargingStationClient.ts
src/client/ocpp/json/JsonRestChargingStationClient.ts
@@ -5,7 +5,6 @@ import { ServerAction, WSServerProtocol } from '../../../types/Server';
import BackendError from '../../../exception/BackendError';
import ChargingStationClient from '../ChargingStationClient';
-import Configuration from '../../../utils/Configuration';
import Logging from '../../../utils/Logging';
import Utils from '../../../utils/Utils';
import WSClient from '../../websocket/WSClient';
@@ -42,7 +41,11 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
chargingStationURL = chargingStationURL.substring(0, chargingStationURL.length - 1);
}
// Keep
+ this.serverURL = `wss://${chargingStation.cloudHostIP}/REST/${tenantID}/${chargingStation.tokenID}/${chargingStation.id}`;
+ // Override
+ if (Utils.isDevelopmentEnv()) {
this.serverURL = `${chargingStationURL}/REST/${tenantID}/${chargingStation.tokenID}/${chargingStation.id}`;
+ }
this.chargingStation = chargingStation;
this.requests = {};
}
@@ -124,18 +127,17 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
message: `Try to connect to '${this.serverURL}'...`
});
// Create Promise
- return await new Promise((resolve, reject) => {
+ return new Promise((resolve, reject) => {
try {
// Create WS
- const wsOptions = {
- protocol: WSServerProtocol.REST
- };
const wsClientOptions: WSClientOptions = {
- WSOptions: wsOptions,
- autoReconnectTimeout: Configuration.getWSClientConfig().autoReconnectTimeout,
- autoReconnectMaxRetries: Configuration.getWSClientConfig().autoReconnectMaxRetries,
+ wsOptions: {
+ protocol: WSServerProtocol.REST,
+ handshakeTimeout: 5000,
+ },
logTenantID: this.tenantID
};
+ // Create and Open the WS
this.wsConnection = new WSClient(this.serverURL, wsClientOptions);
// Opened
this.wsConnection.onopen = async () => {
@@ -227,8 +229,7 @@ export default class JsonRestChargingStationClient extends ChargingStationClient
});
}
} catch (error) {
- await Logging.logException(error, ServerAction.WS_REST_CLIENT_MESSAGE, MODULE_NAME, 'onMessage', this.tenantID
- );
+ await Logging.logException(error, ServerAction.WS_REST_CLIENT_MESSAGE, MODULE_NAME, 'onMessage', this.tenantID);
}
};
} catch (error) {

MODIFY
src/client/websocket/WSClient.ts
src/client/websocket/WSClient.ts
@@ -40,7 +40,7 @@ export default class WSClient {
}
public open(): void {
- this.ws = new WebSocket(this.url, this.options.protocols || [], this.options.WSOptions || {});
+ this.ws = new WebSocket(this.url, this.options.protocols || [], this.options.wsOptions || {});
// Handle Socket open
this.ws.on('open', this.onOpen.bind(this));
// Handle Socket error

MODIFY
src/types/WebSocket.ts
src/types/WebSocket.ts
-import WSClientConfiguration from './configuration/WSClientConfiguration';
import { WSServerProtocol } from './Server';
import WebSocket from 'ws';
@@ -40,8 +39,8 @@ export enum WebSocketCloseEventStatusCode {
CLOSE_TLS_HANDSHAKE = 1015
}
-export interface WSClientOptions extends WSClientConfiguration {
- WSOptions?: WebSocket.ClientOptions;
+export interface WSClientOptions {
+ wsOptions?: WebSocket.ClientOptions;
logTenantID?: string;
protocols?: WSServerProtocol | WSServerProtocol[];
}

DELETE
src/types/configuration/WSClientConfiguration.ts
-export default interface WSClientConfiguration {
- autoReconnectMaxRetries: number;
- autoReconnectTimeout: number;
-}

MODIFY
src/utils/Configuration.ts
src/utils/Configuration.ts
@@ -25,7 +25,6 @@ import OICPEndpointConfiguration from '../types/configuration/OICPEndpointConfig
import OICPServiceConfiguration from '../types/configuration/OICPServiceConfiguration';
import SchedulerConfiguration from '../types/configuration/SchedulerConfiguration';
import StorageConfiguration from '../types/configuration/StorageConfiguration';
-import WSClientConfiguration from '../types/configuration/WSClientConfiguration';
import WSDLEndpointConfiguration from '../types/configuration/WSDLEndpointConfiguration';
import fs from 'fs';
import global from './../types/GlobalType';
@@ -153,19 +152,6 @@ export default class Configuration {
return Configuration.getConfig().Logging;
}
- public static getWSClientConfig(): WSClientConfiguration {
- if (Configuration.isUndefined(Configuration.getConfig().WSClient)) {
- Configuration.getConfig().WSClient = {} as WSClientConfiguration;
- }
- if (Configuration.isUndefined(Configuration.getConfig().WSClient.autoReconnectMaxRetries)) {
- Configuration.getConfig().WSClient.autoReconnectMaxRetries = Constants.WS_DEFAULT_RECONNECT_MAX_RETRIES;
- }
- if (Configuration.isUndefined(Configuration.getConfig().WSClient.autoReconnectTimeout)) {
- Configuration.getConfig().WSClient.autoReconnectTimeout = Constants.WS_DEFAULT_RECONNECT_TIMEOUT;
- }
- return Configuration.getConfig().WSClient;
- }
-
public static getHealthCheckConfig(): HealthCheckConfiguration {
if (Configuration.isUndefined(Configuration.getConfig().HealthCheck)) {
Configuration.getConfig().HealthCheck = {} as HealthCheckConfiguration;

MODIFY
test/api/ocpp/json/OCPPJsonService16.ts
test/api/ocpp/json/OCPPJsonService16.ts
@@ -30,8 +30,6 @@ export default class OCPPJsonService16 extends OCPPService {
const sentRequests = {};
const wsClientOptions: WSClientOptions = {
protocols: WSServerProtocol.OCPP16,
- autoReconnectTimeout: config.get('wsClient').autoReconnectTimeout,
- autoReconnectMaxRetries: config.get('wsClient').autoReconnectMaxRetries
};
const wsConnection = new WSClient(`${this.serverUrl}/${chargeBoxIdentity}`, wsClientOptions, false);
// Opened

MODIFY
test/config-template.json
test/config-template.json
"host": "127.0.0.1",
"port": 1080
},
- "wsClient": {
- "autoReconnectMaxRetries": 10,
- "autoReconnectTimeout": 0
- },
"storage": {
"implementation": "mongodb",
"uri": null,

MODIFY
test/config.js
test/config.js
@@ -183,18 +183,6 @@ const config = convict({
default: 1080,
},
},
- wsClient: {
- autoReconnectMaxRetries: {
- doc: 'WebSocket client re-connection max retries.',
- format: 'int',
- default: 0,
- },
- autoReconnectTimeout: {
- doc: 'WebSocket client re-connection timeout.',
- format: 'int',
- default: 0,
- },
- },
axios: {
timeout: {
doc: 'Axios HTTP client connection timeout',

Call the right cloud instance in production