openleadr-python icon indicating copy to clipboard operation
openleadr-python copied to clipboard

How the DSRSP(the VTN) handles the oadrPoll request?

Open xingyiditongxue opened this issue 10 months ago • 2 comments

In the source code, we could see that the VTN responds to an oadrPoll payload with oadrDistributeEvent or oadrResponse. This is in <<poll_service.py>>.

However, on the client(the VEN) side, the expected responses of a poll action may be one of the following: oadrResponse, oadrRequestReregistration, oadrDistributeEvent, oadrUpdateReport, oadrCreateReport, etc, etc. How could we initiate all these payloads from the VTN side? It looks like it isn't implemented at all in OpenleADR?

xingyiditongxue avatar Oct 16 '23 14:10 xingyiditongxue

Thank you a lot in advance! For any kinds of instruction!

xingyiditongxue avatar Oct 16 '23 14:10 xingyiditongxue

In OpenLEADR, the following is supported. If you use the default internal polling handler, the following is supported:

  • oadDistributeEvent is returned after you add an event using the server.add_event method. This takes care of all the details of the event status and allows you to register a callback for when the client responds to the event. This is the most used and most convenient way to distribute events to the VENs.
  • oadrResponse: this is automatically returned if no new Events are available. It is basically an empty message.

If you want to deliver the other messages, you can disable the internal polling mechanism, and implement your own on_poll handler like this:


# vtn.py

from openleadr import OpenADRServer


def my_custom_polling_handler(ven_id):
    """
    Called when the ven with 'ven_id' does a Poll
    """
    
    # You should determine what message you want to send to the client here. For example, look it up in a database or some dictionary or datastore that you have.

    # For example:
    message_type = "oadrRequestReregistration"
    message_payload = {'ven_id': ven_id}

    # Or, to create a report:
    message_type = "oadrCreateReport"
    message_payload = {
        "request_id": "request123", 
        "report_requests": [
            {
                "report_request_id": "reportrequest123", 
                "report_specifier": {
                    "report_specifier_id": "reportspec123", 
                    "granularity": timedelta(minutes=15), 
                    "specifier_payloads": [
                        {"r_id": "rid123", "reading_type": "Direct Read"}
                    ]
                }
            ]
        }

    return message_type, message_payload

# Create a new server and set the polling method to external
server = OpenADRServer(...,)

# Add our own polling handler. This should return the correct message for the VEN.
server.add_handler('on_poll', my_custom_polling_handler)

You'll be 'on your own' to handle the responses to these, but it is absolutely supported. Let me know if this helps!

stan-janssen avatar Oct 18 '23 17:10 stan-janssen