ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

asynchronous tasks one after another

Open stStavropoulos opened this issue 3 years ago • 4 comments

Hello!

I implemented a charging point and a CSMS based on the examples and comments I found, and now, I want to implement a full charging scenario for smart charging. image image

The CSMS: image

The script: image

So my problem is that after I receive the answer from the CSMS for the authorization, I want the coroutine to be terminated and go to the next step which is the start transaction. When the start transaction receives an answer to go to the remote start of charging and goes like this. But what happens is that is stuck there and waiting. Do you have any idea what should I do?

Thanks!

stStavropoulos avatar Aug 30 '22 15:08 stStavropoulos

I want the coroutine to be terminated

Which one?

after I receive the answer from the CSMS for the authorization, [...] and go to the next step which is the start transaction.

Seems like you might need the @after() decorator.

OrangeTux avatar Aug 31 '22 07:08 OrangeTux

Maybe I wasn't very clear. Sorry about that. image I meant this part here, the asyncio.gather should collect an answer from the csms. Here is what CSMS does:

image

And here is what the charging point sees: image

After I receive this answer, I want to store it and run another coroutinee for the remote start and stop, but the asyncio.gather is stuck there after the answer.

Thanks for your time!

stStavropoulos avatar Aug 31 '22 09:08 stStavropoulos

Thanks for clarifying. It seems that you're question is more related to asyncio, than this library. I suggest to take a look at the documentation of asyncio.gather() and asyncio.wait().

The docs of asyncio.gather() state:

If all awaitables are completed successfully, the result is an aggregate list of returned values. The order of result values corresponds to the order of awaitables in aws.

asyncio.wait() seems what you need. Quoting the docs:

Run awaitable objects in the aws iterable concurrently and block until the condition specified by return_when.

OrangeTux avatar Aug 31 '22 09:08 OrangeTux

The use of wait never receives something:

image

It also didn't work with other conditions, only gather receives the answer fromt he CSMS.

Thanks again!

stStavropoulos avatar Aug 31 '22 10:08 stStavropoulos