python plugin - onHeartbeat frequency

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!
Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
pipiche
Posts: 51
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi
Domoticz version: beta
Location: France
Contact:

python plugin - onHeartbeat frequency

Post by pipiche » Wednesday 01 August 2018 14:44

I'm struggling with the onHeartbeat frequency and before login an issue on github, I'm wondering if that is a miss-expectation from my end.

In order to duplicate my problem, I simply took the "BaseTemplateExample.py" which is available on the domoticz distributioin.
I added the corresponding Hardware named it "Testing" and then I'm simply looking in the log to see what happen as it is for instance by default logging every onHeartbeat call

If I look to the Wiki, here is what I found for onHeartbeat()
Called every 'heartbeat' seconds (default 10) regardless of connection status.

Heartbeat interval can be modified by the Heartbeat command. Allows the Plugin to do periodic tasks including request reconnection if the connection has failed.

Warning: Setting this interval to greater than 30 seconds will cause a 'thread seems to have ended unexpectedly' message to be written to the log file every 30 seconds. The plugin will function correctly but this message can not be suppressed because it is a standard warning from Domoticz that a piece of hardware may have stopped responding.
If a plugin wants to heartbeat every 100 seconds it should be coded with the heartbeat interval set to 10, 20 or 25 seconds and only take action every 6th, 5th or 4th time the callback is invoked.
Now here is what I see in the log, and this doesn't match at all what is expected, no ?
Sometimes 20 secondes, sometimes it is called in the same seconds !

Is that a Bug or a Feature ? But in all it is far from 10s ....

Code: Select all

Aug 01 14:36:14 pi3 domoticz[20058]: 2018-08-01 14:36:14.853  Status: (Testing) Started.
Aug 01 14:36:27 pi3 domoticz[20058]: 2018-08-01 14:36:27.008  Status: (Testing) Entering work loop.
Aug 01 14:36:27 pi3 domoticz[20058]: 2018-08-01 14:36:27.009  Status: (Testing) Initialized version 1.0.0, author 'gizmocuz'
Aug 01 14:36:27 pi3 domoticz[20058]: 2018-08-01 14:36:27.077  (Testing) onStart called
Aug 01 14:36:36 pi3 domoticz[20058]: 2018-08-01 14:36:36.537  (Testing) onHeartbeat called
Aug 01 14:36:57 pi3 domoticz[20058]: 2018-08-01 14:36:57.077  (Testing) onHeartbeat called
Aug 01 14:36:57 pi3 domoticz[20058]: 2018-08-01 14:36:57.138  (Testing) onHeartbeat called
Aug 01 14:37:06 pi3 domoticz[20058]: 2018-08-01 14:37:06.517  (Testing) onHeartbeat called
Aug 01 14:37:27 pi3 domoticz[20058]: 2018-08-01 14:37:27.203  (Testing) onHeartbeat called
Aug 01 14:37:27 pi3 domoticz[20058]: 2018-08-01 14:37:27.264  (Testing) onHeartbeat called
Aug 01 14:37:36 pi3 domoticz[20058]: 2018-08-01 14:37:36.541  (Testing) onHeartbeat called
Aug 01 14:37:56 pi3 domoticz[20058]: 2018-08-01 14:37:56.828  (Testing) onHeartbeat called
Aug 01 14:37:56 pi3 domoticz[20058]: 2018-08-01 14:37:56.889  (Testing) onHeartbeat called
Aug 01 14:38:06 pi3 domoticz[20058]: 2018-08-01 14:38:06.568  (Testing) onHeartbeat called
Aug 01 14:38:26 pi3 domoticz[20058]: 2018-08-01 14:38:26.703  (Testing) onHeartbeat called
Aug 01 14:38:26 pi3 domoticz[20058]: 2018-08-01 14:38:26.765  (Testing) onHeartbeat called
Aug 01 14:38:36 pi3 domoticz[20058]: 2018-08-01 14:38:36.543  (Testing) onHeartbeat called
Aug 01 14:38:56 pi3 domoticz[20058]: 2018-08-01 14:38:56.328  (Testing) onHeartbeat called
Aug 01 14:38:56 pi3 domoticz[20058]: 2018-08-01 14:38:56.555  (Testing) onHeartbeat called
Aug 01 14:39:06 pi3 domoticz[20058]: 2018-08-01 14:39:06.548  (Testing) onHeartbeat called
Aug 01 14:39:26 pi3 domoticz[20058]: 2018-08-01 14:39:26.828  (Testing) onHeartbeat called
Aug 01 14:39:26 pi3 domoticz[20058]: 2018-08-01 14:39:26.890  (Testing) onHeartbeat called
Aug 01 14:39:36 pi3 domoticz[20058]: 2018-08-01 14:39:36.570  (Testing) onHeartbeat called
Aug 01 14:39:57 pi3 domoticz[20058]: 2018-08-01 14:39:57.204  (Testing) onHeartbeat called
Aug 01 14:39:57 pi3 domoticz[20058]: 2018-08-01 14:39:57.267  (Testing) onHeartbeat called
Aug 01 14:40:06 pi3 domoticz[20058]: 2018-08-01 14:40:06.578  (Testing) onHeartbeat called
Aug 01 14:40:26 pi3 domoticz[20058]: 2018-08-01 14:40:26.579  (Testing) onHeartbeat called
Aug 01 14:40:26 pi3 domoticz[20058]: 2018-08-01 14:40:26.642  (Testing) onHeartbeat called
Aug 01 14:40:36 pi3 domoticz[20058]: 2018-08-01 14:40:36.574  (Testing) onHeartbeat called
Aug 01 14:40:56 pi3 domoticz[20058]: 2018-08-01 14:40:56.380  (Testing) onHeartbeat called
Aug 01 14:40:56 pi3 domoticz[20058]: 2018-08-01 14:40:56.592  (Testing) onHeartbeat called
Aug 01 14:41:06 pi3 domoticz[20058]: 2018-08-01 14:41:06.570  (Testing) onHeartbeat called
Aug 01 14:41:27 pi3 domoticz[20058]: 2018-08-01 14:41:27.205  (Testing) onHeartbeat called
Aug 01 14:41:27 pi3 domoticz[20058]: 2018-08-01 14:41:27.267  (Testing) onHeartbeat called
Aug 01 14:41:36 pi3 domoticz[20058]: 2018-08-01 14:41:36.594  (Testing) onHeartbeat called
Aug 01 14:41:56 pi3 domoticz[20058]: 2018-08-01 14:41:56.581  (Testing) onHeartbeat called
Aug 01 14:41:56 pi3 domoticz[20058]: 2018-08-01 14:41:56.644  (Testing) onHeartbeat called
Aug 01 14:42:06 pi3 domoticz[20058]: 2018-08-01 14:42:06.575  (Testing) onHeartbeat called
Aug 01 14:42:27 pi3 domoticz[20058]: 2018-08-01 14:42:27.082  (Testing) onHeartbeat called
Aug 01 14:42:27 pi3 domoticz[20058]: 2018-08-01 14:42:27.154  (Testing) onHeartbeat called
Aug 01 14:42:36 pi3 domoticz[20058]: 2018-08-01 14:42:36.607  (Testing) onHeartbeat called
Aug 01 14:42:56 pi3 domoticz[20058]: 2018-08-01 14:42:56.382  (Testing) onHeartbeat called
Aug 01 14:42:56 pi3 domoticz[20058]: 2018-08-01 14:42:56.595  (Testing) onHeartbeat called
Aug 01 14:43:06 pi3 domoticz[20058]: 2018-08-01 14:43:06.627  (Testing) onHeartbeat called
Aug 01 14:43:27 pi3 domoticz[20058]: 2018-08-01 14:43:27.207  (Testing) onHeartbeat called
Aug 01 14:43:27 pi3 domoticz[20058]: 2018-08-01 14:43:27.268  (Testing) onHeartbeat called
Aug 01 14:43:36 pi3 domoticz[20058]: 2018-08-01 14:43:36.625  (Testing) onHeartbeat called
Aug 01 14:43:56 pi3 domoticz[20058]: 2018-08-01 14:43:56.832  (Testing) onHeartbeat called
Aug 01 14:43:56 pi3 domoticz[20058]: 2018-08-01 14:43:56.895  (Testing) onHeartbeat called

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

