On Github Azdle / CoAPTalkSlides
Patrick Barrett / Applications Engineer
Hello, Me, Questions Audience: What do you want out of this? Engineer, "Lord Business", Hobbyist, C Lang, TCP/UDPPOST /api:v1/stack/alias HTTP/1.1 Host: m2.exosite.com X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909 Content-Type: application/x-www-form-urlencoded; charset=utf-8 Content-Length: 7 temp=26
HTTP/1.1 204 No Content Date: Thu, 05 Mar 2015 18:00:44 GMT Content-Length: 0 Server: nginx
GET /api:v1/stack/alias?temp HTTP/1.1 Host: m2.exosite.com X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909 Accept: application/x-www-form-urlencoded; charset=utf-8
HTTP/1.1 200 OK Date: Tue, 25 Aug 2015 05:43:42 GMT Server: nginx Connection: Close Content-Length: 7 temp=26
GET /api:v1/stack/alias?temp HTTP/1.1 Host: m2.exosite.com X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909 Accept: application/x-www-form-urlencoded; charset=utf-8 Request-Timeout: 300000 If-Modified-Since: 1440481217
HTTP/1.1 200 OK Date: Tue, 25 Aug 2015 05:43:42 GMT Server: nginx Connection: Close Content-Length: 7 Last-Modified: Tue, 25 Aug 2015 05:43:42 GMT temp=26
GET /api:v1/stack/alias?temp HTTP/1.1 Host: m2.exosite.com X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909 Accept: application/x-www-form-urlencoded; charset=utf-8 Request-Timeout: 300000 If-Modified-Since: 1440481217
HTTP/1.1 304 Not Modified Date: Tue, 25 Aug 2015 05:45:17 GMT Server: nginx Connection: Close
POST /api:v1/stack/alias HTTP/1.1 Host: m2.exosite.com X-Exosite-CIK: f6b2d8b26aa4a42f54eca858d509663e02a7b909 Content-Type: application/x-www-form-urlencoded; charset=utf-8 Content-Length: 7 temp=26
HTTP/1.1 204 No Content Date: Thu, 05 Mar 2015 18:00:44 GMT Content-Length: 0 Server: nginxThat may look short and sweet, but there's really a lot going on there just to say that the temperature is 26º. This just happens to be an API call to Exosite's (where I work) simple HTTP data API. Note that I said simple. We stripped out everything that we could to make the data use overhead as small as we could without breaking protocol. Lets look at it in a slightly different way just so we can see every byte that is there. ->
00000000: 50 4F 53 54 20 2F 61 70 69 3A 76 31 2F 73 74 61 POST /api:v1/sta 00000010: 63 6B 2F 61 6C 69 61 73 20 48 54 54 50 2F 31 2E ck/alias HTTP/1. 00000020: 31 0A 48 6F 73 74 3A 20 6D 32 2E 65 78 6F 73 69 1.Host: m2.exosi 00000030: 74 65 2E 63 6F 6D 0A 58 2D 45 78 6F 73 69 74 65 te.com.X-Exosite 00000040: 2D 43 49 4B 3A 20 61 33 32 63 38 35 62 61 39 64 -CIK: a32c85ba9d 00000050: 64 61 34 35 38 32 33 62 65 34 31 36 32 34 36 63 da45823be416246c 00000060: 66 38 62 34 33 33 62 61 61 30 36 38 64 37 0A 43 f8b433baa068d7.C 00000070: 6F 6E 74 65 6E 74 2D 54 79 70 65 3A 20 61 70 70 ontent-Type: app 00000080: 6C 69 63 61 74 69 6F 6E 2F 78 2D 77 77 77 2D 66 lication/x-www-f 00000090: 6F 72 6D 2D 75 72 6C 65 6E 63 6F 64 65 64 3B 20 orm-urlencoded; 000000A0: 63 68 61 72 73 65 74 3D 75 74 66 2D 38 0A 43 6F charset=utf-8.Co 000000B0: 6E 74 65 6E 74 2D 4C 65 6E 67 74 68 3A 20 37 0A ntent-Length: 7. 000000C0: 0A 74 65 6D 70 3D 32 36 .temp=26
00000000: 48 54 54 50 2f 31 2e 31 20 32 30 34 20 4e 6f 20 HTTP.....2.4.No. 00000010: 43 6f 6e 74 65 6e 74 44 61 74 65 3a 20 54 68 75 ContentDate:.Thu 00000020: 2c 20 30 35 20 4d 61 72 20 32 30 31 35 20 31 38 ...5.Mar.2..5..8 00000030: 3a 30 30 3a 34 34 20 47 4d 54 43 6f 6e 74 65 6e :..:44.GMTConten 00000040: 74 2d 4c 65 6e 67 74 68 3a 20 30 53 65 72 76 65 t.Length:..Serve 00000050: 72 3a 20 6e 67 69 6e 78 20 20 r:.nginx..That's a lot of bytes when all we're trying to say is "temp=26". So, how do we make this shorter? Well, we could remove some of the headers or make our own aliases for them. Maybe take this Content-Type header and say that our Content-Type is "urlenc". It's a lot shorter, but it's also not going to be understood by any software that wasn't written specfically for our APIs. Not good. So, what's a presenter to do with this obviously leading question? Why show you something much shorter and completely incomprehensible, of course.
00000000: 40 01 00 37 B2 31 61 04 74 65 6D 70 4D 07 A3 2C @..7.1a.tempM.., 00000010: 85 BA 9D DA 45 82 3B E4 16 24 6C F8 B4 33 BA A0 ....E.;..$l..3.. 00000020: 68 D7 h.
00000000: 60 44 00 37 `D.7Looking over at the little preview window, it's really not quite as clear what's going on just from looking. We can see somethings in there. Here there's "temp", there there's a "26". Oh, right we were trying to tell the server that temp=26 in the last slide, maybe that's what we're still doing. Yup. This packet contains all the same information and is doing the same thing that the last one did. But this one is using CoAP instead of HTTP. Not bad, we went from a total of NNN bytes for HTTP to just MM bytes for CoAP. So, that's cool. We just did some thing that we were already able to do, but with fewer bytes. Is that all? Just what is this CoAP thing anyway? Well, I'm glad that I'm assuming you're asking that.
The Constrained Application Protocol (CoAP) is a specialized web transfer protocol for use with constrained nodes and constrained (e.g., low-power, lossy) networks. The nodes often have 8-bit microcontrollers with small amounts of ROM and RAM, while constrained networks such as IPv6 over Low-Power Wireless Personal Area Networks (6LoWPANs) often have high packet error rates and a typical throughput of 10s of kbit/s. The protocol is designed for machine- to-machine (M2M) applications such as smart energy and building automation.
CoAP provides a request/response interaction model between application endpoints, supports built-in discovery of services and resources, and includes key concepts of the Web such as URIs and Internet media types. CoAP is designed to easily interface with HTTP for integration with the Web while meeting specialized requirements such as multicast support, very low overhead, and simplicity for constrained environments.
"web transfer protocol ... low-power .. 8-bit ... low-power again ... M2M"Like HTTP, but...
0 1 2 3 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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Ver| T | TKL | Code | Message ID | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Token (if any, TKL bytes) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Options (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1 1 1 1 1 1 1 1| Payload (if any) ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
00000000: 40 01 00 37 B2 31 61 04 74 65 6D 70 4D 07 A3 2C @..7.1a.tempM.., 00000010: 85 BA 9D DA 45 82 3B E4 16 24 6C F8 B4 33 BA A0 ....E.;..$l..3.. 00000020: 68 D7 h.
00000000: 60 44 00 37 `D.7Looking over at the little preview window, it's really not quite as clear what's going on just from looking. We can see somethings in there. Here there's "temp", there there's a "26". Oh, right we were trying to tell the server that temp=26 in the last slide, maybe that's what we're still doing. Yup. This packet contains all the same information and is doing the same thing that the last one did. But this one is using CoAP instead of HTTP. Not bad, we went from a total of NNN bytes for HTTP to just MM bytes for CoAP. So, that's cool. We just did some thing that we were already able to do, but with fewer bytes. Is that all? Just what is this CoAP thing anyway? Well, I'm glad that I'm assuming you're asking that.