ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

Call from central_system to charge_point - AttributeError

Open garima8 opened this issue 4 years ago • 5 comments
trafficstars

I need help please, I was trying to implement a call from central_system to charge_point for reset.req and got this error. *** AttributeError: 'ChargePoint' object has no attribute '_call_result'

This is my function of the reset request

async def reset_req(self):
    request = call.ResetPayload(
        type= ResetType.hard
    )
    response = await self.call(request)
    if response.status == ResetStatus.accepted:
        print("Reset Accepted!!")
    else:
        print("Reset Rejected!!")

Thank you.

garima8 avatar May 27 '21 10:05 garima8

I see nothing wrong there. Two things:

  • Provide us your code from starting of the Server/client up to the Reset Call
  • Provide us a complete logging message of the error you got please

tropxy avatar May 27 '21 14:05 tropxy

I see nothing wrong there. Two things:

  • Provide us your code from starting of the Server/client up to the Reset Call
  • Provide us a complete logging message of the error you got please

Thank you, I got it working. Though I had to make some changes in the charge_point.py code. Now, if you can help me out with this issue,

  • How can I send a reset call, from the server according to whenever I want it to be sent?
async def on_connect(websocket, path):
    """ For every new charge point that connects, create a ChargePoint
    instance and start listening for messages.
    """
    try:
        requested_protocols = websocket.request_headers[
            'Sec-WebSocket-Protocol']
    except KeyError:
        logging.info("Client hasn't requested any Subprotocol. "
                 "Closing Connection")
    if websocket.subprotocol:
        logging.info("Protocols Matched: %s", websocket.subprotocol)
    else:
        logging.warning('Protocols Mismatched | Expected Subprotocols: %s,'
                        ' but client supports  %s | Closing connection',
                        websocket.available_subprotocols,
                        requested_protocols)
        return await websocket.close()
    charge_point_id = path.strip('/')
    cp = ChargePoint(charge_point_id, websocket)
    try:
        asyncio.gather(cp.reset_req())
        await asyncio.gather(cp.start())        
    except websockets.exceptions.ConnectionClosed:
        connected.remove(websocket)
        print("Charge Point disconnected")
    
async def main():
    server = await websockets.serve(
        on_connect,
        '0.0.0.0',
        port,
        subprotocols=['ocpp1.6'],
        ping_interval=None,
        ping_timeout=None
    )
    logging.info("WebSocket Server Started")
    await server.wait_closed()


if __name__ == '__main__':
    asyncio.run(main())    

The reset code is mentioned above.

Thank you.

garima8 avatar May 27 '21 17:05 garima8

I am trying to do this exact same thing. This could be a really useful tool for basic, local OCPP testing provided there was a way to trigger certain events from the CSMS to the CS. I'd love to know how to do this so I can make better use of this tool!

I had thought of creating a simple UI with a drop down of the requests to send with a button event, but UIs don't play nicely at all with asyncio...

jhaws1982 avatar Oct 20 '21 20:10 jhaws1982

@garima8 Hi, were you able to get some progress in this. I am trying to send a call from central system to charge point but I am stuck. Control is not able to move past this line - await self.call(request) .

ashutoshshisodia avatar Jul 04 '22 06:07 ashutoshshisodia

Hi,

Yes, I was able to resolve it. It's working fine for me now.

Regards, Garima Mangla

On Mon, Jul 4, 2022 at 12:15 PM Ashutosh Shisodia @.***> wrote:

@garima8 https://github.com/garima8 Hi, were you able to get some progress in this. I am trying to send a call from central system to charge point but I am stuck. Control is not able to move past this line - await self.call(request) .

— Reply to this email directly, view it on GitHub https://github.com/mobilityhouse/ocpp/issues/211#issuecomment-1173416256, or unsubscribe https://github.com/notifications/unsubscribe-auth/AELVMIVBEOSGU7CMNG4DYTLVSKCBTANCNFSM45T7SJWA . You are receiving this because you were mentioned.Message ID: @.***>

garima8 avatar Jul 04 '22 15:07 garima8