COAP-CLIENT(5)
π¦ NAME π¦
okay bestie, this is the manual for coap-client(5) β the CoAP Client based on libcoap π. The whole squad named on this page is: coap-client, coap-client-gnutls, coap-client-mbedtls, coap-client-openssl, coap-client-notls β CoAP Client based on libcoap. periodt β¨
πΈ SYNOPSIS πΈ
coap-client [-a addr] [-b [num,]size] [-e text] [-f file] [-l loss] [-m
method] [-o file] [-p port] [-q tls_engine_conf_file] [-r] [-s duration]
[-t type] [-v num] [-w] [-A type] [-B seconds] [-E
oscore_conf_file[,seq_file]] [-G count] [-H hoplimit] [-K interval] [-L
value] [-N] [-O num,text] [-P scheme://addr[:port]] [-T token] [-U] [-V
num] [-X size] [-d value] [[-h match_hint_file] [-k key] [-u user] [-2]]
[[-c certfile] [-j keyfile] [-n] [-C cafile] [-J pkcs11_pin] [-M
rpk_file] [-R trust_casfile]] URI
For versions of coap-client where libcoap is compiled against different (D)TLS libraries, you may also see coap-client-notls, coap-client-gnutls, coap-client-openssl, coap-client-mbedtls, or coap-client-tinydtls out in the wild. If those arenβt around, coap-client just uses the default libcoap (D)TLS support. π
β¨ DESCRIPTION β¨
coap-client is a CoAP client for chatting with 6LoWPAN devices over the CoAP protocol (RFC 7252), using the URI you hand it on the command line. The URI must have the scheme coap, coap+tcp, coaps, or coaps+tcp. π°οΈ
coaps and coaps+tcp are only supported when coap-client is built with support for secure (D)TLS communication.
If coaps or coaps+tcp is being used, and the CoAP server supports PKI and is configured with a certificate and private key, then coap-client does not need to have a Pre-Shared Key (-k) or certificate (-c) configured. cute, right? π
The URIβs host part may be a DNS name, a literal IP address, or a Unix domain name. For Unix domain names, %2F is used as the / separator to differentiate between the host and patch definitions. For IPv6 address references, angle brackets are required (c.f. EXAMPLES) to delimit the host portion of the URI. π
π OPTIONS - GENERAL π
-a addrβ the local address of the interface that has to be used.
β οΈ Note: do not use this option if the interface is likely to be transient β i.e. it is a tunnel interface that may come and go, as this is likely to cause "No such device" errors on transmission.
-b [num,]sizeβ the block size to be used inGET/PUT/POSTrequests (value must be16,32,64,128,256,512, or1024). Ifnumis present, the request chain will start at blocknum. When the server includes aBlock2option in its response to aGETrequest,coap-clientwill automatically retrieve the subsequent block from the server until there are no more outstanding blocks for the requested content. π§±-e textβ includetextas payload (use percent-encoding for non-ASCII characters).-f fileβ file to send withPUT/POST(use-forSTDIN).-l listβ fail to send some datagrams specified by a comma separated list of numbers or number ranges (debugging only).-l loss%β randomly failed to send datagrams with the specified probability β100%all datagrams,0%no datagrams (debugging only).-m methodβ the request method for action (get|put|post|delete), default isget. (Note that the string passed to-mis compared case-insensitive.) π-o fileβ a filename to store data retrieved withGET.-p portβ the port to send from.-q tls_engine_conf_fileβtls_engine_conf_filecontains TLS ENGINE configuration. Only OpenSSL is currently supported. Seecoap-tls-engine-conf(5)for definitions.-rβ use reliable protocol (TCP or TLS).-s durationβ subscribe to / observe the resource specified by URI for the givendurationin seconds. π-t typeβ content format for given resource forPUT/POST.typemust be either a numeric value reflecting a valid CoAP content format or a string describing a registered format. The following registered content format descriptors are supported, with alternative shortcuts given in parentheses:text/plain(plain)application/link-format(link,link-format)application/xml(xml)application/octet-stream(binary,octet-stream)application/exi(exi)application/json(json)application/cbor(cbor)
-v numβ the verbosity level to use (default4, maximum is8) for general CoAP logging.-wβ append a newline to received data.-A typeβ accepted media type.typemust be either a numeric value reflecting a valid CoAP content format or a string that specifies a registered format as described for option-t.-B secondsβ break operation after waiting givenseconds(default is90). β³-E oscore_conf_file[,seq_file]βoscore_conf_filecontains OSCORE configuration. Seecoap-oscore-conf(5)for definitions. Optionalseq_file(which is created if needed) is used to save the current transmit sequence number, so on client restart sequence numbers continue to increase and are not reset to prevent anti-replay mechanisms being triggered. π-G countβ repeat the Requestcounttimes with a second delay between each one. Must have a value between1and255inclusive. Default is1.-H hoplimitβ set the Hop Limit count tohoplimitfor proxies. Must have a value between1and255inclusive. Default is16.-K intervalβ send a ping afterintervalseconds of inactivity. If not specified (or0), keep-alive is disabled (default).-L valueβ sum of one or moreCOAP_BLOCK_*flag values for different block handling methods. Default is1(COAP_BLOCK_USE_LIBCOAP).
COAP_BLOCK_USE_LIBCOAP 1
COAP_BLOCK_SINGLE_BODY 2
COAP_BLOCK_TRY_Q_BLOCK 4
COAP_BLOCK_USE_M_Q_BLOCK 8
COAP_BLOCK_NO_PREEMPTIVE_RTAG 16
COAP_BLOCK_STLESS_FETCH 32
-Nβ send NON-confirmable message. If option-Nis not specified, a confirmable message will be sent.-O num,textβ add optionnumwith contents oftextto the request. If thetextbegins with0x, then the hex text (two[0-9a-f]per byte) is converted to binary data. β¨-P scheme://addr[:port]β scheme, address and optional port to define how to connect to a CoAP proxy (automatically addsProxy-Urioption to request) to forward the request to. Scheme is one ofcoap,coaps,coap+tcp,coaps+tcp,coap+ws, andcoaps+ws.-T tokenβ define the initial starting token for the request (up to24characters).-Uβ never includeUri-HostorUri-Portoptions.-V numβ the verbosity level to use (default3, maximum is7) for (D)TLS library logging.-X sizeβ maximum message size to use for TCP based connections (default is8388864). Maximum value of2^32 -1.
π¦ OPTIONS - DTLS π¦
(If supported by underlying (D)TLS library)
-d countβ for DTLS, enable use of Connection-ID (RFC9176). If thecountis not0, then the client changes its source port everycountpackets to test CID. π₯
π OPTIONS - PSK π
(If supported by underlying (D)TLS library)
-h match_hint_fileβ this is a file that contains one or more lines of received Identity Hints to match to use different user identity and associated pre-shared key (PSK) (comma separated) instead of the-k keyand-u useroptions. E.g., per line:
hint_to_match,use_user,with_key
A line that starts with # is treated as a comment. π
π‘ Note:-k keyand-u userstill need to be defined for the default case in case there is no match.
-k keyβ pre-shared key for the specified user identity (-uoption also required).
If the key begins with 0x, then the hex text (two [0-9a-f] per byte) is converted to binary data.
-u userβ user identity to send for pre-shared key mode (-koption also required).-2β use EC-JPAKE negotiation (if supported). π«Ά
π₯ OPTIONS - PKI π₯
(If supported by underlying (D)TLS library)
π‘ Note: if any one ofcertfile,keyfileorcafileis in PKCS11 URI naming format (pkcs11:prefix), then any remaining non PKCS11 URI file definitions have to be in DER, not PEM, format. Otherwise all ofcertfile,keyfileorcafileare in PEM format.
-c certfileβ PEM file or PKCS11 URI for the certificate. The private key can also be in the PEM file, or has the same PKCS11 URI. If not, the private key is defined by-j keyfile.-j keyfileβ PEM file or PKCS11 URI for the private key for the certificate in-c certfileif the parameter is different fromcertfilein-c certfile.-nβ disable remote peer certificate checking.-C cafileβ PEM file or PKCS11 URI for the CA certificate and any intermediate CAs that was used to sign the servercertfile. Ideally the client certificate should be signed by the same CA so that mutual authentication can take place. The contents ofcafileare added to the trusted store of root CAs. Using the-Cor-Roptions will trigger the validation of the server certificate unless overridden by the-noption. π-J pkcs11_pinβ the user pin to unlock access to the PKCS11 token.-M rpk_fileβ Raw Public Key (RPK) PEM file or PKCS11 URI that contains bothPUBLIC KEYandPRIVATE KEYor justEC PRIVATE KEY. (GnuTLS and TinyDTLS(PEM) support only).-C cafileor-R trust_casfileare not required. π-R trust_casfileβ PEM file containing the set of trusted root CAs that are to be used to validate the server certificate. Alternatively, this can point to a directory containing a set of CA PEM files. The-C cafileCA does not have to be in this list and is trusted for the validation. Using-R trust_casfiledisables common CA mutual authentication which can only be done by using-C cafile. Using the-Cor-Roptions will trigger the validation of the server certificate unless overridden by the-noption. π
β¨ EXAMPLES β¨
okay bestie, this is the part where it all clicks. real commands, real vibes, copy-paste away π
- Example
coap-client coap://libcoap.net
Hit up the resource / on the server libcoap.net β and yeah, that's using the GET method, because GET is literally the default main character here π
- Example
coap-client -m get coap://[::1]/
Ask for resource / on localhost with the GET method so you get the summary info back. lowkey the coziest way to check the server's doing fine π«Ά
- Example
coap-client -m get -P coap://upstream-proxy coap://[::1]/
Same energy, but now you're going through upstream-proxy β ask for resource / with the GET method and get that summary information back. it's giving "middle man but make it useful" β¨
- Example
coap-client -m get coap://%2Fsome%2Funix%2Fdomain%2Fpath/time
This one is so cool. You're asking for resource /time on a server that's listening on the datagram Unix domain /some/unix/domain/path, using the GET method so you get the current time back. and the %2F?? that's the hex encoding for / β it marks which slash is the host definition separator, while the plain / is the path definition separator. iykyk π§
- Example
coap-client -m get coap://[::1]/.well-known/core
Ask for resource .well-known/core on localhost and get back a whole list of the known resources, complete with their attribute definitions. it's the guest list of the server fr fr π
- Example
echo -n "mode=on" | coap-client -m put \
coap://[2001:db8:c001:f00d:221:2eff:ff00:2704]:5683/actuators/leds?color=r -f-
Sending the text mode=on to resource actuators/leds?color=r on the endpoint with address 2001:db8:c001:f00d:221:2eff:ff00:2704 and port 5683. and hey β 5683 is the default port, so it isn't actually required in this instance. not me including it anyway for the aesthetic π
- Example
coap-client -m put coap://[fec0::3]/ck -T 3a -t binary -f to_upload
Put the contents of the file to_upload into resource ck on fec0::3, with content type binary (that's application/octet-stream, bestie), using a token of 3a, via the PUT method. obsessed with how much this one line does πΈ
ποΈ FILES ποΈ
There are literally no configuration files. none. zero. nada. π¦
π¦ EXIT STATUS π¦
0β Success! slay, it worked π1β Failure. and to be clear, that covers: syntax or usage error; configuration error; document processing failure; or an unexpected error π
π SEE ALSO π
coap-server(5) and coap-oscore-conf(5) β go read those next, bestie π«Ά
π BUGS π
Found a bug? Please raise an issue on GitHub at https://github.com/obgm/libcoap/issues to report it π
Got a fix? Please raise a Pull Request at https://github.com/obgm/libcoap/pulls for any fixes. be the change you want to see in the codebase β¨
π AUTHORS π
The libcoap project <libcoap-developers@lists.sourceforge.net> β the icons who made all this happen π
and that's a wrap!! this page was brought to you by coap-client version 4.3.5, dated 08/24/2026, filed under COAP-CLIENT(5) πβ¨ go forth and query, bestie π
π¦ where this page comes from
- ubuntu stonking: libcoap3-bin 4.3.5-4ubuntu1 Β· BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms