|
SimpleOTA client v1.2.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
|
Delivery and polling policy for deferred status reports. More...
Go to the source code of this file.
Data Structures | |
| struct | sota_report_t |
| One status report waiting to be sent. More... | |
| struct | sota_outbox_t |
| The outbox, oldest report first. More... | |
Macros | |
| #define | SOTA_REPORT_QUICK_RETRIES 3u |
| Quick retries for a pending report before it waits for the check interval. | |
| #define | SOTA_CONNECT_POLL_S 1u |
| Seconds between is_connected() polls while the network is down. | |
| #define | SOTA_RETRY_AFTER_MAX_S 86400u |
| The longest a server's Retry-After is honoured: a day. | |
| #define | SOTA_JITTER_MIN_S 60u |
| Waits from this long on are spread, so devices that start together (a power cut ending, a batch off the line) do not check in together for ever after. | |
| #define | SOTA_OUTBOX_VERSION 1u |
| Layout of the stored outbox blob. | |
| #define | SOTA_OUTBOX_SLOTS 2u |
| Reports the outbox holds. | |
Functions | |
| static bool | sota_report_delivered (int http_status) |
| A report is delivered once the server returns any HTTP response. | |
| static uint32_t | sota_poll_interval_s (bool connected, bool in_trial, bool report_pending, uint32_t report_failures, uint32_t quick_s, uint32_t check_interval_s) |
| Seconds until the next check. | |
| static bool | sota_http_transient (int http_status) |
| An HTTP result worth trying again soon: no response, a server error, or a server asking for patience. | |
| static uint32_t | sota_retry_interval_s (uint32_t failures, uint32_t check_interval_s) |
| Seconds until the next check after one that failed on the network, at the check-in or in the download: 30 s, 2 min and 10 min after the first three failures in a row, then the check interval, and never longer than it. | |
| static uint32_t | sota_retry_after_wait_s (uint32_t wait_s, uint32_t retry_after_s, uint32_t random) |
| The wait once a 429 or 503 asked for retry_after_s seconds (0: it did not): never sooner than asked, and up to a tenth later, because every device was told the same number. | |
| static uint32_t | sota_jitter_s (uint32_t wait_s, uint32_t random) |
| wait_s moved within a span of wait_s / 5 (rounded down) seconds: down by up to span / 2 rounded down, up by up to span / 2 rounded up: at most a tenth either way, except that an odd span reaches half a second further up (65 s gives 59 to 72 s). | |
| static bool | sota_copy_field (char *dst, size_t cap, const char *src) |
| Copy src into a fixed field. | |
| static void | sota_outbox_init (sota_outbox_t *box) |
| Empty the outbox. | |
| static bool | sota_field_terminated (const char *field, size_t cap) |
| True when field has a NUL within cap bytes. | |
| static bool | sota_outbox_valid (const sota_outbox_t *box) |
| True when a loaded blob has this layout, a count it can hold, and only reports that sota_outbox_push() could have added. | |
| static bool | sota_outbox_push (sota_outbox_t *box, const char *event, const char *reason, const char *deployment, uint32_t build) |
| Add a report at the back. | |
| static void | sota_outbox_pop (sota_outbox_t *box) |
| Remove the report at the front. | |
Delivery and polling policy for deferred status reports.
"confirmed" and "rolled_back" are telemetry. What the server says about them never changes what the device does. A report is delivered once the server returns any HTTP response. Without a response it stays pending and is sent again on later checks: a few quick retries, then at the normal check interval.
No platform types, so the host tests can include this header.
| #define SOTA_JITTER_MIN_S 60u |
Waits from this long on are spread, so devices that start together (a power cut ending, a batch off the line) do not check in together for ever after.
Shorter waits stay exact: the connection, trial and report polls, and the first network retry. The later retries are spread too.
|
inlinestatic |
Seconds until the next check.
connected: is_connected() allowed the check that just ran. While it does not, it is polled every SOTA_CONNECT_POLL_S, so the check runs as soon as the network is up instead of a whole check interval later. in_trial: a trial is running, so checks come every quick_s until it is confirmed or rolled back. report_pending: a confirmed or rolled_back report is waiting to be sent. report_failures: sends of that report that got no response this boot.
|
inlinestatic |
An HTTP result worth trying again soon: no response, a server error, or a server asking for patience.
Any other answer will not change by asking again.
|
inlinestatic |
Seconds until the next check after one that failed on the network, at the check-in or in the download: 30 s, 2 min and 10 min after the first three failures in a row, then the check interval, and never longer than it.
failures is 0 after a check that did not fail that way.
|
inlinestatic |
The wait once a 429 or 503 asked for retry_after_s seconds (0: it did not): never sooner than asked, and up to a tenth later, because every device was told the same number.
A request shorter than wait_s changes nothing.
|
inlinestatic |
wait_s moved within a span of wait_s / 5 (rounded down) seconds: down by up to span / 2 rounded down, up by up to span / 2 rounded up: at most a tenth either way, except that an odd span reaches half a second further up (65 s gives 59 to 72 s).
random is any 32-bit value, and its middle (0x80000000) leaves the wait unchanged when the span is even.
|
inlinestatic |
Copy src into a fixed field.
Returns false when it does not fit.
|
inlinestatic |
Empty the outbox.
< Layout of the stored outbox blob.
|
inlinestatic |
True when a loaded blob has this layout, a count it can hold, and only reports that sota_outbox_push() could have added.
< Layout of the stored outbox blob.
< Reports the outbox holds.
|
inlinestatic |
Add a report at the back.
One without an event, deployment or build, or whose fields do not fit, is not added; returns false then.
< Reports the outbox holds.
< Reports the outbox holds.
|
inlinestatic |
Remove the report at the front.
< Reports the outbox holds.