- this.startAuthorizationFileMonitoring();
- // Monitor station template file
- this.startStationTemplateFileMonitoring();
- // Handle Socket incoming messages
- this.wsConnection.on('message', this.onMessage.bind(this));
- // Handle Socket error
- this.wsConnection.on('error', this.onError.bind(this));
- // Handle Socket close
- this.wsConnection.on('close', this.onClose.bind(this));
- // Handle Socket opening connection
- this.wsConnection.on('open', this.onOpen.bind(this));
- // Handle Socket ping
- this.wsConnection.on('ping', this.onPing.bind(this));
- // Handle Socket pong
- this.wsConnection.on('pong', this.onPong.bind(this));
+ FileUtils.watchJsonFile<string[]>(
+ this.logPrefix(),
+ FileType.Authorization,
+ this.getAuthorizationFile(),
+ this.authorizedTags
+ );
+ // Monitor charging station template file
+ FileUtils.watchJsonFile(
+ this.logPrefix(),
+ FileType.ChargingStationTemplate,
+ this.stationTemplateFile,
+ null,
+ (event, filename): void => {
+ if (filename && event === 'change') {
+ try {
+ logger.debug(
+ `${this.logPrefix()} ${FileType.ChargingStationTemplate} ${
+ this.stationTemplateFile
+ } file have changed, reload`
+ );
+ // Initialize
+ this.initialize();
+ // Restart the ATG
+ if (
+ !this.stationInfo.AutomaticTransactionGenerator.enable &&
+ this.automaticTransactionGenerator
+ ) {
+ this.automaticTransactionGenerator.stop();
+ }
+ this.startAutomaticTransactionGenerator();
+ if (this.getEnableStatistics()) {
+ this.performanceStatistics.restart();
+ } else {
+ this.performanceStatistics.stop();
+ }
+ // FIXME?: restart heartbeat and WebSocket ping when their interval values have changed
+ } catch (error) {
+ logger.error(
+ `${this.logPrefix()} ${FileType.ChargingStationTemplate} file monitoring error: %j`,
+ error
+ );
+ }
+ }
+ }
+ );
+ FileUtils.watchJsonFile<ChargingStationConfiguration>(
+ this.logPrefix(),
+ FileType.ChargingStationConfiguration,
+ this.configurationFile,
+ this.configuration
+ );
+ // Handle WebSocket message
+ this.wsConnection.on(
+ 'message',
+ this.onMessage.bind(this) as (this: WebSocket, data: RawData, isBinary: boolean) => void
+ );
+ // Handle WebSocket error
+ this.wsConnection.on(
+ 'error',
+ this.onError.bind(this) as (this: WebSocket, error: Error) => void
+ );
+ // Handle WebSocket close
+ this.wsConnection.on(
+ 'close',
+ this.onClose.bind(this) as (this: WebSocket, code: number, reason: Buffer) => void
+ );
+ // Handle WebSocket open
+ this.wsConnection.on('open', this.onOpen.bind(this) as (this: WebSocket) => void);
+ // Handle WebSocket ping
+ this.wsConnection.on('ping', this.onPing.bind(this) as (this: WebSocket, data: Buffer) => void);
+ // Handle WebSocket pong
+ this.wsConnection.on('pong', this.onPong.bind(this) as (this: WebSocket, data: Buffer) => void);
+ parentPort.postMessage({
+ id: ChargingStationWorkerMessageEvents.STARTED,
+ data: { id: this.stationInfo.chargingStationId },
+ });