Adding scheduler to Nodes #202
Replies: 1 comment
-
Hi Per, What I'd suggest is that you create a library out of Let me know how it works! typedef struct CoolScheduleItem
{
uint32_t interval;
uint32_t start;
void (*functionName)();
bool active;
} CoolScheduleItem;
CoolScheduleItem theCoolSchedule[16];
bool add_to_schedule(void (*added_func)(), uint32_t added_interval)
{
CoolScheduleItem arg = {.interval = added_interval, .start = millis(), .functionName = added_func, .active = true};
for (int i = 0; i < 16; i++)
{
if (!theCoolSchedule[i].active)
{
theCoolSchedule[i] = arg;
return true;
}
}
Serial.println("Schedule is full!");
return false;
}
void handle_cool_schedule()
{
for (int i = 0; i < 16; i++)
{
if (theCoolSchedule[i].active && (millis() - theCoolSchedule[i].start > theCoolSchedule[i].interval))
{
theCoolSchedule[i].start = millis();
theCoolSchedule[i].functionName();
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Adding scheduler to Nodes
Timm you have everything to add scheduler to nodes.
Here is my suggestion to add scheduling to nodes.
1: Copy “fdrs_gateway_scheduler.h” -> “fdrs_node_scheduler.h”
2: Edit “fdrs_node.h”
Add #include "fdrs_node_scheduler.h", just below #include "fdrs_debug.h"
Line58 #include "fdrs_debug.h"
NEW Line #include "fdrs_node_scheduler.h"
3: Edit “fdrs_node.h”
Add handle_schedule(); in void loopFDRS()
Line 283 void loopFDRS()
{
NEW Line void loopFDRS()
{
handle_schedule();
After this I can use scheduleFDRS() in Nodes.
Example in the your “Irrigation”:
If I want the Irrigition node to report status every 30 sec. I just have to add
scheduleFDRS(checkCoils, 30000);
in setup()
You made it easy , thanks 🙂
Beta Was this translation helpful? Give feedback.
All reactions