Question to the "setPluginTaskTimer" function

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
michael3
New user
Posts: 2
Joined: 06 Oct 2018, 22:52

Question to the "setPluginTaskTimer" function

#1 Post by michael3 » 06 Oct 2018, 23:17

Hello,
i'm currently developing a plugin called "_P081_DosingPump" to control some small dosing pump motors.
The 6 motor drivers for the dosing pumps are controlled via an 74HC595 shift register.
I basically copied the "_P001_Switch" plugin and modified it a little, so I can enter some calibration paramters for the dosing pump in the device section.

At the moment the plugin is supporting two types of command
- "dose_ms,pump_number,dosing_time"
- "dose_ml,pump_number,dosing_amount"
which basically turns on the pump "pump_number" on for "dosing_time" milliseconds or for a time which corresponds to "dosing_amount" millilitres using the calibration parameter from the device section.

Everything is working so far but now I want to change the code in this way that it is not using the "delay" function inside the WRITE part of the plugin and using timers instead.
So basically doing the same as using the "longpulse_ms" command in the "_P001_switch" plugin and not the "pulse" command which is also using the "delay" function.

This is the point where I don't know how to do this. I tried to figure out how the function

void setPluginTaskTimer(unsigned long timer, byte plugin, short taskIndex, int Par1, int Par2, int Par3, int Par4, int Par5)

works but I don't really understand it.

As far as I figured out the parameters of the function are

timer: length of the timer in ms
plugin: ID of the plugin
taskIndex:not really sure but maybe the tasknumber of the command which is executed at the time?
Par1-5 some parameter for code execution of the timer

But I don't see where the code is executed after the timer. For example in the switch module the parameters when calling the function are the duration of the pulse,
the gpio pin and the state of the gpio pin after the pulse, but where in the code is the "digitalWrite(gpio,value)" for doing this?

I attached my plugin to this question.
Thanks for any help in advance!
Attachments
_P081_DosingPump.zip
(1.96 KiB) Downloaded 253 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Question to the "setPluginTaskTimer" function

#2 Post by TD-er » 07 Oct 2018, 11:08

First: Great that you are looking into the (relatively new) timers.
Second: Given the name of your plugin, please do not use it in 'life critical' situations.
Third: ESPeasy is not a real-time environment, so there is no guarantee things will happen at the specified moment.

Scheduling does work rather well, as long as there are no "blocking" plugins or controllers running.
For example the Framed OLED plugin may take up-to 100 msec to refresh the screen and even longer when scrolling.
A controller may send data to another host in the network and when this timeouts, it may take up-to the timeout time before another item can be executed from the scheduler queue.
So if things are a bit time-critical, do not add other plugins or use controllers.
Only exception can be when your own plugin is sending to a controller and the repeat interval is longer than the time needed by the controller to send the data.

The setPluginTimer needs the following:
- timer (number of msec from now)
- plugin The ID of the plugin (81 in your example)
- TaskIndex, simply the number of the plugin in the plugin list on the web page tab "Devices"
- Par1...5 The parameters needed to run the operation. (Par2...5 are optional)

This will eventually call the set plugin with the function PLUGIN_TIMER_IN.
So your plugin should also have a

Code: Select all

case PLUGIN_TIMER_IN:
These PLUGIN_TASK_TIMER only run once.

The combination "plugin" and "par1" form a key to store the timer in the queue.
So if you add a new one with the same combination, it will remove any existing one from the queue.
It is probably best to set the "on/off" like parameter as par1 in your event. That allows you to schedule the on and off at the same moment and just wait for it to happen.

michael3
New user
Posts: 2
Joined: 06 Oct 2018, 22:52

Re: Question to the "setPluginTaskTimer" function

#3 Post by michael3 » 07 Oct 2018, 16:09

Thank you very much for your reply,

PLUGIN_TASK_TIMER was exaxtly what I was looking for.

The device will run later as a standalone only with one device (my own plugin), I just use the espeasy enviroment since
it has all the features as NTP already implemented.

The commands "dose_ml" will be called once a day using the Rules section, where the exact start of the command is not critical at all
and the length of the command is not too critical (couple of ms are not relevant at all), so I may just keep using the "delay" function since
it seems to be more stable, since no other Task whatsoever can interfere.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Question to the "setPluginTaskTimer" function

#4 Post by TD-er » 07 Oct 2018, 17:06

A delay of x msec is not guaranteed to be x msec.
During a call to delay, some background tasks are run, like processing webserver requests, handling wifi, etc.
And these may take a little more every now and then.

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: Question to the "setPluginTaskTimer" function

#5 Post by TungstenE2 » 20 Aug 2019, 11:16

any news on this dosing pump plugin? can not find it in the plugin list.

TungstenE2
Normal user
Posts: 123
Joined: 03 Apr 2018, 21:46

Re: Question to the "setPluginTaskTimer" function

#6 Post by TungstenE2 » 07 Nov 2019, 13:38

sad to see that michael3 is not sharing his plugin with the Forum, after he got an answer. As he did not visit the Forum since his last answer he als did not get my PM.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 22 guests