muwerk Scheduler Library
A low-resource cooperative scheduler with MQTT-like queues for Arduinos, ATtiny up to ESP32
|
muwerk is a cooperative scheduler with mqtt-like queues.
muwerk relies only on ustd. Check documentation for required platform defines.
muwerk provides a cooperative scheduler that allows fixed-intervall task creation on platforms from attiny up to ESP32 and Linux. (Linux support for testing with debuggers and valgrind.)
Tasks can simply be created by:
This example creates a task identified by function void myTask()
with task-name taskname
that is executed every 50ms (50000us). On ESP8266 minimum schedule time is around 50us.
The arduino main look simply needs to contain the line:
This calls the muwerk scheduler who dispatches the registered tasks.
If a message with topic $SYS/stat/get
with string-encoded integer N
as message is received, the scheduler sends a statistics json object to topic $SYS/stat
every N
milliseconds. If N
is zero, no more stat information is published.
Sample stat json (single output-line from Examples/mac-linux
):
Field | Explanation |
---|---|
dt | µsec since last stat sample |
syt | time in usec used by OS |
apt | time in usec used by mwerk tasks |
mat | time in usec for housekeeping |
upt | uptime of system in seconds |
mem | free memory, max. INT_MAX for unixoids |
tsks | number of muwerk tasks tn |
tdt | array of tn entries for each task, containing: task-name tname , tid taskID of process, sched_time scheduling time, number of times task was executed during sample time cn , usecs used by this task during this sample sct , accumulated usecs task execution was later than scheduled slt |
This example shows a dt=500ms
sample, it has two tasks, task1
, id=1
was called 10 times, every 50ms, and used average 9.9240ms per call (task-code has approx. 10ms sleep), and task2
, id=2
was called 7 times, every 75ms, and used average 4.991ms (5ms sleep in code). Both tasks were always executed as schedules (negligable late-times cn
).
See Examples\mac-linux
. (Not available on ATTINY platforms, only ATMEGA and better).
For systems that are connected to an MQTT-server (via munet
), a python example script mutop shows how to parse the statistical information.
A more complete example is available at blink that shows how tasks can communicate MQTT-style with each other and – blink a led.
Tasks can communicate with each other using an MQTT-like pub/sub mechanism. On ESP8266 or ESP32 platforms, the internal communication can be exported transparently using munet's interface to the PubSubClient Arduino MQTT library. The scheduler's task information is also exported via MQTT.
See the documentation for more samples on muwerk's task scheduler and pub/sub intertask communication.
The Console
class allows to bind a serial console to muwerk that allows to inspect message passing, file system (if available) and statistical information. See the mu_console
example for more information.
doctor.h
and i2cdoctor.h
hat wrong casing for Arduino_JSON.h
include.ustd_
prefix to prevent name-clashes with various platform-sdks. [queue.h clashed with ESP8266-Wifi, platform.h clashed with RISC-V SDK, hence new names ustd_queue.h
and ustd_platform.h
etc.]Doctor
and I2CDoctor
.ustd::Console
and ustd::SerialConsole
do now honour the USTD_FEATURE_xxx defines.__ARM__
, __RISC_V__
)UST_FEATURE_MEM
defines used (requires ustd
version 0.4.1 or higher), ATtiny T_TASK limited to static functions.library.properties
project name repaired, to allow Arduino automatic update.readString
with length validation to ustd::jsonfile
ustd::doctor
implements a remote diagnostics interface via pub/sub messages.ustd::Console
has now a better interface for using other Printer-derived stream objects, ustd::SerialConsole
can now be used with alternative serial interfacesustd::Scheduler
mutop
heartbeat
and timeout
.shift
and split
for string argument handling.mutop
that allows to monitor tasks and resource consumption for mqtt connected systems.$SYS/STAT
format expanded to contain uptime, free memory, and per-task infos task-id and schedule-time.$SYS/stat
. Use publish to $SYS/stat/get
, message body number
(as string encoded) to receive stat information every number
milliseconds.ustd::function<>
.muwerk
is a derivative and lightweight version of Meisterwerk.