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

Feature request: add hook to detect reconnect #1354

Closed
wlcrs opened this issue Feb 18, 2023 · 2 comments
Closed

Feature request: add hook to detect reconnect #1354

wlcrs opened this issue Feb 18, 2023 · 2 comments

Comments

@wlcrs
Copy link
Contributor

wlcrs commented Feb 18, 2023

Both the RTU and TCP client have functionality that automatically do a reconnect when the connection is interrupted.

I would like to be notified when such an event takes place, so that I can take some appropriate actions.

There is no clear way to add this functionality in the client currently, and with your upcoming work in #1199 it is unwise for me to try to implement something myself.

Proposal: add an argument to the constructor which allows you to pass a function that will be called when the event takes place. Maybe it even makes sense to add callbacks for different events?

callbacks : {
 'on_connection_made': ...,
 'on_connection_lost': ....,
 'on_reconnect': ....
}

On AsyncModbusXXXClient objects these callback functions are async, otherwise they are expected to by normal functions?

@janiversen
Copy link
Collaborator

Your idea of adding callbacks is good ! Please remember this needs to be added for async as well as sync and for all types.

I am not sure why you think there are no clear way, I would add the arguments to the base client (making it available for all) and then insert the hook in the appropriate methods.

The first part of cleaning the client is to clean the base, but I do not think it will affect a PR from you a lot, should it affect I can help solve the problems.

The callbacks should be defined as callbacks not async (this is the same as as “connection_made” etc). It is a lot more work to make them async, since you need to start an async task.

So please do not let #1199 stand in the way for a nice new functionality.

Feel free to make the pull request early in your process, and request comments from the maintainers.

@janiversen janiversen added this to the Versión 3.4 milestone Feb 21, 2023
@janiversen
Copy link
Collaborator

On dev.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants