SimpleOTA client v1.0.0
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_net.h
Go to the documentation of this file.
1
10#ifndef SOTA_NET_H
11#define SOTA_NET_H
12
13#include <stddef.h>
14#include <stdint.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
21#define SOTA_NET_MAX_REDIRECTS 3
22
24static inline int sota_net_is_redirect(int status)
25{
26 return status == 301 || status == 302 || status == 303 || status == 307 || status == 308;
27}
28
30enum {
32 SOTA_NET_AGAIN = -2,
34};
35
42int sota_net_post(void *user, const char *url, const char *token, const char *body,
43 char *resp, size_t cap);
44
55int sota_net_dl_open(void *user, const char *url, int64_t *len, char *location,
56 size_t location_cap);
57
61int sota_net_dl_read(void *user, uint8_t *buf, size_t cap);
62
64void sota_net_dl_close(void *user);
65
66#ifdef __cplusplus
67}
68#endif
69
70#endif /* SOTA_NET_H */
void sota_net_dl_close(void *user)
End the download and free its connection.
int sota_net_dl_read(void *user, uint8_t *buf, size_t cap)
Read the next bytes of the body: a count, 0 once the whole body has arrived, SOTA_NET_AGAIN,...
static int sota_net_is_redirect(int status)
A status sota_net_dl_open() returns for a redirect.
Definition sota_net.h:24
int sota_net_dl_open(void *user, const char *url, int64_t *len, char *location, size_t location_cap)
Start a firmware download: a GET without the Authorization header (the pre-signed URL carries its own...
int sota_net_post(void *user, const char *url, const char *token, const char *body, char *resp, size_t cap)
POST body as JSON to url, with "Authorization: Bearer <token>".
@ SOTA_NET_ERROR
The connection failed.
Definition sota_net.h:31
@ SOTA_NET_AGAIN
No byte yet: the core calls again, and gives up with download_stalled after http_timeout_ms.
Definition sota_net.h:32