ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

How can I handle schema exception in Central System application?

Open Huron opened this issue 4 years ago • 2 comments

I go this DataTransfer message from one of my stations

<Call - unique_id=425, action=DataTransfer, payload={'vendorId': 'Growatt', 'messageId': 'currentrecord', 'data': {'id': 166, 'connectorId': 1, 'chargemode': 1, 'plugtime': '2020-07-31 12:33:53', 'unplugtime': '2020-07-31 12:34:04', 'starttime': '2020-07-31 12:33:53', 'endtime': '2020-07-31 12:34:04', 'costenergy': 0, 'costmoney': 0, 'transactionId': 142}}>

After that, the thread of the charge point connection is terminated.

ValidationError
Payload '{'vendorId': 'Growatt', 'messageId': 'currentrecord', 'data': {'id': 166, 'connectorId': 1, 'chargemode': 1, 'plugtime': '2020-07-31 12:33:53', 'unplugtime': '2020-07-31 12:34:04', 'starttime': '2020-07-31 12:33:53', 'endtime': '2020-07-31 12:34:04', 'costenergy': 0, 'costmoney': 0, 'transactionId': 142}} for action 'DataTransfer' is not valid: {'id': 166, 'connectorId': 1, 'chargemode': 1, 'plugtime': '2020-07-31 12:33:53', 'unplugtime': '2020-07-31 12:34:04', 'starttime': '2020-07-31 12:33:53'...

How can I change this exception and save the connection online?

Huron avatar Aug 03 '20 07:08 Huron

There is no mechanism of hooks (yet) implemented. So what's left is to override ocpp.ChargePoint.route_message() and try to ocpp.messages.unpack() first. If that succeeds you can call route_message() of the super class.

async def route_message(self, raw_msg):
    try:
         ocpp.messages.unpack(raw_msg)
     except ocpp.exceptions.ValidationError:
         # do you thing
    else:
        super().route_message(raw_msg):

OrangeTux avatar Aug 04 '20 07:08 OrangeTux

Because of your ticket I realized that this library can be improved and return CallErrors if a it receives a Call that fails to unpack. I've created a ticket #102 for that.

OrangeTux avatar Aug 04 '20 07:08 OrangeTux

As this is a duplicate, I'll close it - reference https://github.com/mobilityhouse/ocpp/issues/102

Jared-Newell-Mobility avatar Dec 18 '23 09:12 Jared-Newell-Mobility