OpenLEADR/openleadr-python

Getting an Error at VEN SIDE.....

chandank21 opened this issue · 5 comments

Non-OK status 500 when performing a request to http://localhost:8080/OpenADR2/Simple/2.0b/EiReport with data

<?xml version="1.0" encoding="utf-8"?>
<oadr:oadrPayload xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
    <oadr:oadrSignedObject oadr:Id="oadrSignedObject" xmlns:oadr="http://openadr.org/oadr-2.0b/2012/07">
        <oadr:oadrRegisterReport ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
            <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads">32e5db4c-d11b-4fa6-85cb-2881d4a37b17</requestID>
            <oadr:oadrReport xmlns:strm="urn:ietf:params:xml:ns:icalendar-2.0:stream" xmlns:xcal="urn:ietf:params:xml:ns:icalendar-2.0">
                <ei:eiReportID/>
                <oadr:oadrReportDescription xmlns:emix="http://docs.oasis-open.org/ns/emix/2011/06" xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power">
                    <ei:rID>06fc0da1-901b-4fc9-b39e-09bbded6e794</ei:rID>
                    <ei:reportDataSource>
                        <ei:resourceID>device001</ei:resourceID>
                    </ei:reportDataSource>
                    <ei:reportType>reading</ei:reportType>
                    <power:voltage xmlns:power="http://docs.oasis-open.org/ns/emix/2011/06/power" xmlns:scale="http://docs.oasis-open.org/ns/emix/2011/06/siscale">
                        <power:itemDescription>Voltage</power:itemDescription>
                        <power:itemUnits>V</power:itemUnits>
                        <scale:siScaleCode>none</scale:siScaleCode>
                    </power:voltage>
                    <ei:readingType>Direct Read</ei:readingType>
                    <oadr:oadrSamplingRate>
                        <oadr:oadrMinPeriod>PT10S</oadr:oadrMinPeriod>
                        <oadr:oadrMaxPeriod>PT10S</oadr:oadrMaxPeriod>
                        <oadr:oadrOnChange>false</oadr:oadrOnChange>
                    </oadr:oadrSamplingRate>
                </oadr:oadrReportDescription>
                <ei:reportRequestID>0</ei:reportRequestID>
                <ei:reportSpecifierID>046b0583-3224-44a1-89c3-a05e308c1c4a</ei:reportSpecifierID>
                <ei:reportName>METADATA_TELEMETRY_USAGE</ei:reportName>
                <ei:createdDateTime>2022-04-29T18:50:14.281646Z</ei:createdDateTime>
            </oadr:oadrReport>
            <ei:venID>ven_id_123</ei:venID>
            <ei:reportRequestID>0</ei:reportRequestID>
        </oadr:oadrRegisterReport>
    </oadr:oadrSignedObject>
</oadr:oadrPayload>

: 500

Can you show me the code for your VEN and VTN? I can do very little with just the above information. Thanks.

# VTN side code....
async def on_create_party_registration(registration_info):
    """
    Inspect the registration info and return a ven_id and registration_id.
    """
    if registration_info['ven_name'] == 'ch126':
        ven_id = 'ch_id_126'
        registration_id = 'ch_reg_id_123'
        return ven_id, registration_id
    else:
        return False

async def on_register_report(ven_id, resource_id, measurement, unit, scale,
                             min_sampling_interval, max_sampling_interval):
    """
    Inspect a report offering from the VEN and return a callback and sampling interval for receiving the reports.
    """
    callback = partial(on_update_report, ven_id=ven_id, resource_id=resource_id, measurement=measurement)
    sampling_interval = min_sampling_interval
    return callback, sampling_interval

async def on_update_report(data, ven_id, resource_id, measurement):
    """
    Callback that receives report data from the VEN and handles it.
    """
    for time, value in data:
        print(f"Ven {ven_id} reported {measurement} = {value} at time {time} for resource {resource_id}")
        tyme = datetime.now(timezone.utc)+timedelta(seconds=5)
        server.add_event(ven_id='ven_id_123',
                         signal_name='simple',
                         signal_type='level',
                         intervals=[{'dtstart': tyme,
                                     'duration': timedelta(minutes=10),
                                     'signal_payload': 1}],
                         callback=event_response_callback)

async def event_response_callback(ven_id, event_id, opt_type):
    """
    Callback that receives the response from a VEN to an Event.
    """
    print(f"VEN {ven_id} responded to Event {event_id} with: {opt_type}")


server = OpenADRServer(vtn_id='teravtn')
server.add_handler('on_create_party_registration', on_create_party_registration)
server.add_handler('on_register_report', on_register_report)

loop = asyncio.get_event_loop()
loop.create_task(server.run())
loop.run_forever()
# VEN side code..
async def collect_report_value():
    return 1.23
async def handle_event(event):
    print(event)
    return 'optOut'

client = OpenADRClient(ven_name='ch126',
                       vtn_url='http://localhost:8080/OpenADR2/Simple/2.0b')

client.add_report(callback=collect_report_value,
                  resource_id='device1',
                  measurement='voltage',
                  sampling_rate=timedelta(seconds=30))
client.add_handler('on_event', handle_event)
loop = asyncio.get_event_loop()
loop.create_task(client.run())
loop.run_forever()

I think this is related to the issue that was reported in #116, which is fixed in OpenLEADR version 0.5.26. Parsing of just a single report would go wrong at the VTN side.

Could you try it again with the latest version? Thanks.

thank you....
can you tell me ? what is use of report duration in client.add_report()? how should I use?

thank you