ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

Key name naming style for AnyType data

Open m4su6747 opened this issue 1 year ago • 0 comments
trafficstars

Hello,

I tried to collect data using customData or DataTransfer.

Here is an example:

request = call.DataTransfer(
    vendor_id="my.vendor.id",
    message_id="dataCollection",
    data={
        "camelCaseKey": 1,
        "snake_case_key": 2,
        "SCREAMING_CASE_KEY": 3,
        "iso15118eMAID": "Desired key name:iso15118eMAID",
        "iso15118Emaid": "camelCase iso15118eMAID",
        "iso15118_emaid": "snake_case iso15118eMAID"
    }
)
response = await cp.call(request)

According to the document:

OCPP uses a camelCase naming scheme for the keys in the payload. Python, on the other hand, uses snake_case.

Therefore this ocpp package converts all keys in messages from camelCase to snake_case and vice versa to make sure you can write Pythonic code.

Since all the data I send will pass through the camelCase/snake_case conversion, the outgoing message will be:

INFO:ocpp:CP_001: send [2,"15dd2db7-6338-4d98-9de7-29f20a50894c","DataTransfer",{"vendorId":"eTreego","messageId":"dataCollection","data":{"camelCaseKey":1,"snakeCaseKey":2,"SCREAMINGCASEKEY":3,"iso15118eMAID":"Desired key name:iso15118eMAID","iso15118Emaid":"snake_case iso15118eMAID"}}]

And the received payload structure in python becomes:

{
    "vendor_id": "my.vendor.id",
    "message_id": "dataCollection",
    "data": {
        "camel_case_key": 1,
        "snake_case_key": 2,
        "screamingcasekey": 3,
        "iso15118e_maid": "Desired key name:iso15118eMAID",
        "iso15118_emaid": "snake_case iso15118eMAID",
    }
}

I'm wondering whether it should skip the conversion, or should OCPP be restricted to using camelCase key names even for AnyType data?

m4su6747 avatar Jun 05 '24 10:06 m4su6747