Closed martenjacobs closed 5 years ago
quote @jodur in #1:
After getting a better overview now, one important thing must also be added to the library if we want to run this software as a "never forget" service. exception handling for following situations:
power cycle (on->off->on) of OTGW should be possible without terminating the service temporary communication breaks (TCP -> Wifi problem, disconnection) For the Serial implementation this is probably not necessary, due the nature of serial com, but for the tcp implementation this is a must! For the above i would normally implement a state machine with states disconnected, connected and communication interrupted In the disconnected state i would do, the open method, after success => State connected if not retry to open the connection after a delay, the read statements in State connected. If a failure is detected=> communication interrupted state, do some error handling (closing sockets for example) in State communication interrupted and then go back to state disconnected. I think this should be implemented in the worker Thread?
To make sure the service does not fail when the connection is lost, I think we could define some Exceptions (something like a ConnectionLostException
springs to mind) and raise them whenever read
fails due to a broken connection. Then the worker could call close
and then open
to reopen the connection. If this fails, wait 10 seconds and try again. Does that sound good to you @jodur?
Marten sounds good!
Hi @jodur,
Could you do some testing on the tcp branch? I've made some changes to improve support for connection dropping, but I'm unable to test them. If it works, I'll merge it into master
@martenjacobs , Thx for the improvements, i will be able to test it this weekend!
I notice on first sight of the code that no exception handeling is defined for the open method?
In case the code starts and the client is not available, it should als try to reconnect!
@martenjacobs ,
It took sometime longer, had no time this weekend but i have created a pull request for the code i tested. I have added als the reconnection on the open method.
Any updates?
@andriej please see #1 and #3
As requested by @Jodur in the discussion on PR #1, handling of disconnects on less reliable connections should be improved