@@ -14,24 +14,10 @@ Python package implementing the JSON version of the Open Charge Point Protocol
1414(OCPP). Currently OCPP 1.6 (errata v4), OCPP 2.0.1 (Edition 2 FINAL, 2022-12-15 and Edition 3 errata 2024-11)
1515are supported.
1616
17- You can find the documentation on `rtd `_.
18-
19- The purpose of this library is to provide the building blocks to construct a
20- charging station/charge point and/or charging station management system
21- (CSMS)/central system. The library does not provide a completed solution, as any
22- implementation is specific for its intended use. The documents in this library
23- should be inspected, as these documents provided guidance on how best to
24- build a complete solution.
25-
26- Note: "OCPP 2.0.1 contains fixes for all the known issues, to date, not only
27- the fixes to the messages. This version replaces OCPP 2.0. OCA advises
28- implementers of OCPP to no longer implement OCPP 2.0 and only use version
29- 2.0.1 going forward."
30-
3117Installation
3218------------
3319
34- You can either the project install from Pypi:
20+ You can either install the project from Pypi:
3521
3622.. code-block :: bash
3723
@@ -43,165 +29,26 @@ Or clone the project and install it manually using:
4329
4430 $ pip install .
4531
46- Quick start
47- -----------
48-
49- Below you can find examples on how to create a simple OCPP 1.6 or 2.0.1 Central
50- System/CSMS as well as the respective OCPP 1.6 or 2.0.1
51- Charging Station/Charge Point.
52-
53- .. note ::
54-
55- To run these examples the dependency websockets _ is required! Install it by running:
56-
57- .. code-block :: bash
58-
59- $ pip install websockets
60-
61- Charging Station Management System (CSMS) / Central System
62- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
63-
64- The code snippet below creates a simple OCPP 2.0.1 CSMS which
65- is able to handle BootNotification calls. You can find a detailed explanation of the
66- code in the `Central System documentation `_.
67-
68-
69- .. code-block :: python
70-
71- import asyncio
72- import logging
73- import websockets
74- from datetime import datetime
75-
76- from ocpp.routing import on
77- from ocpp.v201 import ChargePoint as cp
78- from ocpp.v201 import call_result
79- from ocpp.v201.enums import RegistrationStatusType
80-
81- logging.basicConfig(level = logging.INFO )
82-
83-
84- class ChargePoint (cp ):
85- @on (' BootNotification' )
86- async def on_boot_notification (self , charging_station , reason , ** kwargs ):
87- return call_result.BootNotificationPayload(
88- current_time = datetime.utcnow().isoformat(),
89- interval = 10 ,
90- status = RegistrationStatusType.accepted
91- )
92-
93-
94- async def on_connect (websocket , path ):
95- """ For every new charge point that connects, create a ChargePoint
96- instance and start listening for messages.
97- """
98- try :
99- requested_protocols = websocket.request_headers[
100- ' Sec-WebSocket-Protocol' ]
101- except KeyError :
102- logging.info(" Client hasn't requested any Subprotocol. "
103- " Closing Connection" )
104- return await websocket.close()
105-
106- if websocket.subprotocol:
107- logging.info(" Protocols Matched: %s " , websocket.subprotocol)
108- else :
109- # In the websockets lib if no subprotocols are supported by the
110- # client and the server, it proceeds without a subprotocol,
111- # so we have to manually close the connection.
112- logging.warning(' Protocols Mismatched | Expected Subprotocols: %s ,'
113- ' but client supports %s | Closing connection' ,
114- websocket.available_subprotocols,
115- requested_protocols)
116- return await websocket.close()
117-
118- charge_point_id = path.strip(' /' )
119- cp = ChargePoint(charge_point_id, websocket)
32+ Documentation
33+ -------------
12034
121- await cp.start()
35+ For detailed usage instructions, examples and API references, visit the full documentation: ` rtd `_.
12236
37+ SECURITY
38+ --------
12339
124- async def main ():
125- server = await websockets.serve(
126- on_connect,
127- ' 0.0.0.0' ,
128- 9000 ,
129- subprotocols = [' ocpp2.0.1' ]
130- )
131- logging.info(" WebSocket Server Started" )
132- await server.wait_closed()
40+ You can find the security policy of this project at `SECURITY.md `_.
13341
134- if __name__ == ' __main__' :
135- asyncio.run(main())
136-
137- Charging Station / Charge point
138- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
139-
140- .. code-block :: python
141-
142- import asyncio
143-
144- from ocpp.v201.enums import RegistrationStatusType
145- import logging
146- import websockets
147-
148- from ocpp.v201 import call
149- from ocpp.v201 import ChargePoint as cp
150-
151- logging.basicConfig(level = logging.INFO )
152-
153-
154- class ChargePoint (cp ):
155-
156- async def send_boot_notification (self ):
157- request = call.BootNotificationPayload(
158- charging_station = {
159- ' model' : ' Wallbox XYZ' ,
160- ' vendor_name' : ' anewone'
161- },
162- reason = " PowerUp"
163- )
164- response = await self .call(request)
165-
166- if response.status == RegistrationStatusType.accepted:
167- print (" Connected to central system." )
168-
169-
170- async def main ():
171- async with websockets.connect(
172- ' ws://localhost:9000/CP_1' ,
173- subprotocols = [' ocpp2.0.1' ]
174- ) as ws:
175- cp = ChargePoint(' CP_1' , ws)
176-
177- await asyncio.gather(cp.start(), cp.send_boot_notification())
178-
179-
180- if __name__ == ' __main__' :
181- asyncio.run(main())
182-
183- Debugging
184- ---------
185-
186- Python's default log level is `logging.WARNING `. As result most of the logs
187- generated by this package are discarded. To see the log output of this package
188- lower the log level to `logging.DEBUG `.
189-
190- .. code-block :: python
191-
192- import logging
193- logging.basicConfig(level = logging.DEBUG )
42+ CONTRIBUTING
43+ ------------
19444
195- However, this approach defines the log level for the complete logging system.
196- In other words: the log level of all dependencies is set to `logging.DEBUG `.
45+ If you want to contribute to this project, please read the `CONTRIBUTING.md `_ file.
19746
198- To lower the logs for this package only use the following code:
47+ CODE OF CONDUCT
48+ ---------------
19949
200- .. code-block :: python
50+ You can find the code of conduct of this project at ` CODE_OF_CONDUCT.md `_.
20151
202- import logging
203- logging.getLogger(' ocpp' ).setLevel(level = logging.DEBUG )
204- logging.getLogger(' ocpp' ).addHandler(logging.StreamHandler())
20552
20653Aknowledgements
20754---------------
@@ -231,3 +78,6 @@ Attribution-NoDerivatives 4.0 International Public License.
23178.. _Chad Meadowcroft : https://github.com/mdwcrft
23279.. _Mohit Jain : https://github.com/jainmohit2001
23380.. _Patrick Roelke : https://github.com/proelke
81+ .. _SECURITY.md : https://github.com/mobilityhouse/ocpp/blob/master/SECURITY.md
82+ .. _CONTRIBUTING.md : https://github.com/mobilityhouse/ocpp/blob/master/CONTRIBUTING.md
83+ .. _CODE_OF_CONDUCT.md : https://github.com/mobilityhouse/ocpp/blob/master/CODE_OF_CONDUCT.md
0 commit comments