Python Framework - Not detecting connection issue

Python and python framework

Moderator: leecollings

Post Reply
pipiche
Posts: 2035
Joined: Monday 02 April 2018 20:33
Target OS: Linux
Domoticz version:
Contact:

Python Framework - Not detecting connection issue

Post by pipiche »

I'm developing a plugin with the Python Framework and I'm having issue with connection failure.

I was under the impression that the plugin is capable to get information of connection issue, but it looks not !

Here are the 2 connection types I'm creating. The first one is using Serial (USB), the second is using TCP.
In both case, if I start the plugin, the connection is well established.

Then I unplug the USB stick or I powerOff the Wifi device on which there is the connection

And the when checking

Code: Select all

self._connection.Connected()
, it always report True !!!!! Despite the fact that I'm writting to the connection view the Send() method.
Of course when plugin back the USB Stick or PowerOn the Wifi device, nothing restart !

Code: Select all

self._connection = Domoticz.Connection(Name="ZiGate", Transport="Serial", Protocol="None",
                                                   Address=self._serialPort, Baud=115200)
self._connection = Domoticz.Connection(Name="Zigate", Transport="TCP/IP", Protocol="None ",
                                                   Address=self._wifiAddress, Port=self._wifiPort)
pipiche
Posts: 2035
Joined: Monday 02 April 2018 20:33
Target OS: Linux
Domoticz version:
Contact:

Re: Python Framework - Not detecting connection issue

Post by pipiche »

Did a test and it tooks 10 minutes for Domoticz to detect that the connection was aborted !!!!!! ( test made with a TCP/IP connection; I'll do a serial as well but do expect the same)

Coming from the Python Framework

Code: Select all

Dec 21 08:53:24 pi3 domoticz[3244]: 2018-12-21 08:53:24.312  Error: (ZigateWifi): Async Read Exception: 113, No route to host
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python Framework - Not detecting connection issue

Post by Dnpwwo »

@pipiche,

This behaviour is standard for TCP/IP connections. If you turn off (or unplug) devices then the remote device does not have the opportunity to terminate the connection gracefully so the other end assumes it is still open. This is the reason that many protocols that go on top of TCP/IP have a heartbeat message capability so that the client can periodically test to see if the connection is still good. Also, some network devices (load balancers and firewalls) silently drop connections after a timeout period and 'pinging' prevents that.

I don't know much about ZiGate but it has a:
0x8017 Get Time server Response (v3.0f) <Timestamp UTC: uint32_t> from 2001-01-01 00:00:00
message that you could send from onHeartbeat that would tell you much quicker
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
pipiche
Posts: 2035
Joined: Monday 02 April 2018 20:33
Target OS: Linux
Domoticz version:
Contact:

Re: Python Framework - Not detecting connection issue

Post by pipiche »

Thanks
Post Reply