Here is My Remote Start Transaction code
async function handleStartTransactionNotificationAction(ws, req) {
try {
if (!ws) {
console.error("WebSocket connection is undefined.");
return;
}
console.log("Charger Start Function called...");
const currentDate = new Date();
const formattedTimestamp = currentDate
.toISOString()
.replace(/\.\d{3}Z$/, "Z");
const remoteStartTransactionRequest = [
2,
"b32da12b-1375-4f36-98e8-8368849c8d84",
"RemoteStartTransaction",
{
connectorId: 1,
idTag: "2222",
chargingProfile: {
chargingProfileId: 1,
transactionId: 54344,
stackLevel: 0,
chargingProfilePurpose: "TxDefaultProfile",
chargingProfileKind: "Absolute",
recurrencyKind: "Daily",
validFrom: "2023-10-06T01:00:00Z",
validTo: "2023-10-06T18:00:00Z",
chargingSchedule: {
duration: 3600,
startSchedule: formattedTimestamp,
chargingRateUnit: "W",
chargingSchedulePeriod: [
{
startPeriod: 0,
limit: 800.0,
numberPhases: 3,
},
{
startPeriod: 180,
limit: 4000.0,
numberPhases: 3,
},
],
minChargingRate: 1000.0,
},
},
},
];
const requestJson = JSON.stringify(remoteStartTransactionRequest);
ws.on("message", async (message) => {
try {
const parsedMessage = JSON.parse(message);
console.log("Received message from Start OCPP device: ", parsedMessage);
if (parsedMessage[2] === "StartTransaction") {
console.log(
"Received RemoteStartTransactionResponse:",
parsedMessage
);
// Start Handler Logic Here
const response = [
3,
parsedMessage[1],
{
status: "Accepted",
transactionId: 54344,
},
];
console.log("Acknowledgement sent to station");
const responseJson = JSON.stringify(response);
ws.send(responseJson);
}
} catch (error) {
console.error("Error handling OCPP message:", error);
}
});
ws.send(requestJson);
} catch (error) {
console.error(“Error handling ‘RemoteStartTransaction’ action:”, error);
const response = {
status: “Failed”,
errorCode: “InternalServerError”,
};
}
}