3.9 Stop Transaction

The StopTransaction message in OCPP 1.6J is sent by the charge point to the central system when a charging session ends. It includes details like the transaction ID, user ID tag, timestamp, final meter reading, and the reason for stopping (e.g., user action or remote stop). This message helps finalize the session, track energy usage, and ensure accurate billing.

API Syntax

Description

Input Params

Return Value

SendStopTransactionRequest

This function sends a StopTransaction request packet to the server with the specified kWh value.

Creates an OCPP frame for the request and sends it using “sendframe”.

double kwh

STOPTRANSACTIONERROR_T

Example:

void UpdateAndSendStopTransaction(char* IdTag, int meterStop, int transactionId, STOPTRANSACTION_REASON reason, double kwh)
{
    UpdateStopTransactionRequestIdTag(IdTag);
    UpdateStopTransactionRequestTransctionId(transactionId);
    UpdateStopTransactionReason(reason);
    UpdateStopTransactionRequestMeterStop(meterStop);
    SendStopTransactionRequest(kwh);

}

API Syntax

Description

Input Params

Return Value

UpdateStopTransactionRequestTransctionId

Updates the StopTransaction request transaction ID.

int transactionId

void

Example:

 if (cJSONHasObjectItem(rx->jsonPacket, "transactionId"))
            {
                starttransactionResponse.transactionId = cJSONGetObjectItem(rx->jsonPacket, "transactionId")->valueint;
                SetMeterValuesTransactionId(starttransactionResponse.transactionId);
                UpdateStopTransactionRequestTransctionId(starttransactionResponse.transactionId);
                OCPPProcessReportToApplication(START_TRANSACTION, STARTTRANSACTION_RESPONSE_SUCCESS);
            }
            else
            {
                OCPPLogMessage(LOG_INFO, LOG_RECEIVED, "StartTransaction packet is missing transactionId\n");
                OCPPProcessReportToApplication(START_TRANSACTION, STARTTRANSACTION_RESPONSE_FAILED);
            }

API Syntax

Description

Input Params

Return Value

UpdateStopTransactionRequestMeterStop

Updates the StopTransaction request meter stop value.

int meterStop

void

Example:

void UpdateAndSendStopTransaction(char* IdTag, int meterStop, int transactionId, STOPTRANSACTION_REASON reason, double kwh)
{
    UpdateStopTransactionRequestIdTag(IdTag);
    UpdateStopTransactionRequestTransctionId(transactionId);
    UpdateStopTransactionReason(reason);
    UpdateStopTransactionRequestMeterStop(meterStop);
    (void)SendStopTransactionRequest(kwh);

}

Syntax

Description

Constants/Members

STOPTRANSACTION_REQUEST_T

Structure for StopTransaction request parameters

char IdTag[];

char uuid[];

int meterStop;

char timeStamp[];

int transactionId;

STOPTRANSACTION_REASON reason;

char transactionData[];

AUTHORIZATIONSTATUS_T

Enumeration of possible authorization statuses

AUTHORIZATION_ACCEPTED

AUTHORIZATION_BLOCKED

AUTHORIZATION_EXPIRED

AUTHORIZATION_INVALID

IDTAG_INFO_T

Structure used to store details about an ID tag

char expiryDate[];

idToken parentIdTag;

AUTHORIZATION_STATUS_T status;

STOPTRANSACTION_RESPONSE_T

Structure for StopTransaction response parameters

AUTHORIZATIONSTATUS_T enumState;

IDTAG_INFO_T idTagInfo;

STOPTRANSACTIONERROR_T

Enumeration of possible error codes for StopTransaction operations

STOPTRANSACTION_SUCCESS

STOPTRANSACTION_FAILED

STOPTRANSACTION_RESPONSE_SUCCESS

STOPTRANSACTION_RESPONSE_FAILED