examples.rst 975 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. .. _examples:
  2. =====================
  3. Ready-to-Run Examples
  4. =====================
  5. This page contains examples for OpenLEADR:
  6. .. _client_example:
  7. Client Example
  8. ==============
  9. This example sets up a minimal OpenADR Client (Virtual End Node):
  10. .. code-block:: python3
  11. from openleadr import OpenADRClient
  12. import asyncio
  13. async def main():
  14. client = OpenADRClient(ven_name="Device001", vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
  15. client.on_event = handle_event
  16. await client.run()
  17. async def handle_event(event):
  18. """
  19. This coroutine will be called
  20. whenever there is an event to be handled.
  21. """
  22. print("There is an event!")
  23. print(event)
  24. return 'optIn'
  25. loop = asyncio.get_event_loop()
  26. loop.create_task(main())
  27. loop.run_forever()
  28. .. _server_example:
  29. Server Example
  30. ==============
  31. .. _server_with_gui_example:
  32. Server with GUI Example
  33. =======================