Aucune description

charge_point.py 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import asyncio
  2. import logging
  3. try:
  4. import websockets
  5. except ModuleNotFoundError:
  6. print("This example relies on the 'websockets' package.")
  7. print("Please install it by running: ")
  8. print()
  9. print(" $ pip install websockets")
  10. import sys
  11. sys.exit(1)
  12. from ocpp.v16 import ChargePoint as cp
  13. from ocpp.v16 import call
  14. from ocpp.v16.enums import RegistrationStatus
  15. logging.basicConfig(level=logging.INFO)
  16. class ChargePoint(cp):
  17. async def send_boot_notification(self):
  18. request = call.BootNotificationPayload(
  19. charge_point_model="Optimus", charge_point_vendor="The Mobility House"
  20. )
  21. response = await self.call(request)
  22. if response.status == RegistrationStatus.accepted:
  23. print("Connected to central system.")
  24. async def main():
  25. async with websockets.connect(
  26. "ws://localhost:9000/CP_1", subprotocols=["ocpp1.6"]
  27. ) as ws:
  28. cp = ChargePoint("CP_1", ws)
  29. await asyncio.gather(cp.start(), cp.send_boot_notification())
  30. if __name__ == "__main__":
  31. # asyncio.run() is used when running this example with Python >= 3.7v
  32. asyncio.run(main())