ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

How handling of sending to consecutive messages from central system

Open scotty1269 opened this issue 4 years ago • 12 comments
trafficstars

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')".

scotty1269 avatar Apr 21 '21 08:04 scotty1269

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

maurerle avatar Apr 21 '21 11:04 maurerle

What about the @after() decorator? https://github.com/mobilityhouse/ocpp/blob/fdfb5b1b33665dad13708b47226f48b56ee6b438/ocpp/routing.py#L58-L80

OrangeTux avatar Apr 21 '21 16:04 OrangeTux

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..

tropxy avatar Apr 22 '21 10:04 tropxy

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.

scotty1269 avatar Apr 22 '21 15:04 scotty1269

Can you post code snippets and/or debug logs that show what you've tried?

OrangeTux avatar Apr 23 '21 07:04 OrangeTux

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"}]`

scotty1269 avatar Apr 24 '21 09:04 scotty1269

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?

OrangeTux avatar Apr 24 '21 10:04 OrangeTux

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?

scotty1269 avatar Apr 25 '21 12:04 scotty1269

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(...))

OrangeTux avatar Apr 26 '21 09:04 OrangeTux

@scotty1269 hey, is your issue being solved?

laysauchoa avatar Jun 18 '21 20:06 laysauchoa

@laysauchoa thank you for asking! I found now a solution and it's working. This issue can be closed.

scotty1269 avatar Jun 23 '21 07:06 scotty1269

Hi @scotty1269 , do you mind sharing your finding as support for helping others with similar questions?

laysauchoa avatar Jun 23 '21 07:06 laysauchoa