Series: ocpp
python
54 lines
· Updated 2025-10-10
charge_point.py
ocpp/homework/ocpp_many/examples/v201/charge_point.py
import asyncio
import logging
try:
import websockets
except ModuleNotFoundError:
print("This example relies on the 'websockets' package.")
print("Please install it by running: ")
print()
print(" $ pip install websockets")
import sys
sys.exit(1)
from ocpp.v201 import ChargePoint as cp
from ocpp.v201 import call
logging.basicConfig(level=logging.INFO)
class ChargePoint(cp):
async def send_heartbeat(self, interval):
request = call.Heartbeat()
while True:
await self.call(request)
await asyncio.sleep(interval)
async def send_boot_notification(self):
request = call.BootNotification(
charging_station={"model": "Wallbox XYZ", "vendor_name": "anewone"},
reason="PowerUp",
)
response = await self.call(request)
if response.status == "Accepted":
print("Connected to central system.")
await self.send_heartbeat(response.interval)
async def main():
async with websockets.connect(
"ws://localhost:9000/CP_1", subprotocols=["ocpp2.0.1"]
) as ws:
charge_point = ChargePoint("CP_1", ws)
await asyncio.gather(
charge_point.start(), charge_point.send_boot_notification()
)
if __name__ == "__main__":
# asyncio.run() is used when running this example with Python >= 3.7v
asyncio.run(main())
Related articles
ocpp
python
Updated 2026-02-03
central_system.py
central_system.py — python source code from the ocpp learning materials (ocpp/homework/central_system.py).
Read article →
ocpp
python
Updated 2026-02-03
charge_point.py
charge_point.py — python source code from the ocpp learning materials (ocpp/homework/ocpp/charge_point.py).
Read article →
ocpp
python
Updated 2026-02-03
exceptions.py
exceptions.py — python source code from the ocpp learning materials (ocpp/homework/ocpp/exceptions.py).
Read article →
ocpp
python
Updated 2026-02-03
messages.py
messages.py — python source code from the ocpp learning materials (ocpp/homework/ocpp/messages.py).
Read article →
ocpp
python
Updated 2026-02-03
routing.py
routing.py — python source code from the ocpp learning materials (ocpp/homework/ocpp/routing.py).
Read article →
ocpp
python
Updated 2026-02-03
__init__.py
__init__.py — python source code from the ocpp learning materials (ocpp/homework/ocpp/v16/__init__.py).
Read article →