-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_reboot_request.ino
More file actions
64 lines (54 loc) · 1.63 KB
/
Copy pathbasic_reboot_request.ino
File metadata and controls
64 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <ESPRebootManager.h>
#include <cstdio>
ESPRebootManager rebootManager;
void setup() {
Serial.begin(115200);
ESPRebootManagerConfig config;
config.taskName = "reboot-manager";
config.taskStackSizeBytes = 6 * 1024;
config.taskPriority = 1;
config.taskCoreId = tskNO_AFFINITY;
config.callbackTimeoutMs = 1000;
rebootManager.init(config);
rebootManager.onRebootRequest([](const RebootRequestContext &ctx) {
RebootVote vote;
if (ctx.reason[0] == '\0') {
vote.allow = false;
std::snprintf(vote.detail, sizeof(vote.detail), "missing reboot reason");
return vote;
}
// Return false from any callback to block reboot.
vote.allow = true;
return vote;
});
rebootManager.onEvaluation([](const RebootEvaluation &evaluation) {
if (evaluation.accepted) {
Serial.printf(
"[reboot] accepted id=%lu reason=%s delay=%lu\n",
static_cast<unsigned long>(evaluation.requestId),
evaluation.reason,
static_cast<unsigned long>(evaluation.delayMs)
);
return;
}
Serial.printf(
"[reboot] rejected id=%lu code=%u blocker=%s detail=%s\n",
static_cast<unsigned long>(evaluation.requestId),
static_cast<unsigned>(evaluation.code),
evaluation.blockerName,
evaluation.detail
);
});
RebootSubmitResult result = rebootManager.requestReboot("ExampleReason", 1500);
Serial.printf(
"submit status=%u requestId=%lu\n",
static_cast<unsigned>(result.status),
static_cast<unsigned long>(result.requestId)
);
}
void loop() {
delay(250);
if (rebootManager.isRebootRequested()) {
Serial.printf("status=%u\n", static_cast<unsigned>(rebootManager.rebootStatus()));
}
}