ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

How the CS can notice when charge point is unpluged from power supply

Open iandresolares opened this issue 3 years ago • 2 comments
trafficstars

Hello, I am having issues when a Charge Point is connected to the CS but it is suddenly disconnected from the power supply and then it is connected again. The thing is, I am not able to detect that the Charge Point has been disconnected and when it reconnects another task it's created to it, having 2 tasks refering to the same Charge Point. I would like to cancel and erase the task from the queue when the hearbeat is not received for a bigger amount of time than the HearbeatInterval. But since the ChargePoint object has no access to the csms object I don't know how I can achieve such behaviour. Is there any solution for this issue?

I tried something like this hoping the Exception would propagate to the try except block around cp.start() but it doesn't.

    @on(Action.Heartbeat)
    def on_heartbeat(self, **kwargs) -> call_result.HeartbeatPayload:
        if self.task is None:
            self.task = asyncio.create_task(self.disconnection())
        elif not self.task.done():
            self.task.cancel()
            self.task = asyncio.create_task(self.disconnection())

        return call_result.HeartbeatPayload(current_time=get_utc_timestamp())

    async def disconnection(self):
        try:
            await asyncio.sleep(self.heartbeat_interval * 1.2)
            raise CustomError
        except asyncio.CancelledError:
            logger.debug("CP is connected - CancelledError")
        except CustomError:
            logger.debug("POWER OFF")
            # do some stuff
            raise Exception("POWER OFF")

Thanks!!

iandresolares avatar Mar 18 '22 11:03 iandresolares

The thing is, I am not able to detect that the Charge Point has been disconnected

Why not? If a connection dies, reading from the socket fails and ChargePoint.start() raises an error.

async def on_connect(websocket, path):

    charge_point_id = path.strip('/')
    cp = ChargePoint(charge_point_id, websocket)

    try:
       await cp.start()
    except websockets.exceptions.ConnectionClosed:
        # handle disconnect
         pass

OrangeTux avatar Apr 01 '22 13:04 OrangeTux

Hi, thanks for your response. Well yes, but there is no exception until the CS sends a request to the Charge Point and there is a timeout error, am I right?

iandresolares avatar Apr 07 '22 14:04 iandresolares

I would expect the charge point to send a new boot notification at this point it has registered again to the central system, depending on how message routing is setup and will determine delivery to the newly established connection. Regarding stale connections, the central system could periodically query the charge point with a message such as from OCPP 1.6 - section 1.27. GetTransactionStatus - or at the websockets layer a periodic ping message or query the IP. However, as this issue has gone stale I will close this for now.

Jared-Newell-Mobility avatar Dec 18 '23 14:12 Jared-Newell-Mobility