ocpp
ocpp copied to clipboard
How handling of sending to consecutive messages from central system
In scneario "K16 - Optimized charging with scheduling to the CSMS" it is necessarry to send two consecutive messages from central system.
When getting NotifyEVChargingNeedsRequest, CSMS has to send NotifyEVChargingNeedsResponse and then NotifyCentralChargingNeedsRequest.
How could this be handled with e.g. @on('NotifyEVChargingNeeds')? In the examples there is only one return value e.g. in "@on('Heartbeat')".
From where did you find the Scenario K16? In the OCPP 2.0.1 Specs its "K16 - Renegotiation initiated by CSMS" and NotifyCentralChargingNeedsRequest does not exist?
Anyway you would schedule the new NotifyCentralChargingNeedsRequest with for example asyncio loop.call_soon and then send the response directly. Or you could use any other Background-Job mechanism
What about the @after() decorator? https://github.com/mobilityhouse/ocpp/blob/fdfb5b1b33665dad13708b47226f48b56ee6b438/ocpp/routing.py#L58-L80
What about the
@after()decorator?https://github.com/mobilityhouse/ocpp/blob/fdfb5b1b33665dad13708b47226f48b56ee6b438/ocpp/routing.py#L58-L80
Side note: we have to improve our examples to include the after decorator. As with other libs that I have used, is not until I dive into the source code that I found new useful functionalities which I wouldnt know about just sticking to the examples and I think that is not the right way..
Thank you all for you support! Unfortunately I didn't manage to get the after decorator to work. A real example within the ..\examples\v201\central_system.py would help.
Can you post code snippets and/or debug logs that show what you've tried?
I tried to send two messages in a row with this construction, but only the first one is sent.
@on('NotifyEVChargingNeeds')
def on_evchargingneeds(self, charging_needs, evse_id, **kwargs):
return call_result.NotifyEVChargingNeedsPayload(
status="Accepted"
)
@after('NotifyEVChargingNeeds')
def after_evchargingneeds(self, charging_needs, evse_id, **kwargs):
return call_result.NotifyEVChargingNeedsPayload(
status="Rejected"
)
INFO:ocpp:CP_1: receive message [2,"e850e28d-a372-407e-b11e-889e0ac9642a","NotifyEVChargingNeeds",{"chargingNeeds":{"requestedEnergyTransfer":"DC"},"evseId":12345,"maxScheduleTuples":12}]
INFO:ocpp:CP_1: send [3,"e850e28d-a372-407e-b11e-889e0ac9642a",{"status":"Accepted"}]`
The @after() decorator is not meant for sending responses back the the peer. The @on() handler must be used for that
The return value of the @after() handlers is discarded.
I guess you want to send a NotifyCentralChargingNeedsRequest from the @after() handler, right?
Yes, actually I wanted to send a NotifyCentralChargingNeedsRequest (for ocpp 2.0 resp. a SetChargingProfileRequest for 2.0.1). The question is just how to send two consecutive messages?
As I said, you should use the @after() decorator for that. Something like:
@after('NotifyEVChargingNeeds')
def after_evchargingneeds(self, charging_needs, evse_id, **kwargs):
await self.call(NotifyCentralChargingNeedsRequestPayload(...))
@scotty1269 hey, is your issue being solved?
@laysauchoa thank you for asking! I found now a solution and it's working. This issue can be closed.
Hi @scotty1269 , do you mind sharing your finding as support for helping others with similar questions?