pan class="time-since" title="Sat, 16 Sep 2023 07:03:00 UTC">2 年 前 tailwind-color-palette 30f7226d9a first commit 2 年 前 tailwindcss 30f7226d9a first commit 2 年 前 thenify 30f7226d9a first commit 2 年 前 thenify-all 30f7226d9a first commit 2 年 前 to-regex-range 30f7226d9a first commit 2 年 前 tr46 30f7226d9a first commit 2 年 前 ts-interface-checker 30f7226d9a first commit 2 年 前 uglify-js 30f7226d9a first commit 2 年 前 underscore 30f7226d9a first commit 2 年 前 upper-case 30f7226d9a first commit 2 年 前 util-deprecate 30f7226d9a first commit 2 年 前 valid-data-url 30f7226d9a first commit 2 年 前 web-resource-inliner 30f7226d9a first commit 2 年 前 webidl-conversions 30f7226d9a first commit 2 年 前 whatwg-url 30f7226d9a first commit 2 年 前 wrap-ansi 30f7226d9a first commit 2 年 前 wrappy 30f7226d9a first commit 2 年 前 y18n 30f7226d9a first commit 2 年 前 yallist 30f7226d9a first commit 2 年 前 yaml 30f7226d9a first commit 2 年 前 yargs 30f7226d9a first commit 2 年 前 yargs-parser 30f7226d9a first commit 2 年 前 .yarn-integrity 30f7226d9a first commit 2 年 前 tum/mycp - Gogs: Simplico Git Service

Nessuna descrizione

charge_point.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.v201 import ChargePoint as cp
  13. from ocpp.v201 import call
  14. logging.basicConfig(level=logging.INFO)
  15. class ChargePoint(cp):
  16. async def send_heartbeat(self, interval):
  17. request = call.HeartbeatPayload()
  18. while True:
  19. await self.call(request)
  20. await asyncio.sleep(interval)
  21. async def send_boot_notification(self):
  22. request = call.BootNotificationPayload(
  23. charging_station={"model": "Wallbox XYZ", "vendor_name": "anewone"},
  24. reason="PowerUp",
  25. )
  26. response = await self.call(request)
  27. if response.status == "Accepted":
  28. print("Connected to central system.")
  29. await self.send_heartbeat(response.interval)
  30. async def main():
  31. async with websockets.connect(
  32. "ws://localhost:9000/CP_1", subprotocols=["ocpp2.0.1"]
  33. ) as ws:
  34. charge_point = ChargePoint("CP_1", ws)
  35. await asyncio.gather(
  36. charge_point.start(), charge_point.send_boot_notification()
  37. )
  38. if __name__ == "__main__":
  39. # asyncio.run() is used when running this example with Python >= 3.7v
  40. asyncio.run(main())