Re: python plugin - onHeartbeat frequency

Post by Dnpwwo » Thursday 02 August 2018 7:59

@pipiche,

onHeartBeat events are posted to the Plugin Framework's event queue once for every 'interval' you specify. The framework itself will service the queue as quickly as possible and process any events that are ready.

My first question for you would be: Do you have other plugins do you have running on your system?

If you have some they could be the problem if they are taking a long time to process events. Plugins that use urllib or http.client connectivity rather than the built in Connection objects can block the framework's event queue if they fail to connect which could cause things like this. Try disabling other plugins 1 by 1 to see if one of them is the issue
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: 51
Joined: Monday 02 April 2018 20:33
Target OS: Raspberry Pi
Domoticz version: beta
Location: France
Contact:

Re: python plugin - onHeartbeat frequency

Post by pipiche » Thursday 02 August 2018 11:36

Dnpwwo wrote:
Thursday 02 August 2018 7:59
@pipiche,

onHeartBeat events are posted to the Plugin Framework's event queue once for every 'interval' you specify. The framework itself will service the queue as quickly as possible and process any events that are ready.

My first question for you would be: Do you have other plugins do you have running on your system?

If you have some they could be the problem if they are taking a long time to process events. Plugins that use urllib or http.client connectivity rather than the built in Connection objects can block the framework's event queue if they fail to connect which could cause things like this. Try disabling other plugins 1 by 1 to see if one of them is the issue
Thanks, I'll investigate as indeed they are quiet a number of plugin running on that Domoticz server:

SVT ( Smart Virtual Temperature) is using urllib

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests