Golioth Firmware SDK
Loading...
Searching...
No Matches
client.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Golioth, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef __cplusplus
8extern "C"
9{
10#endif
11
12#pragma once
13
14#include <stdbool.h>
15#include <stdint.h>
16#include <stdlib.h>
18#include "golioth_sys.h"
19
32
34struct golioth_client;
35
44
52
68
79
85{
87 const char *psk_id;
88 size_t psk_id_len;
89
91 const char *psk;
92 size_t psk_len;
93};
94
100{
101 // DER Common CA cert
102 const uint8_t *ca_cert;
104
106 const uint8_t *public_cert;
108
110 const uint8_t *private_key;
112};
113
125
131
137typedef void (*golioth_client_event_cb_fn)(struct golioth_client *client,
138 enum golioth_client_event event,
139 void *arg);
140
153typedef void (*golioth_get_cb_fn)(struct golioth_client *client,
154 const struct golioth_response *response,
155 const char *path,
156 const uint8_t *payload,
157 size_t payload_size,
158 void *arg);
159typedef void (*golioth_get_block_cb_fn)(struct golioth_client *client,
160 const struct golioth_response *response,
161 const char *path,
162 const uint8_t *payload,
163 size_t payload_size,
164 bool is_last,
165 void *arg);
166
179typedef void (*golioth_set_cb_fn)(struct golioth_client *client,
180 const struct golioth_response *response,
181 const char *path,
182 void *arg);
183
196struct golioth_client *golioth_client_create(const struct golioth_client_config *config);
197
206bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms);
207
217enum golioth_status golioth_client_start(struct golioth_client *client);
218
233enum golioth_status golioth_client_stop(struct golioth_client *client);
234
240void golioth_client_destroy(struct golioth_client *client);
241
248bool golioth_client_is_running(struct golioth_client *client);
249
259bool golioth_client_is_connected(struct golioth_client *client);
260
266void golioth_client_register_event_callback(struct golioth_client *client,
268 void *arg);
269
277uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client);
278
286
292golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client);
293
295
296#ifdef __cplusplus
297}
298#endif
golioth_status
void * golioth_sys_thread_t
Definition golioth_sys.h:70
golioth_auth_type
Authentication type.
Definition client.h:71
golioth_content_type
Golioth Content Type.
Definition client.h:47
bool golioth_client_is_connected(struct golioth_client *client)
void(* golioth_get_block_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, const uint8_t *payload, size_t payload_size, bool is_last, void *arg)
Definition client.h:159
enum golioth_status golioth_client_start(struct golioth_client *client)
bool golioth_client_wait_for_connect(struct golioth_client *client, int timeout_ms)
void(* golioth_get_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:153
void golioth_client_register_event_callback(struct golioth_client *client, golioth_client_event_cb_fn callback, void *arg)
bool golioth_client_is_running(struct golioth_client *client)
uint32_t golioth_client_num_items_in_request_queue(struct golioth_client *client)
golioth_client_event
Golioth client events.
Definition client.h:38
enum golioth_status golioth_client_stop(struct golioth_client *client)
void(* golioth_set_cb_fn)(struct golioth_client *client, const struct golioth_response *response, const char *path, void *arg)
Definition client.h:179
void golioth_client_destroy(struct golioth_client *client)
struct golioth_client * golioth_client_create(const struct golioth_client_config *config)
golioth_sys_thread_t golioth_client_get_thread(struct golioth_client *client)
void golioth_client_set_packet_loss_percent(uint8_t percent)
void(* golioth_client_event_cb_fn)(struct golioth_client *client, enum golioth_client_event event, void *arg)
Definition client.h:137
@ GOLIOTH_TLS_AUTH_TYPE_TAG
Authenticate with TLS credential tag (Zephyr specific)
Definition client.h:77
@ GOLIOTH_TLS_AUTH_TYPE_PKI
Authenticate with PKI certificates (CA cert, public client cert, private client key)
Definition client.h:75
@ GOLIOTH_TLS_AUTH_TYPE_PSK
Authenticate with pre-shared key (psk-id and psk)
Definition client.h:73
@ GOLIOTH_CONTENT_TYPE_JSON
Definition client.h:48
@ GOLIOTH_CONTENT_TYPE_CBOR
Definition client.h:49
@ GOLIOTH_CONTENT_TYPE_OCTET_STREAM
Definition client.h:50
@ GOLIOTH_CLIENT_EVENT_CONNECTED
Client was previously not connected, and is now connected.
Definition client.h:40
@ GOLIOTH_CLIENT_EVENT_DISCONNECTED
Client was previously connected, and is now disconnected.
Definition client.h:42
Golioth client configuration, passed into golioth_client_create.
Definition client.h:128
struct golioth_credential credentials
Definition client.h:129
TLS Authentication Credential.
Definition client.h:116
enum golioth_auth_type auth_type
Definition client.h:117
struct golioth_pki_credential pki
Definition client.h:121
struct golioth_psk_credential psk
Definition client.h:120
const uint8_t * public_cert
DER Public client cert.
Definition client.h:106
const uint8_t * ca_cert
Definition client.h:102
const uint8_t * private_key
DER Private client key.
Definition client.h:110
const char * psk
Pre-shared key, secret password.
Definition client.h:91
const char * psk_id
PSK Identifier (e.g. "devicename@projectname")
Definition client.h:87
Response status and CoAP class/code.
Definition client.h:55
enum golioth_status status
Definition client.h:62
uint8_t status_code
the 03 in 4.03
Definition client.h:66
uint8_t status_class
the 2 in 2.XX
Definition client.h:64