2
2
2 . [ Overview] ( ./SCHEDULE.md#2-overview )
3
3
3 . [ Installation] ( ./SCHEDULE.md#3-installation )
4
4
4 . [ The cron object] ( ./SCHEDULE.md#4-the-cron-object )
5
- 4.1 [ Time specifiers] ( ./SCHEDULE.md#41-time-specifiers ) ..
5
+ 4.1 [ Time specifiers] ( ./SCHEDULE.md#41-time-specifiers )
6
6
4.2 [ The time to an event] ( ./SCHEDULE.md#42-the-time-to-an-event )
7
7
4.3 [ How it works] ( ./SCHEDULE.md#43-how-it-works )
8
8
4.4 [ Calendar behaviour] ( ./SCHEDULE.md#44-calendar-behaviour )
9
9
4.5 [ Limitations] ( ./SCHEDULE.md#45-limitations )
10
10
4.6 [ The Unix build] ( ./SCHEDULE.md#46-the-unix-build )
11
- 5 . [ The schedule function] (./SCHEDULE.md#5-the schedule-function)
12
- 6 . [ Use in synchronous code] ( ./SCHEDULE.md#6-use-in-synchronous-code )
11
+ 5 . [ The schedule function] ( ./SCHEDULE.md#5-the-schedule-function ) The primary interface for uasyncio
12
+ 6 . [ Use in synchronous code] ( ./SCHEDULE.md#6-use-in-synchronous-code ) If you really must
13
+ 7 . [ Hardware timing limitations] ( ./SCHEDULE,md#7-hardware-timing-limitations )
13
14
14
- ###### [ Tutorial] ( ./TUTORIAL.md#contents )
15
- ###### [ Main V3 README] ( ../README.md )
15
+ ##### [ Tutorial] ( ./TUTORIAL.md#contents )
16
+ ##### [ Main V3 README] ( ../README.md )
16
17
17
18
# 1. Scheduling tasks
18
19
@@ -46,6 +47,8 @@ function takes a `cron` instance and a callback and causes that callback to run
46
47
at the times specified by the ` cron ` . A coroutine may be substituted for the
47
48
callback - at the specified times it will be promoted to a ` Task ` and run.
48
49
50
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
51
+
49
52
# 3. Installation
50
53
51
54
Copy the ` sched ` directory and contents to the target's filesystem. It requires
@@ -74,6 +77,8 @@ numbers are shown as inclusive ranges.
74
77
5 . ` month=None ` Months (1..12).
75
78
6 . ` wday=None ` Weekday (0..6 Mon..Sun).
76
79
80
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
81
+
77
82
## 4.1 Time specifiers
78
83
79
84
The args may be of the following types.
@@ -109,6 +114,8 @@ now = int(time.time()) # Unix build returns a float here
109
114
tnext = min (cron1(now), cron2(now), cron3(now)) # Seconds until 1st event
110
115
```
111
116
117
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
118
+
112
119
## 4.3 How it works
113
120
114
121
When a cron instance is run it seeks a future time and date relative to the
@@ -159,6 +166,8 @@ my_cron(month=(2, 7, 10), hrs=1, mins=59) # moves forward 1 day
159
166
t_wait = my_cron(time.time()) # but month may be disallowed
160
167
```
161
168
169
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
170
+
162
171
## 4.5 Limitations
163
172
164
173
The ` cron ` code has a resolution of 1 second. It is intended for scheduling
@@ -175,10 +184,6 @@ On hardware platforms the MicroPython `time` module does not handle daylight
175
184
saving time. Scheduled times are relative to system time. This does not apply
176
185
to the Unix build.
177
186
178
- It has been tested on ESP8266 but this platform has poor time stability so is
179
- not well suited to long term timing applications. On my reference board timing
180
- drifted by 1.4mins/hr, an error of 2.3%.
181
-
182
187
## 4.6 The Unix build
183
188
184
189
Asynchronous use requires ` uasyncio ` V3, so ensure this is installed on a Linux
@@ -200,6 +205,8 @@ adapt `cron.py` to account for this: its design focus is small lightweight code
200
205
to run on bare metal targets. I could adapt ` crontest.py ` but it would surely
201
206
fail in other countries.
202
207
208
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
209
+
203
210
# 5. The schedule function
204
211
205
212
This enables a callback or coroutine to be run at intervals specified by a
@@ -256,6 +263,8 @@ finally:
256
263
_ = asyncio.new_event_loop()
257
264
```
258
265
266
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
267
+
259
268
# 6. Use in synchronous code
260
269
261
270
It is possible to use the ` cron ` closure in synchronous code. This involves
@@ -315,3 +324,22 @@ In my opinion the asynchronous version is cleaner and easier to understand. It
315
324
is also more versatile because the advanced features of ` uasyncio ` are
316
325
available to the application. The above code is incompatible with ` uasyncio `
317
326
because of the blocking calls to ` time.sleep ` .
327
+
328
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
329
+
330
+ # 7. Hardware timing limitations
331
+
332
+ The code has been tested on Pyboard 1.x, Pyboard D, ESP32 and ESP8266. All
333
+ except ESP8266 have good timing performance. Pyboards can be calibrated to
334
+ timepiece precision using a cheap DS3231 and
335
+ [ this utility] ( https://github.com/peterhinch/micropython-samples/tree/master/DS3231 ) .
336
+
337
+ The ESP8266 has poor time stability so is not well suited to long term timing
338
+ applications. On my reference board timing drifted by 1.4mins/hr, an error of
339
+ 2.3%.
340
+
341
+ Boards with internet connectivity can periodically synchronise to an NTP server
342
+ but this carries a risk of sudden jumps in the system time which may disrupt
343
+ ` uasyncio ` and the scheduler.
344
+
345
+ ##### [ Top] ( ./SCHEDULE.md#1-scheduling-tasks )
0 commit comments