diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0f46484ef..5ce74d413 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,8 +1,7 @@ ## Contributing -[fork]: /fork -[pr]: /compare -[style]: https://standardjs.com/ +[fork]: ../../fork +[pr]: ../../compare [code-of-conduct]: CODE_OF_CONDUCT.md Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. diff --git a/README.rst b/README.rst index 291638691..cac38aac0 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,7 @@ implementers of OCPP to no longer implement OCPP 2.0 and only use version Installation ------------ -You can either the project install from Pypi: +You can either install the project from Pypi: .. code-block:: bash @@ -71,32 +71,32 @@ code in the `Central System documentation`_. import asyncio import logging import websockets - from datetime import datetime + from datetime import datetime, timezone from ocpp.routing import on from ocpp.v201 import ChargePoint as cp from ocpp.v201 import call_result - from ocpp.v201.enums import RegistrationStatusType + from ocpp.v201.enums import Action, RegistrationStatusType logging.basicConfig(level=logging.INFO) class ChargePoint(cp): - @on('BootNotification') + @on(Action.boot_notification) async def on_boot_notification(self, charging_station, reason, **kwargs): - return call_result.BootNotificationPayload( - current_time=datetime.utcnow().isoformat(), + return call_result.BootNotification( + current_time=datetime.now(timezone.utc).isoformat(), interval=10, status=RegistrationStatusType.accepted ) - async def on_connect(websocket, path): + async def on_connect(websocket): """ For every new charge point that connects, create a ChargePoint instance and start listening for messages. """ try: - requested_protocols = websocket.request_headers[ + requested_protocols = websocket.request.headers[ 'Sec-WebSocket-Protocol'] except KeyError: logging.info("Client hasn't requested any Subprotocol. " @@ -115,7 +115,7 @@ code in the `Central System documentation`_. requested_protocols) return await websocket.close() - charge_point_id = path.strip('/') + charge_point_id = websocket.request.path.strip('/') cp = ChargePoint(charge_point_id, websocket) await cp.start() @@ -140,13 +140,13 @@ Charging Station / Charge point .. code-block:: python import asyncio - - from ocpp.v201.enums import RegistrationStatusType import logging + import websockets from ocpp.v201 import call from ocpp.v201 import ChargePoint as cp + from ocpp.v201.enums import RegistrationStatusType logging.basicConfig(level=logging.INFO) @@ -154,7 +154,7 @@ Charging Station / Charge point class ChargePoint(cp): async def send_boot_notification(self): - request = call.BootNotificationPayload( + request = call.BootNotification( charging_station={ 'model': 'Wallbox XYZ', 'vendor_name': 'anewone' diff --git a/SUPPORT.md b/SUPPORT.md index 72b64a6c6..829d28de5 100644 --- a/SUPPORT.md +++ b/SUPPORT.md @@ -1,3 +1,7 @@ +[coc]: CODE_OF_CONDUCT.md +[chat]: ../../discussions +[contributing]: CONTRIBUTING.md + # Support This article explains where to get help with this OCPP project. @@ -24,11 +28,11 @@ Here are some tips: * What problem are you encountering and what steps have you taken to try and fix it? * Is there a concept you don’t understand? -* Provide sample code, such as a [CodeSandbox][cs] or video, if possible +* Provide sample code, such as a CodeSandbox or video, if possible * Screenshots can help, but if there’s important text such as code or error messages in them, please also provide those as text * The more time you put into asking your question, the better we can help you ## Contributions -See [`contributing.md`][contributing] on how to contribute. +See [`CONTRIBUTING.md`][contributing] on how to contribute. diff --git a/docs/source/central_system.rst b/docs/source/central_system.rst index c1a80af5a..c4e726029 100644 --- a/docs/source/central_system.rst +++ b/docs/source/central_system.rst @@ -22,9 +22,9 @@ and that prints 'Charge point connected' for every new websocket connection made import websockets - async def on_connect(websocket, path): + async def on_connect(websocket): await websocket.send('Connection made successfully.') - print(f'Charge point {path} connected') + print(f'Charge point {websocket.request.path} connected') async def main(): @@ -46,9 +46,10 @@ There are two things that requires a few words of explanation. * The `on_connect()` handler that is passed as a first argument to `websockets.serve()`_. This is the handler that is executed on every new connection. - The handler is passed two arguments: an instance of `websockets.server.WebSocketServerProtocol`_ - and the request URI. The request URI is used as identifier for the charge point that made the - connection. To quote a snippet from section 3.1.1 of the OCPP-J specification: + The handler is passed one argument: an instance of `websockets.asyncio.server.ServerConnection`_. + The request URI can be retrieved from the ServerConnections request attribute and + is used as identifier for the charge point that made the connection. + To quote a snippet from section 3.1.1 of the OCPP-J specification: *"The charge point's connection URL contains the charge point identity so that the Central System knows which charge point a Websocket connection @@ -61,7 +62,7 @@ There are two things that requires a few words of explanation. supports OCPP 1.6. After you've started the server you can connect a client to it by using the `websockets` interactive -`client`_: +`client`: .. code-block:: shell @@ -78,9 +79,9 @@ OCPP compliant handler .. note:: This document describes how to create an central system that supports OCPP - 1.6. The ocpp Python package has support for OCPP 2.0 as well. This + 1.6. The ocpp Python package has support for OCPP 2.0.1 as well. This documentation will be updated soon to reflect that. In the mean time please - consult the `examples/`_ to learn how to create an OCPP 2.0 central system. + consult the `examples/`_ to learn how to create an OCPP 2.0.1 central system. The websocket server created above is not very useful and only sends a non-OCPP compliant message. @@ -88,7 +89,7 @@ Remove the `on_connect()` handler from the code above and replace it by the foll .. code-block:: python - from datetime import datetime + from datetime import datetime, timezone from ocpp.routing import on from ocpp.v16 import ChargePoint as cp @@ -99,19 +100,19 @@ Remove the `on_connect()` handler from the code above and replace it by the foll class MyChargePoint(cp): @on(Action.boot_notification) async def on_boot_notification(self, charge_point_vendor, charge_point_model, **kwargs): - return call_result.BootNotificationPayload( - current_time=datetime.utcnow().isoformat(), + return call_result.BootNotification( + current_time=datetime.now(timezone.utc).isoformat(), interval=10, status=RegistrationStatus.accepted ) - async def on_connect(websocket, path): + async def on_connect(websocket): """ For every new charge point that connects, create a ChargePoint instance and start listening for messages. """ - charge_point_id = path.strip('/') + charge_point_id = websocket.request.path.strip('/') cp = MyChargePoint(charge_point_id, websocket) await cp.start() @@ -135,7 +136,7 @@ required arguments, 'chargePointModel' and 'chargePointVendor', as well as an se arguments. The handler reflects this by having two required arguments, `charge_point_vendor` and `charge_point_model`. The handler uses `**kwargs` for the optional arguments. -The handler returns an instance of `ocpp.v16.call_result.BootNotificationPayload`_. This object +The handler returns an instance of `ocpp.v16.call_result.BootNotification`_. This object is used to create a response that is send back to the client. .. note:: @@ -168,13 +169,12 @@ Congratulations! You've created a central system. You can find the source code of the central system created in this document in the `examples/`_ directory. -.. _client: https://websockets.readthedocs.io/en/stable/intro.html#one-more-thing .. _examples/: https://github.com/mobilityhouse/ocpp/blob/master/examples -.. _ocpp.v16.call_result.BootNotificationPayload: https://github.com/mobilityhouse/ocpp/blob/3b92c2c53453dd6511a202e1dc1b9aa1a236389e/ocpp/v16/call_result.py#L28 -.. _ocpp.v16.ChargePoint: https://github.com/mobilityhouse/ocpp/blob/master/ocpp/v16/charge_point.py#L80 -.. _start(): https://github.com/mobilityhouse/ocpp/blob/3b92c2c53453dd6511a202e1dc1b9aa1a236389e/ocpp/v16/charge_point.py#L125 +.. _ocpp.v16.call_result.BootNotification: https://github.com/mobilityhouse/ocpp/blob/master/ocpp/v16/call_result.py#L30 +.. _ocpp.v16.ChargePoint: https://github.com/mobilityhouse/ocpp/blob/master/ocpp/v16/__init__.py#L5 +.. _start(): https://github.com/mobilityhouse/ocpp/blob/master/ocpp/charge_point.py#L244 .. _websockets: https://websockets.readthedocs.io/en/stable/ -.. _websockets.serve(): https://websockets.readthedocs.io/en/stable/api.html#module-websockets.server -.. _websockets.server.WebsocketServerProtocol: https://websockets.readthedocs.io/en/stable/api.html#websockets.server.WebSocketServerProtocol -.. _@on(): https://github.com/mobilityhouse/ocpp/blob/3b92c2c53453dd6511a202e1dc1b9aa1a236389e/ocpp/routing.py#L4 -.. _@after(): https://github.com/mobilityhouse/ocpp/blob/3b92c2c53453dd6511a202e1dc1b9aa1a236389e/ocpp/routing.py#L34 +.. _websockets.serve(): https://websockets.readthedocs.io/en/stable/reference/asyncio/server.html#websockets.asyncio.server.serve +.. _websockets.asyncio.server.ServerConnection: https://websockets.readthedocs.io/en/stable/reference/asyncio/server.html#websockets.asyncio.server.ServerConnection +.. _@on(): https://github.com/mobilityhouse/ocpp/blob/master/ocpp/routing.py#L6 +.. _@after(): https://github.com/mobilityhouse/ocpp/blob/master/ocpp/routing.py#L59