---
name: "coap_deprecated"
section: "3"
platform: "linux"
package: "libcoap3t64"
version: "4.3.4-1.1+deb13u3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/coap_deprecated"
---

# coap\_deprecated(3)

Work with CoAP deprecated functions

## NAME

coap\_deprecated, coap\_clear\_event\_handler, coap\_context\_set\_psk, coap\_encode\_var\_bytes, coap\_new\_client\_session\_psk, coap\_option\_clrb, coap\_option\_getb, coap\_option\_setb, coap\_read, coap\_register\_handler, coap\_resource\_set\_dirty, coap\_run\_once, coap\_set\_event\_handler, coap\_write - Work with CoAP deprecated functions

## SYNOPSIS

**#include \<coap3/coap.h\>**

**void coap\_clear\_event\_handler(coap\_context\_t \****context***);**

**int coap\_context\_set\_psk(coap\_context\_t \****context***, const char \****hint***, const uint8\_t \****key***, size\_t** *key\_len***);**

**int coap\_encode\_var\_bytes(uint8\_t \****buffer***, unsigned int** *value***);**

**coap\_session\_t \*coap\_new\_client\_session\_psk(coap\_context\_t \****context***, const coap\_address\_t \****local\_if***, const coap\_address\_t \****server***, coap\_proto\_t** *proto***, const char \****identity***, const uint8\_t \****key***, unsigned** *key\_len***);**

**int coap\_option\_clrb(coap\_opt\_filter\_t \****filter***, uint16\_t** *type***);**

**int coap\_option\_getb(coap\_opt\_filter\_t \****filter***, uint16\_t** *type***);**

**int coap\_option\_setb(coap\_opt\_filter\_t \****filter***, uint16\_t** *type***);**

**void coap\_read(coap\_context\_t \****context***, coap\_tick\_t** *now***);**

**void coap\_register\_handler(coap\_resource\_t \****resource***, coap\_request\_t** *method***, coap\_method\_handler\_t** *handler***);**

**int coap\_resource\_set\_dirty(coap\_resource\_t \****resource***, const coap\_string\_t \****query***);**

**int coap\_run\_once(coap\_context\_t \****context***, uint32\_t** *timeout\_ms***);**

**void coap\_set\_event\_handler(coap\_context\_t \****context***, coap\_event\_handler\_t** *handler***);**

**unsigned int coap\_write(coap\_context\_t \****context***, coap\_socket\_t \****sockets***\[\], unsigned int** *max\_sockets***, unsigned int \****num\_sockets***, coap\_tick\_t** *now***);**

For specific (D)TLS library support, link with **-lcoap-3-notls**, **-lcoap-3-gnutls**, **-lcoap-3-openssl**, **-lcoap-3-mbedtls** or **-lcoap-3-tinydtls**. Otherwise, link with **-lcoap-3** to get the default (D)TLS library support.

## DESCRIPTION

Several of the existing CoAP API functions have been deprecated. These are listed here, along with the functions that should now be used instead.

## FUNCTIONS

**Function: coap\_clear\_event\_handler()**

The **coap\_clear\_event\_handler**() function is replaced by [**coap\_register\_event\_handler**(3)](/coap_register_event_handler/3.md), using NULL for *handler*.

**Function: coap\_context\_set\_psk()**

The **coap\_context\_set\_psk**() function is replaced by [**coap\_context\_set\_psk2**(3)](/coap_context_set_psk2/3.md) which gives additional PSK configuration capability by the use of the coap\_dtls\_spsk\_t structure.

**Function: coap\_encode\_var\_bytes()**

The **coap\_encode\_var\_bytes**() function is replaced by [**coap\_encode\_var\_safe**(3)](/coap_encode_var_safe/3.md).

**Function: coap\_new\_client\_session\_psk()**

The **coap\_new\_client\_session\_psk**() function is replaced by [**coap\_new\_client\_session\_psk2**(3)](/coap_new_client_session_psk2/3.md) which gives additional PSK configuration capability by the use of the coap\_dtls\_cpsk\_t structure.

**Function: coap\_option\_clrb()**

The **coap\_option\_clrb**() function is replaced by [**coap\_option\_filter\_unset**(3)](/coap_option_filter_unset/3.md).

**Function: coap\_option\_getb()**

The **coap\_option\_getb**() function is replaced by [**coap\_option\_filter\_get**(3)](/coap_option_filter_get/3.md).

**Function: coap\_option\_setb()**

The **coap\_option\_setb**() function is replaced by [**coap\_option\_filter\_set**(3)](/coap_option_filter_set/3.md).

**Function: coap\_read()**

The **coap\_read**() function is replaced by [**coap\_io\_do\_io**(3)](/coap_io_do_io/3.md).

**Function: coap\_register\_handler()**

The **coap\_register\_handler**() function is replaced by [**coap\_register\_request\_handler**(3)](/coap_register_request_handler/3.md).

**Function: coap\_resource\_set\_dirty()**

The **coap\_resource\_set\_dirty**() function is replaced by [**coap\_resource\_notify\_observers**(3)](/coap_resource_notify_observers/3.md).

**Function: coap\_run\_once()**

The **coap\_run\_once**() function is replaced by [**coap\_io\_process**(3)](/coap_io_process/3.md).

**Function: coap\_set\_event\_handler()**

The **coap\_set\_event\_handler**() function is replaced by [**coap\_register\_event\_handler**(3)](/coap_register_event_handler/3.md).

**Function: coap\_clear\_event\_handler()**

The **coap\_write**() function is replaced by [**coap\_io\_prepare\_io**(3)](/coap_io_prepare_io/3.md).

## RETURN VALUES

**coap\_context\_set\_psk**() returns 1 if success, 0 on failure.

**coap\_encode\_var\_bytes**() returns either the length of bytes encoded (which can be 0 when encoding 0) or 0 on failure.

**coap\_new\_client\_session\_psk**() returns a new session if success, NULL on failure.

**coap\_option\_clrb**() returns 1 if bit was set, -1 otherwise.

**coap\_option\_getb**() returns 1 if bit was set, 0 if not.

**coap\_option\_setb**() returns 1 if bit was set, -1 otherwise.

**coap\_resource\_set\_dirty**() returns 1 if success, 0 on failure.

**coap\_run\_once**() returns number of milliseconds spent in function or -1 if there was an error.

**coap\_write**() returns the number of milli-seconds that need to be waited before the function should next be called.

## SEE ALSO

[**coap\_endpoint\_client**(3)](/coap_endpoint_client/3.md), [**coap\_endpoint\_server**(3)](/coap_endpoint_server/3.md), [**coap\_handler**(3)](/coap_handler/3.md), [**coap\_io**(3)](/coap_io/3.md), [**coap\_observe**(3)](/coap_observe/3.md), [**coap\_pdu\_access**(3)](/coap_pdu_access/3.md) and [**coap\_pdu\_setup**(3)](/coap_pdu_setup/3.md).

## FURTHER INFORMATION

See

"RFC7252: The Constrained Application Protocol (CoAP)"

for further information.

## BUGS

Please report bugs on the mailing list for libcoap: libcoap-developers@lists.sourceforge.net or raise an issue on GitHub at https://github.com/obgm/libcoap/issues

## AUTHORS

The libcoap project \<libcoap-developers@lists.sourceforge.net\>
