-
Notifications
You must be signed in to change notification settings - Fork 327
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
Only route messages if connection is not None #248
base: master
Are you sure you want to change the base?
Conversation
We have an edge case when using a ChargePoint instance with Home Assistant (https://github.com/lbbrhzn/ocpp/) where the Charger does not close its websocket properly and keeps sending messages. In the integration we want to keep the ChargePoint instance and simply reconnect the websocket when it fails eg network, reboot etc. This can be done by setting the `_connection` to `None` but with the current code `while True` throws an `AttributeError`. Checking the connection is not none would solve this and is preferable to checking the websocket is still open in my view.
Thanks for the PR @drc38.
This make sense. I've seen others wanting something similar. But I'm not entirely sure how your modification would help you. solving this problem. And whether your goal can be achieved in a different way. Can you provide a code snippet that shows the issue you're having? |
The modification stops the ChargePoint instance from responding and replying to messages ocpp received from the charger after the websocket half-close, without generating an error. I will capture a debug log when the connection is left open and post. |
Here is the debug log, note even though websockets closes there is still a ping/pong response afterwards
|
The debug log doesn't help me much, unfortunately. Assuming this PR gets merged, how you're planning to catch any exception related to connection issues? When you handle such exception, wouldn't it be an alternative to update the I'm still having troubles understanding how this PR would make your live easier. A code snippet would help with that. |
Here is the code snippet for starting and reconnecting the charger from the ChargePoint instance
Here is the relevant section from the server's on_connect method passed to websockets.serve. Let me know if you need more.
|
To prevent the connected charger from incorrectly assuming the websocket is still open after
before the HA integration reports the charger is no longer contactable. If the cause is something like a reboot the charger will then initiate a new websocket request and the reconnect code is executed. |
@OrangeTux, another reason for the PR is for our upstream integration to easily close the |
We have an edge case when using a ChargePoint instance with Home Assistant (https://github.com/lbbrhzn/ocpp/) where the Charger does not close its websocket properly and keeps sending messages. In the integration we want to keep the ChargePoint instance and simply reconnect the websocket when it fails eg network, reboot etc. This can be achieved by setting the
_connection
toNone
when the server detects the websocket half-close (resulting in the Charger timing out and closing its half as well) but with the current ocpp codewhile True
throws anAttributeError
. Checking the connection is not none would solve this and is preferable to checking the websocket is still open in my view.