mikuso / ocpp-rpc

A Node.js client & server implementation of the WAMP-like RPC-over-websocket system defined in the OCPP-J protocols.
MIT License
98 stars 29 forks source link

Unable to set chargingProfileKind. #51

Closed Seekay369 closed 1 year ago

Seekay369 commented 1 year ago

const chargingProfile = { chargingProfileId: 1, stackLevel: 1, chargingSchedule: [ { startPeriod: 0, }, { startPeriod: 10, }, ], chargingProfileKind: ocpp.ChargingProfileKind.Relative, ChargingProfilePurposeType: ocpp.ChargingProfilePurposeType.TxProfile };

Kindly help how to set chargingProfileKind to Relative? Can it be string "Relative"?
mikuso commented 1 year ago

I'm not sure if you're in the right place. ocpp.ChargingProfileKind is not an export defined by this library.

Can you provide more context?

Seekay369 commented 1 year ago

Sorry that I provide not enuf information. For my situation, I want to set chargingProfile in RemoteStartTransaction.req. According to OCPP1.6 protocol, We are able to set ChargingProfile.

Screenshot 2023-07-17 at 8 32 56 PM Screenshot 2023-07-17 at 8 33 44 PM

Inside the chargingProfile consist of chargingProfilePurpose, chargingProfileKind, chargingSchedule which is required field.

My question is how to set chargingProfilePurpose, chargingProfileKind, chargingSchedule by using this library. Below are my code.

async function startChargingWithProfile(clientId) { const chargingProfile = { chargingProfileId: 1, stackLevel: 1, chargingProfileKind: 'Relative', chargingProfilePurposeType: 'TxProfile' }; console.log('Received start charging'); console.log('Client ID: ' + clientId); const sampleClient = clients.get(clientId); console.log('Sample Client: ' + sampleClient); if (sampleClient) { const response = await sampleClient.call('RemoteStartTransaction', { connectorId: 1, // start on connector 1 idTag: 'seekaypersonal', // using an idTag with identity 'XXXXXXXX' chargingProfile: chargingProfile, });

    if (response.status === 'Accepted') {
        console.log('Remote start worked!');
    } else {
        console.log('Remote start rejected.');
    }

    return response.status;
}
else {
    return 'Client is not available.'
}

}

My purpose is to remote charging and auto-stop charge within a duration. Example: After 60seconds auto stop charge. Hope you can help to clear or correct my misunderstanding.

mikuso commented 1 year ago

My question is how to set chargingProfilePurpose, chargingProfileKind, chargingSchedule by using this library.

There are no enum-like constants - you simply need to write the string values.

Seekay369 commented 1 year ago

is this okay if I set chargingProfileKind to 'Relative' and 'TxProfile' in string value? Because it is not allow me to specify the start time and duration of the charging schedule relative to the start of the transaction, eventhrough the transaction is sucess.

`async function startChargingWithProfile(clientId) {

const chargingSchedulePeriod = {
    startPeriod: 0,
    limit: 8.1,
}

const chargingSchedule = {
    duration: 60,
    chargingRateUnit: 'W',
    chargingSchedulePeriod: [
        chargingSchedulePeriod
    ]
}

const chargingProfile = {
    chargingProfileId: 1,
    stackLevel: 1,
    chargingProfileKind: 'Relative',
    chargingProfilePurposeType: 'TxProfile',
    chargingSchedule: chargingSchedule,
};

const sampleClient = clients.get(clientId);
if (sampleClient) {
    const response = await sampleClient.call('RemoteStartTransaction', {
        connectorId: 1, // start on connector 1
        idTag: 'seekaypersonal', // using an idTag with identity 'XXXXXXXX'
        chargingProfile: chargingProfile,
    });

    if (response.status === 'Accepted') {
        console.log('Remote start with profile worked!');
    } else {
        console.log('Remote start with profile rejected.');
    }

    return response.status;
}
else {
    return 'Client is not available.'
}

}`

mikuso commented 1 year ago

is this okay if I set chargingProfileKind to 'Relative' and 'TxProfile' in string value?

'Relative' is a valid value for chargingProfileKind. 'TxProfile' is a valid value for chargingProfilePurposeType.

If you want to be certain that you are sending valid values, then I recommend enabling strictMode when constructing the RPCServer - as then an error will be generated if you try to send a message that isn't valid.

it is not allow me to specify the start time and duration of the charging schedule relative to the start of the transaction, eventhrough the transaction is sucess.

Do you mean a specific model of charging station is not behaving as expected when you send this charging profile? It may be that the charging station you are using is not fully spec compliant (this is more common than you might think). Additionally, keep in mind that smart charging is an optional component of the OCPP1.6 spec, so it is not required that all charging stations support it.

Seekay369 commented 1 year ago

Thanks for explaining all these. Appreciated.