mobilityhouse / ocpp

Python implementation of the Open Charge Point Protocol (OCPP).
MIT License
744 stars 291 forks source link

Data transfer from CP to Central #619

Open Jonamaita opened 4 months ago

Jonamaita commented 4 months ago

I have been testing my central system sending it a data transfer message. So, I sent a json with the data transfer message how below:

data = [{
        "timestamp": str(datetime.utcnow()),
        "connectorId": 1,
         "vin": "1234567ADAD",
}]

data = json.dumps(data)

request = call.DataTransferPayload(
    vendor_id="StarCharge",
    message_id="CarId",
    data=data,
)

It should be noted that the data is serealized, so when use call.DataTransferPayload method the data will be seralized again remaining as follows:

'"[{\\"timestamp\\": \\"2024-03-18 01:54:02.060142\\", \\"connectorId\\": 1, \\"vin\\": \\"1234567ADAD\\"}]"'

The data was double seralized, so when the central system will unserializes the data it will get a string object and not dict object.

It is important to say that some industry loaders send a json in the data transfer message, so maybe the library should handle this case.

I can do a PR with a approach if this issue is accepted.