Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
xingyiditongxue opened this issue Oct 16, 2023 · 2 comments
Open

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

xingyiditongxue opened this issue Oct 16, 2023 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@xingyiditongxue
Copy link

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
Copy link
Author

xingyiditongxue commented Oct 16, 2023

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

@stan-janssen
Copy link
Member

stan-janssen commented Oct 18, 2023

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!

@axmsoftware axmsoftware added the documentation Improvements or additions to documentation label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants