├── .gitignore ├── coap-cheatsheet.pdf ├── README.md ├── LICENSE └── coap-cheatsheet.tex /.gitignore: -------------------------------------------------------------------------------- 1 | *.aux 2 | *.log 3 | *.out 4 | 5 | -------------------------------------------------------------------------------- /coap-cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crash/coap-cheatsheet/master/coap-cheatsheet.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A cheatsheet for the Constrained Application Protocol (CoAP). 2 | 3 | This document is giving the most important information of CoAP, like 4 | options, codes, etc. in a compressed cheatsheet format. 5 | 6 | ## The current version uses the following drafts/RFCs: 7 | (http://tools.ietf.org/html/rfc6690 "RFC6690") 8 | (http://tools.ietf.org/html/rfc7252 "RFC7252") 9 | (http://tools.ietf.org/html/draft-ietf-core-block-17 "core-block-17") 10 | (http://tools.ietf.org/html/draft-ietf-core-observe-16 "core-observe-16") 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Markus Becker 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 21 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /coap-cheatsheet.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4,10pt,landscape]{article} 2 | \usepackage{multicol} 3 | \usepackage{calc} 4 | \usepackage{ifthen} 5 | \usepackage[landscape]{geometry} 6 | \usepackage{amsmath,amsthm,amsfonts,amssymb} 7 | \usepackage{color,graphicx,overpic} 8 | \usepackage{hyperref} 9 | \usepackage[defaultsans]{droidsans} 10 | \usepackage[defaultmono]{droidmono} 11 | \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be typewriter style 12 | \usepackage[T1]{fontenc} 13 | 14 | 15 | \pdfinfo{ 16 | /Title (coap-cheatsheet.pdf) 17 | /Creator (LaTeX) 18 | /Author (Markus Becker) 19 | /Subject (CoAP) 20 | /Keywords (CoAP)} 21 | 22 | % This sets page margins to .5 inch if using letter paper, and to 1cm 23 | % if using A4 paper. (This probably isn't strictly necessary.) 24 | % If using another size paper, use default 1cm margins. 25 | \ifthenelse{\lengthtest { \paperwidth = 11in}} 26 | { \geometry{top=.25in,left=.25in,right=.25in,bottom=.25in} } 27 | {\ifthenelse{ \lengthtest{ \paperwidth = 297mm}} 28 | {\geometry{top=.5cm,left=.5cm,right=.5cm,bottom=.5cm} } 29 | {\geometry{top=.5cm,left=.5cm,right=.5cm,bottom=.5cm} } 30 | } 31 | 32 | % Turn off header and footer 33 | \pagestyle{empty} 34 | 35 | % Redefine section commands to use less space 36 | \makeatletter 37 | \renewcommand{\section}{\@startsection{section}{1}{0mm}% 38 | {-1ex plus -.5ex minus -.2ex}% 39 | {0.5ex plus .2ex}%x 40 | {\normalfont\large\bfseries}} 41 | \renewcommand{\subsection}{\@startsection{subsection}{2}{0mm}% 42 | {-1ex plus -.5ex minus -.2ex}% 43 | {0.5ex plus .2ex}% 44 | {\normalfont\normalsize\bfseries}} 45 | \renewcommand{\subsubsection}{\@startsection{subsubsection}{3}{0mm}% 46 | {-1ex plus -.5ex minus -.2ex}% 47 | {1ex plus .2ex}% 48 | {\normalfont\small\bfseries}} 49 | \makeatother 50 | 51 | % Define BibTeX command 52 | \def\BibTeX{{\rm B\kern-.05em{\sc i\kern-.025em b}\kern-.08em 53 | T\kern-.1667em\lower.7ex\hbox{E}\kern-.125emX}} 54 | 55 | % Don't print section numbers 56 | \setcounter{secnumdepth}{0} 57 | 58 | 59 | \setlength{\parindent}{0pt} 60 | \setlength{\parskip}{0pt plus 0.5ex} 61 | 62 | %My Environments 63 | \newtheorem{example}[section]{Example} 64 | % ----------------------------------------------------------------------- 65 | 66 | \begin{document} 67 | \raggedright 68 | \footnotesize 69 | \begin{multicols}{3} 70 | 71 | 72 | % multicol parameters 73 | % These lengths are set only within the two main columns 74 | %\setlength{\columnseprule}{0.25pt} 75 | \setlength{\premulticols}{1pt} 76 | \setlength{\postmulticols}{1pt} 77 | \setlength{\multicolsep}{1pt} 78 | \setlength{\columnsep}{1pt} 79 | 80 | \begin{center} 81 | \Large{\underline{Constrained Application Protocol}} \\ 82 | {\tiny 83 | (RFC 6690, RFC7252, draft-ietf-core-block-17, 84 | draft-ietf-core-observe-16) 85 | } 86 | \end{center} 87 | 88 | The Constrained Application Protocol (CoAP) is a specialized web 89 | transfer protocol for use with constrained nodes and constrained 90 | (e.g., low-power, lossy) networks. 91 | 92 | \section{CoAP Message Format} 93 | {\tiny 94 | \begin{verbatim} 95 | 0 1 2 3 96 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 97 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 98 | |Ver| T | TKL | Code | Message ID | 99 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 100 | | Token (if any, TKL bytes) ... 101 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 102 | | Options (if any) ... 103 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 104 | |1 1 1 1 1 1 1 1| Payload (if any) ... 105 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 106 | \end{verbatim} 107 | Ver: Version, T: Type, TKL: Token Length 108 | } 109 | 110 | \section{Message types} 111 | {\tiny 112 | \begin{verbatim} 113 | +------+-----------------+ 114 | | Type | Name | 115 | +------+-----------------+ 116 | | 0 | CONfirmable | 117 | | 1 | NON-confirmable | 118 | | 2 | ACKnowledgement | 119 | | 3 | ReSeT | 120 | +------+-----------------+ 121 | \end{verbatim} 122 | } 123 | 124 | \section{Method codes} 125 | {\tiny 126 | \begin{verbatim} 127 | +------+--------+ 128 | | Code | Name | 129 | +------+--------+ 130 | | 0.00 | EMPTY | 131 | +------+--------+ 132 | | 0.01 | GET | 133 | | 0.02 | POST | 134 | | 0.03 | PUT | 135 | | 0.04 | DELETE | 136 | +------+--------+ 137 | \end{verbatim} 138 | } 139 | 140 | \section{Response codes} 141 | 142 | {\tiny 143 | \begin{verbatim} 144 | 0 145 | 0 1 2 3 4 5 6 7 146 | +-+-+-+-+-+-+-+-+ 147 | |class| detail | 148 | +-+-+-+-+-+-+-+-+ 149 | \end{verbatim} 150 | } 151 | 152 | {\tiny 153 | \begin{verbatim} 154 | +------+--------------+ 155 | |Class | | 156 | +------+--------------+ 157 | | 2.xx | Success | 158 | | 4.xx | Client Error | 159 | | 5.xx | Server Error | 160 | +------+--------------+ 161 | \end{verbatim} 162 | } 163 | 164 | {\tiny 165 | \begin{verbatim} 166 | +------------+------------------------------+ 167 | | Code | Description | 168 | +------------+------------------------------+ 169 | | 2.01 (65) | Created | 170 | | 2.02 (66) | Deleted | 171 | | 2.03 (67) | Valid | 172 | | 2.04 (68) | Changed | 173 | | 2.05 (69) | Content | 174 | | 4.00 (128) | Bad Request | 175 | | 4.01 (129) | Unauthorized | 176 | | 4.02 (130) | Bad Option | 177 | | 4.03 (131) | Forbidden | 178 | | 4.04 (132) | Not Found | 179 | | 4.05 (133) | Method Not Allowed | 180 | | 4.06 (134) | Not Acceptable | 181 | | 4.12 (140) | Precondition Failed | 182 | | 4.13 (141) | Request Entity Too Large | 183 | | 4.15 (143) | Unsupported Content-Format | 184 | | 5.00 (160) | Internal Server Error | 185 | | 5.01 (161) | Not Implemented | 186 | | 5.02 (162) | Bad Gateway | 187 | | 5.03 (163) | Service Unavailable | 188 | | 5.04 (164) | Gateway Timeout | 189 | | 5.05 (165) | Proxying Not Supported | 190 | +------------+------------------------------+ 191 | \end{verbatim} 192 | } 193 | 194 | \section{Options} 195 | {\tiny 196 | \begin{verbatim} 197 | +-----+----+---+---+---+----------------+--------+--------+-------------+ 198 | | No. | C | U | N | R | Name | Format | Length | Default | 199 | +-----+----+---+---+---+----------------+--------+--------+-------------+ 200 | | 1 | x | | | x | If-Match | opaque | 0-8 | (none) | 201 | | 3 | x | x | - | | Uri-Host | string | 1-255 | (see note 1)| 202 | | 4 | | | | x | ETag | opaque | 1-8 | (none) | 203 | | 5 | x | | | | If-None-Match | empty | 0 | (none) | 204 | | 7 | x | x | - | | Uri-Port | uint | 0-2 | (see note 1)| 205 | | 8 | | | | x | Location-Path | string | 0-255 | (none) | 206 | | 11 | x | x | - | x | Uri-Path | string | 0-255 | (none) | 207 | | 12 | | | | | Content-Format | uint | 0-2 | (none) | 208 | | 14 | | x | - | | Max-Age | uint | 0-4 | 60 | 209 | | 15 | x | x | - | x | Uri-Query | string | 0-255 | (none) | 210 | | 17 | x | | | | Accept | uint | 0-2 | (none) | 211 | | 20 | | | | x | Location-Query | string | 0-255 | (none) | 212 | | 35 | x | x | - | | Proxy-Uri | string | 1-1034 | (none) | 213 | | 39 | x | x | - | | Proxy-Scheme | string | 1-255 | (none) | 214 | | 60 | | | x | | Size1 | uint | 0-4 | (none) | 215 | +-----+----+---+---+---+----------------+--------+--------+-------------+ 216 | \end{verbatim} 217 | C=Critical, U=Unsafe, N=No-Cache-Key, R=Repeatable \\ 218 | Note 1: taken from destination address/port of request message 219 | } 220 | 221 | \section{Content-Formats} 222 | {\tiny 223 | \begin{verbatim} 224 | +--------------------------+-----+ 225 | | Media type | Id. | 226 | +--------------------------+-----+ 227 | | text/plain;charset=utf-8 | 0 | 228 | | application/link-format | 40 | 229 | | application/xml | 41 | 230 | | application/octet-stream | 42 | 231 | | application/exi | 47 | 232 | | application/json | 50 | 233 | | application/cbor | 60 | 234 | +--------------------------+-----+ 235 | \end{verbatim} 236 | } 237 | 238 | \section{URI schemes} 239 | {\tiny 240 | \begin{verbatim} 241 | coap-URI = "coap:" "//" host [ ":" port ] path-abempty [ "?" query ] 242 | coaps-URI = "coaps:" "//" host [ ":" port ] path-abempty [ "?" query ] 243 | \end{verbatim} 244 | } 245 | 246 | \section{Transmission parameters} 247 | {\tiny 248 | \begin{verbatim} 249 | +-------------------+---------------+ 250 | | name | default value | 251 | +-------------------+---------------+ 252 | | ACK_TIMEOUT | 2 seconds | 253 | | ACK_RANDOM_FACTOR | 1.5 | 254 | | MAX_RETRANSMIT | 4 | 255 | | NSTART | 1 | 256 | | DEFAULT_LEISURE | 5 seconds | 257 | | PROBING_RATE | 1 Byte/second | 258 | +-------------------+---------------+ 259 | \end{verbatim} 260 | } 261 | 262 | \section{Link Format .well-known/core} 263 | 264 | Link format can be used to describe hosted resources, their 265 | attributes, and other relationships between links. 266 | 267 | Example: 268 | {\tiny 269 | \begin{verbatim} 270 | REQ: GET /.well-known/core 271 | 272 | RES: 2.05 Content 273 | 274 | ;ct=40;title="Sensor Index", 275 | ;rt="temperature-c";if="sensor", 276 | ;rt="light-lux";if="sensor", 277 | ;anchor="/sensors/temp";rel="describedby", 278 | ;anchor="/sensors/temp";rel="alternate" 279 | \end{verbatim} 280 | } 281 | 282 | ABNF: 283 | {\tiny 284 | \begin{verbatim} 285 | Link = link-value-list 286 | link-value-list = [ link-value *[ "," link-value ]] 287 | link-value = "<" URI-Reference ">" *( ";" link-param ) 288 | link-param = ( ( "rel" "=" relation-types ) 289 | / ( "anchor" "=" DQUOTE URI-Reference DQUOTE ) 290 | / ( "rev" "=" relation-types ) 291 | / ( "hreflang" "=" Language-Tag ) 292 | / ( "media" "=" ( MediaDesc 293 | / ( DQUOTE MediaDesc DQUOTE ) ) ) 294 | / ( "title" "=" quoted-string ) 295 | / ( "title*" "=" ext-value ) 296 | / ( "type" "=" ( media-type / quoted-mt ) ) 297 | / ( "rt" "=" relation-types ) 298 | / ( "if" "=" relation-types ) 299 | / ( "sz" "=" cardinal ) 300 | / ( link-extension ) ) 301 | link-extension = ( parmname [ "=" ( ptoken / quoted-string ) ] ) 302 | / ( ext-name-star "=" ext-value ) 303 | ext-name-star = parmname "*" ; reserved for RFC-2231-profiled 304 | ; extensions. Whitespace NOT 305 | ; allowed in between. 306 | ptoken = 1*ptokenchar 307 | ptokenchar = "!" / "#" / "$" / "%" / "&" / "'" / "(" 308 | / ")" / "*" / "+" / "-" / "." / "/" / DIGIT 309 | / ":" / "<" / "=" / ">" / "?" / "@" / ALPHA 310 | / "[" / "]" / "^" / "_" / "`" / "{" / "|" 311 | / "}" / "~" 312 | media-type = type-name "/" subtype-name 313 | quoted-mt = DQUOTE media-type DQUOTE 314 | relation-types = relation-type 315 | / DQUOTE relation-type *( 1*SP relation-type ) DQUOTE 316 | relation-type = reg-rel-type / ext-rel-type 317 | reg-rel-type = LOALPHA *( LOALPHA / DIGIT / "." / "-" ) 318 | ext-rel-type = URI 319 | cardinal = "0" / ( %x31-39 *DIGIT ) 320 | LOALPHA = %x61-7A ; a-z 321 | quoted-string = 322 | URI = 323 | URI-Reference = 324 | type-name = 325 | subtype-name = 326 | MediaDesc = 327 | Language-Tag = 328 | ext-value = 329 | parmname = 330 | \end{verbatim} 331 | } 332 | 333 | \section{Block} 334 | 335 | In order to transfer larger payloads with CoAP $-$ for instance, for 336 | firmware updates $-$ the Block option can be used. 337 | 338 | {\tiny 339 | \begin{verbatim} 340 | +-----+---+---+---+---+----------------+--------+--------+----------+ 341 | | No. | C | U | N | R | Name | Format | Length | Default | 342 | +-----+---+---+---+---+----------------+--------+--------+----------+ 343 | | 23 | x | x | - | - | Block2 | uint | 0-3 B | (none) | 344 | | 27 | x | x | - | - | Block1 | uint | 0-3 B | (none) | 345 | +-----+---+---+---+---+----------------+--------+--------+----------+ 346 | \end{verbatim} 347 | } 348 | {\tiny 349 | \begin{verbatim} 350 | 0 351 | 0 1 2 3 4 5 6 7 352 | +-+-+-+-+-+-+-+-+ 353 | | NUM |M| SZX | 354 | +-+-+-+-+-+-+-+-+ 355 | 356 | 0 1 357 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 358 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 359 | | NUM |M| SZX | 360 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 361 | 362 | 0 1 2 363 | 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 364 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 365 | | NUM |M| SZX | 366 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 367 | \end{verbatim} 368 | } 369 | 370 | \section{Observe} 371 | 372 | In order to follow state changes of CoAP resources the Observe option 373 | can be used. 374 | 375 | {\tiny 376 | \begin{verbatim} 377 | +-----+---+---+---+---+---------+------------+-----------+---------+ 378 | | No. | C | U | N | R | Name | Format | Length | Default | 379 | +-----+---+---+---+---+---------+------------+-----------+---------+ 380 | | 6 | | x | - | | Observe | uint | 0-3 B | (none) | 381 | +-----+---+---+---+---+---------+------------+-----------+---------+ 382 | \end{verbatim} 383 | } 384 | 385 | \section{References} 386 | This cheatsheet is based on and heavily stole from the following 387 | documents:\\ 388 | 389 | {\tiny 390 | Link-format: \url{http://tools.ietf.org/html/rfc6690}\\ 391 | CoAP: \url{http://tools.ietf.org/html/rfc7252}\\ 392 | Block: \url{http://tools.ietf.org/html/draft-ietf-core-block-17}\\ 393 | Observe: \url{http://tools.ietf.org/html/draft-ietf-core-observe-16}\\ 394 | } 395 | % You can even have references 396 | %\rule{0.3\linewidth}{0.25pt} 397 | %\scriptsize 398 | %\bibliographystyle{abstract} 399 | %\bibliography{refFile} 400 | \end{multicols} 401 | \end{document} 402 | --------------------------------------------------------------------------------