server.rst 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. .. _server:
  2. ======
  3. Server
  4. ======
  5. The page contains all information about pyOpenADR Server API.
  6. .. _server_registration:
  7. Registration
  8. ============
  9. If a client (VEN) wants to register for the first time, it will go through a Registration procedure.
  10. The client will send a :ref:`oadrQueryRegistration` message. The server will respond with a :ref:`oadrCreatedPartyRegistration` message containing a list of its capabilities, notable the implemented OpenADR protocol versions and the available Transport Mechanisms (HTTP and/or XMPP).
  11. The client will then usually send a :ref:`oadrCreatePartyRegistration` message, in which it registers to a specific OpenADR version and Transport Method. The server must then decide what it wants to do with this registration.
  12. In the case that the registration is accepted, the VTN will generate a RegistrationID for this VEN and respond with a :ref:`oadrCreatedPartyRegistration` message.
  13. In your application, when a VEN sends a :ref:`oadrCreatePartyRegistration` request, it will call your ``on_register_party`` handler. This handler must somehow look up what to do with this request, and respond with a ``registration_id``.
  14. Example implementation:
  15. .. code-block:: python3
  16. from pyopenadr.utils import generate_id
  17. async def on_create_party_registration(payload):
  18. ven_id = payload['ven_id']
  19. # Check whether or not this VEN is allowed to register
  20. result = await database.query("""SELECT COUNT(*)
  21. FROM vens
  22. WHERE ven_id = ?""",
  23. (payload['ven_id'],))
  24. if result == 1:
  25. # Generate an ID for this registration
  26. registration_id = generate_id()
  27. # Store the registration in a database (pseudo-code)
  28. await database.query("""UPDATE vens
  29. SET registration_id = ?
  30. WHERE ven_id = ?""",
  31. (registration_id, ven_id))
  32. # Return the registration ID.
  33. # This will be put into the correct form by the OpenADRServer.
  34. return registration_id
  35. .. _server_events:
  36. Events
  37. ======
  38. The server (VTN) is expected to know when it needs to inform the clients (VENs) of certain events that they must respond to. This could be a predicted shortage or overage of available power in a certain electricity grid area, for example.
  39. The VTN must determine when VENs are relevant and which Events to send to them. The next time the VEN polls for new messages (using a :ref:`oadrPoll` or :ref:`oadrRequestEvent` message), it will send the Event in a :ref:`oadrDistributeEvent` message to the client. The client will then evaluate whether or not it indends to comply with the request, and respond with an :ref:`oadrCreatedEvent` message containing an optStatus of ``'optIn'`` or ``'optOut'``.
  40. In your application, the creation of Events is completely up to you. PyOpenADR will only call your ``on_poll`` handler with a ``ven_id``. This handler must be able to either retrieve the next event for this VEN out of some storage or queue, or make up the Event in real time.
  41. .. _server_reports:
  42. Reports
  43. =======