Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
24 changes: 12 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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. "
Expand All @@ -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()
Expand All @@ -140,21 +140,21 @@ 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)


class ChargePoint(cp):

async def send_boot_notification(self):
request = call.BootNotificationPayload(
request = call.BootNotification(
charging_station={
'model': 'Wallbox XYZ',
'vendor_name': 'anewone'
Expand Down
8 changes: 6 additions & 2 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.
44 changes: 22 additions & 22 deletions docs/source/central_system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -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
Expand All @@ -78,17 +79,17 @@ 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.

Remove the `on_connect()` handler from the code above and replace it by the following snippet.

.. code-block:: python

from datetime import datetime
from datetime import datetime, timezone

from ocpp.routing import on
from ocpp.v16 import ChargePoint as cp
Expand All @@ -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()
Expand All @@ -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::
Expand Down Expand Up @@ -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