ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

OCPP implementation with Quart

Open betovaca opened this issue 3 years ago • 1 comments

Hi, I'm implementing OCPP 2.0.1 with Quart API.

On server side, when a client is connected I create a global ChargePoint object so I can use it in other functions like:

....
//Creation of the global object charge_point in a class called WebsocketThread so I can run Quart and Websockets at the same time
...
@app.route('/')
async def home():
    await asyncio.create_task(charge_point.send_reserve_now_request(args...))
    return await render_template('index.html')

I use the same logic for a virtual charge point client :

...
//Creation of the global object charge_point in a class called WebsocketThread so I can run Quart and Websockets at the same time
...
@app.route('/')
async def home():
    await asyncio.create_task(charge_point.send_boot_notification(args...))
    return await render_template('index.html')

But when I run the code, I get the same error again and again:

Python RuntimeError: <Queue at 0x199e577e770 maxsize=0 tasks=2> is bound to a different event loop

And I searched everywhere for a queue issue bound to a different event loop but it couldn't find anything. It's an error from the Mixins file from asyncio apparently.

I also tried to do:

try:
    await asyncio.create_task(charge_point.send_boot_notification(args...))
except Exception:
    pass

And now I don't get any errors but I get a message from OCPP "Ignoring reply" to the last request and the server blocks itself.

Does anyone has an idea to solve this bound to event loops?

betovaca avatar Mar 16 '22 10:03 betovaca

A few years ago I created a quick demo using this library and quart, maybe that provides an answer? https://github.com/OrangeTux/CS/blob/master/web/init.py

OrangeTux avatar Apr 01 '22 13:04 OrangeTux