I still haven't figured out how to work with the ICMP connection. I currently use V 4.9971
The example destroys the icmp connection every time a result is received.
I do the same trick, but on the onMessage callback received a additional result everytime the connection is recreated. It looks like the ols conenction is not clean up correctly. Using the send on the ICMP connection does not work as I expect (I expect a ping message to be send)
Some code snippets:
onheartbeat:
Code: Select all
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("Domoticz")
onMessage:
Code: Select all
if isinstance(Data, dict) and (Data["Status"] == 0):
self.Log("Ping reply [ms]: "+str(Data["ElapsedMs"]) , 6, 1)
if not self.lastState: # last state was offline
Devices[1].Update( 1, "On") # update
self.lastState = True
else:
# not alive
self.Log("Not alive", 6, 1)
if self.lastState:
Devices[1].Update( 0, "Off")
self.lastState = False
# reset connection
self.icmpConnection.Disconnect()
self.icmpConnection = None
Heartbeat interval is 10 sec. When the device is online I get logging like:
Code: Select all
2018-09-02 07:57:44.095 (TV) Ping reply [ms]: 1
2018-09-02 07:57:44.095 (TV) Ping reply [ms]: 543
2018-09-02 07:57:44.095 (TV) Ping reply [ms]: 1315
2018-09-02 07:57:44.096 (TV) Ping reply [ms]: 1671
2018-09-02 07:57:44.096 (TV) Ping reply [ms]: 2028
2018-09-02 07:57:44.096 (TV) Ping reply [ms]: 2974
2018-09-02 07:57:44.096 (TV) Ping reply [ms]: 3411
2018-09-02 07:57:44.096 (TV) Ping reply [ms]: 4597
2018-09-02 07:57:44.096 (TV) Ping reply [ms]: 4149
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 5184
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 5497
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 6516
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 6873
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 7834
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 8256
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 8632
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 9848
2018-09-02 07:57:44.097 (TV) Ping reply [ms]: 10831
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 11301
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 12517
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 13088
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 14265
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 14825
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 15267
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 15555
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 16787
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 17530
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 18219
2018-09-02 07:57:44.098 (TV) Ping reply [ms]: 18536
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 19625
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 20108
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 20667
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 21360
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 21669
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 22301
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 23159
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 23398
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 24000
2018-09-02 07:57:44.099 (TV) Ping reply [ms]: 24541
2018-09-02 07:58:03.062 (TV) Ping reply [ms]: 16532
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 17764
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 18508
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 19196
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 19513
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 20603
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 21085
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 21644
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 22338
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 22647
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 23278
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 24137
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 24376
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 24978
2018-09-02 07:58:03.063 (TV) Ping reply [ms]: 25518
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 5
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 979
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 1522
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 2294
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 2650
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 3007
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 3953
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 4389
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 5127
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 5576
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 6162
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 6475
2018-09-02 07:58:03.064 (TV) Ping reply [ms]: 7495
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 7852
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 8814
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 9236
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 9613
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 10828
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 11811
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 12282
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 13498
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 14069
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 15246
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 15806
2018-09-02 07:58:03.065 (TV) Ping reply [ms]: 16247
So It looks like the onMessage is called multiple times, since the ping is only executed each 10 seconds.
How can I solve this?
May goal is to create a icmp 'connection' (idealistically only once) and periodically send a ping message.