ocpp
ocpp copied to clipboard
How can I handle schema exception in Central System application?
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?
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):
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.
As this is a duplicate, I'll close it - reference https://github.com/mobilityhouse/ocpp/issues/102