Python plugion: Reuse an ICMP connection

Python and python framework
Post Reply
elgringo
Posts: 127
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi
Domoticz version: Left
Contact:

Python plugion: Reuse an ICMP connection

Post by elgringo » Sunday 27 May 2018 9:31

I want to check if a certain deivce is online, ping it. The pinger.py example closed each ICMP connection since it uses multiple IP addresses

In the onheartbeat function I added

Code: Select all

# check if TV is online
    if (self.icmpConnection == None):
      self.icmpConnection = Domoticz.Connection(Name="LG_ICMP", Transport="ICMP/IP", Protocol="ICMP", Address=Parameters["Address"])
      self.icmpConnection.Listen()
    else:
      self.icmpConnection.Send("PING")
But this don't seem to work. There is never a message send.
When I ping it form the shell the plugin received the reply and it handles them correct.

When detroying the connection and start a new one (the part in the if statement) if a ICMP message is received does work, but every time a new connection has to be created.

So the requestion: How can I ping on an existing ICMP connection

Secondly I also noticed the file handle count is increasing, so a network connection is not closed/ destroyed correctly.
Are there a basic examples with a ICMP connection (basic is simple ping to single node)?

elgringo
Posts: 127
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi
Domoticz version: Left
Contact:

Re: Python plugion: Reuse an ICMP connection

Post by elgringo » Sunday 03 June 2018 8:03

Does anybody knows this? Or is it not possible?

I noticed a bugfix on releasing the sockets. But still don;t you if the ICMP 'connections' can be reused.

User avatar
Dnpwwo
Posts: 728
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugion: Reuse an ICMP connection

Post by Dnpwwo » Monday 04 June 2018 23:43

@elgringo,

The 'pinger.py' example that ships with Domoticz shows how to use the ICMP transport.

What platform are you using? I just tried this on Linux and it no longer works so I will need to troubleshoot it again.
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

elgringo
Posts: 127
Joined: Thursday 18 May 2017 8:08
Target OS: Raspberry Pi
Domoticz version: Left
Contact:

Re: Python plugion: Reuse an ICMP connection

Post by elgringo » Sunday 10 June 2018 18:24

I am using Linux on a raspberry pi.

The pinger.py example does not reuse a connection. eg use the send command to re ping a device instead of using a new connection with the listen command.

I don't know if this is possible.

User avatar
Dnpwwo
Posts: 728
Joined: Sunday 23 March 2014 10:00
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Python plugion: Reuse an ICMP connection

Post by Dnpwwo » Sunday 17 June 2018 6:35

@elgringo,

The ICMP connection functions a little differently depending on the platform you run it on. Normally the boost libraries Domoticz uses do a good job of protecting users from platform differences but not in this case for some reason. You may need to experiment a little.

There are a couple of patterns that worked when I tested this on different operating systems depending on what you want to achieve.
  • One thing to remember is that 'Send' starts a 5 second timeout for the connection which may get messed up if you don't wait for a response.
  • Listening on an ICMP connection will actually send a 'ping' for you (the 'listen' will fail on Windows if it doesn't for some reason)
  • If you open one connection and listen on it, on some platforms it will see all ICMP traffic (even returns from a command line ping outside of Domoticz) others platforms only return traffic to specific 'listen' address
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

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests