Skip to content

Commit ec43614

Browse files
authored
Merge pull request #17 from juherr/feature/reset
Implement hard/soft reset command
2 parents 9e73508 + 658af1e commit ec43614

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/cp/ChargePoint.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,7 @@ export class ChargePoint {
128128

129129
public connect(): void {
130130
this._webSocket.connect(
131-
() => {
132-
this._messageHandler.sendBootNotification(this._bootNotification);
133-
this.status = OCPPStatus.Available;
134-
this.updateAllConnectorsStatus(OCPPStatus.Available);
135-
this.error = "";
136-
},
131+
() => this.boot(),
137132
(ev: CloseEvent) => {
138133
this.status = OCPPStatus.Unavailable;
139134
this.updateAllConnectorsStatus(OCPPStatus.Unavailable);
@@ -147,12 +142,24 @@ export class ChargePoint {
147142
);
148143
}
149144

145+
public boot(): void {
146+
this._messageHandler.sendBootNotification(this._bootNotification);
147+
this.status = OCPPStatus.Available;
148+
this.updateAllConnectorsStatus(OCPPStatus.Available);
149+
this.error = "";
150+
}
151+
150152
public disconnect(): void {
151153
this._logger.info("Disconnecting from WebSocket");
152154
this._status = OCPPStatus.Unavailable;
153155
this._webSocket.disconnect();
154156
}
155157

158+
public reset(): void {
159+
this.disconnect();
160+
this.connect();
161+
}
162+
156163
public authorize(tagId: string): void {
157164
this._messageHandler.authorize(tagId);
158165
}

src/cp/OCPPMessageHandler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,14 @@ export class OCPPMessageHandler {
357357

358358
private handleReset(payload: request.ResetRequest): response.ResetResponse {
359359
this._logger.log(`Reset request received: ${payload.type}`);
360+
setTimeout(() => {
361+
this._logger.log(`Reset chargePoint: ${this._chargePoint.id}`);
362+
if (payload.type === "Hard") {
363+
this._chargePoint.reset();
364+
} else {
365+
this._chargePoint.boot();
366+
}
367+
}, 5_000);
360368
return {status: "Accepted"};
361369
}
362370

0 commit comments

Comments
 (0)