mobilityhouse / ocpp

Python implementation of the Open Charge Point Protocol (OCPP).
MIT License
791 stars 315 forks source link

Use this package together with Flask #20

Closed id4github closed 5 years ago

id4github commented 5 years ago

I have developed OCPP client and server with this awesome library. I wanted to add GUI to the client and server. I intend to use React as frontend and Flask as backend for the application. How to integrate OCPP python client with Flask framework. As the OCPP has its event loop running continuously blocking the flask code. Please help. git_up

OrangeTux commented 5 years ago

Thanks for your compliment.

Unfortunately Flask and this package don't mix very well because Flask is sync and this package is async.

But I experimented a bit with using this package together with Quart. Quart is a async web framework with a very similar API to Flask.

There is some very ugly code over on my personal profile. Note that it probably doesn't work anymore with the current release of the ocpp package, but I think you can learn from the approach.

tropxy commented 5 years ago

Hey @id4github thanks for your interest. As Auke said, flask doesnt blend so well, but maybe aiohttp can be an option. They have also an api that can mimic flask operations... maybe you can check it out: https://docs.aiohttp.org/en/stable/faq.html

id4github commented 5 years ago

Thanks for the quick reply. I will try these options(Quart , aiohttp).

OrangeTux commented 5 years ago

Great! I will close this issue for now. Feel free to reopen this one or create a new issue if you have questions.

OrangeTux commented 4 years ago

For people landing on this question. I've created a small example of an CSMS integrated with an HTTP API using aiohttp. The code can be found in this comment,

bosscoekku commented 3 years ago

For people landing on this question. I've created a small example of an CSMS integrated with an HTTP API using aiohttp. The code can be found in this comment,

Could you please share the aiohttp version? because I have to try to refer to your code but it not working.

OrangeTux commented 3 years ago

The aiohttp version is shared in the comment I linked in my previous post.