From 003784db1dd48a2c846a3a65c45500fb487d7b18 Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Wed, 18 Sep 2013 23:31:58 +0100 Subject: [PATCH 1/9] More detail. --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0a4fa45..1895a50 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,18 @@ microcoap ========= -A miminal CoAP server implementation for microcontrollers. - -Written from the RFC, http://tools.ietf.org/html/draft-ietf-core-coap-18 +A toy CoAP server for microcontrollers. +See http://tools.ietf.org/html/draft-ietf-core-coap-18 Endpoint handlers are defined in endpoints.c * Arduino demo * POSIX (OS X/Linux) demo * GET/PUT/POST - * Probably not compliant - * Content Types in responses (ie. /.well-known/core as application/linkformat) - * No retry logic + + * No retries + * Piggybacked ACK only + For linux/OSX From 8ad399bafbf264f46b23994cbb4bb2d03d12323b Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Thu, 19 Sep 2013 00:57:09 +0100 Subject: [PATCH 2/9] Arduino /light demo --- Makefile | 2 +- README.md | 2 +- coap.c | 5 +++- coap.h | 17 +++++++++++--- endpoints.c | 64 +++++++++++++++++++++++++++++++++++---------------- microcoap.ino | 7 +++--- 6 files changed, 68 insertions(+), 29 deletions(-) diff --git a/Makefile b/Makefile index acbcf7e..8412c58 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ all: - gcc -Wall -o coap main-posix.c coap.c endpoints.c -DDEBUG + gcc -Wall -o coap endpoints.c main-posix.c coap.c -DDEBUG clean: rm -f coap diff --git a/README.md b/README.md index 1895a50..dffacd1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ See http://tools.ietf.org/html/draft-ietf-core-coap-18 Endpoint handlers are defined in endpoints.c - * Arduino demo + * Arduino demo (Uno + Ethernet shield, LED + 220R on pin 6, PUT "0" or "1" to /light) * POSIX (OS X/Linux) demo * GET/PUT/POST diff --git a/coap.c b/coap.c index c4448e2..28e3dc3 100644 --- a/coap.c +++ b/coap.c @@ -6,6 +6,7 @@ #include #include "coap.h" +extern void endpoint_setup(void); extern const coap_endpoint_t endpoints[]; #ifdef DEBUG @@ -355,5 +356,7 @@ int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_ return 0; } - +void coap_setup(void) +{ +} diff --git a/coap.h b/coap.h index 8fd4cb3..e1729bd 100644 --- a/coap.h +++ b/coap.h @@ -1,6 +1,10 @@ #ifndef COAP_H #define COAP_H 1 +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -89,7 +93,9 @@ typedef enum typedef enum { COAP_RSPCODE_CONTENT = MAKE_RSPCODE(2, 5), - COAP_RSPCODE_NOT_FOUND = MAKE_RSPCODE(4, 4) + COAP_RSPCODE_NOT_FOUND = MAKE_RSPCODE(4, 4), + COAP_RSPCODE_BAD_REQUEST = MAKE_RSPCODE(4, 0), + COAP_RSPCODE_CHANGED = MAKE_RSPCODE(2, 4) } coap_responsecode_t; //http://tools.ietf.org/html/draft-ietf-core-coap-18#section-12.3 @@ -120,11 +126,11 @@ typedef enum /////////////////////// typedef int (*coap_endpoint_func)(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo); - +#define MAX_SEGMENTS 2 // 2 = /foo/bar, 3 = /foo/bar/baz typedef struct { int count; - const char *elems[]; + const char *elems[MAX_SEGMENTS]; } coap_endpoint_path_t; typedef struct @@ -144,6 +150,11 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt); void coap_dump(const uint8_t *buf, size_t buflen, bool bare); int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, coap_responsecode_t rspcode, coap_content_type_t content_type); int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt); +void coap_setup(void); +void endpoint_setup(void); +#ifdef __cplusplus +} #endif +#endif diff --git a/endpoints.c b/endpoints.c index 9540a2c..b0fcce1 100644 --- a/endpoints.c +++ b/endpoints.c @@ -2,42 +2,66 @@ #include #include "coap.h" +#ifdef ARDUINO +#include "Arduino.h" + +static int led = 6; +void endpoint_setup(void) +{ + pinMode(led, OUTPUT); +} +#else +#include +void endpoint_setup(void) +{ +} +#endif + static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}}; static int handle_get_well_known_core(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { - static char *rsp = ""; + static char *rsp = ""; return coap_make_response(scratch, outpkt, (const uint8_t *)rsp, strlen(rsp), id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT); } -static const coap_endpoint_path_t path_hello = {1, {"hello"}}; -static int handle_get_hello(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) +static const coap_endpoint_path_t path_light = {1, {"light"}}; +static int handle_get_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { - static char *rsp = "Hello World"; + static char *rsp = "1"; return coap_make_response(scratch, outpkt, (const uint8_t *)rsp, strlen(rsp), id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN); } -static int handle_put_hello(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) +static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { - static uint8_t rspbuf[32]; // FIXME, re-entrancy - size_t len; - // respond with "Hello " + payload - memcpy(rspbuf, "Hello ", 6); - len = inpkt->payload.len; - if (len + 6 + 1 > sizeof(rspbuf)) - len = sizeof(rspbuf) - (6 + 1); - memcpy(rspbuf + 6, inpkt->payload.p, len); - rspbuf[len + 6] = 0; - - return coap_make_response(scratch, outpkt, (const uint8_t *)rspbuf, len + 6 + 1, id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN); + if (inpkt->payload.len == 0) + return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, COAP_RSPCODE_BAD_REQUEST, COAP_CONTENTTYPE_TEXT_PLAIN); + if (inpkt->payload.p[0] == '1') + { +#ifdef ARDUINO + digitalWrite(led, HIGH); +#else + printf("ON\n"); +#endif + return coap_make_response(scratch, outpkt, (const uint8_t *)"1", 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN); + } + else + { +#ifdef ARDUINO + digitalWrite(led, LOW); +#else + printf("OFF\n"); +#endif + return coap_make_response(scratch, outpkt, (const uint8_t *)"0", 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN); + } + } const coap_endpoint_t endpoints[] = { {COAP_METHOD_GET, handle_get_well_known_core, &path_well_known_core}, - {COAP_METHOD_GET, handle_get_hello, &path_hello}, - {COAP_METHOD_PUT, handle_put_hello, &path_hello}, - {0, NULL, NULL} + {COAP_METHOD_GET, handle_get_light, &path_light}, + {COAP_METHOD_PUT, handle_put_light, &path_light}, + {(coap_method_t)0, NULL, NULL} }; - diff --git a/microcoap.ino b/microcoap.ino index 54a1b0d..803fcf5 100644 --- a/microcoap.ino +++ b/microcoap.ino @@ -9,8 +9,6 @@ #include #include "coap.h" -#include "coap.c" - #define PORT 5683 static uint8_t mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02}; @@ -43,6 +41,9 @@ void setup() } Serial.println(); udp.begin(PORT); + + coap_setup(); + endpoint_setup(); } void udp_send(const uint8_t *buf, int buflen) @@ -82,7 +83,7 @@ void loop() } else { - udp_send(packetbuf, sizeof(packetbuf)); + udp_send(packetbuf, rsplen); } } } From a77ac2e5a7b0a8e6fa1336f8a8d8f4b86331c19a Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Thu, 19 Sep 2013 08:49:44 +0100 Subject: [PATCH 3/9] Bigger receive buffer. --- endpoints.c | 13 +++++++------ microcoap.ino | 13 ++++++++++--- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/endpoints.c b/endpoints.c index b0fcce1..881200a 100644 --- a/endpoints.c +++ b/endpoints.c @@ -2,6 +2,8 @@ #include #include "coap.h" +static char light = '0'; + #ifdef ARDUINO #include "Arduino.h" @@ -27,8 +29,7 @@ static int handle_get_well_known_core(coap_rw_buffer_t *scratch, const coap_pack static const coap_endpoint_path_t path_light = {1, {"light"}}; static int handle_get_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { - static char *rsp = "1"; - return coap_make_response(scratch, outpkt, (const uint8_t *)rsp, strlen(rsp), id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN); + return coap_make_response(scratch, outpkt, (const uint8_t *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_TEXT_PLAIN); } static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) @@ -37,26 +38,26 @@ static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpk return coap_make_response(scratch, outpkt, NULL, 0, id_hi, id_lo, COAP_RSPCODE_BAD_REQUEST, COAP_CONTENTTYPE_TEXT_PLAIN); if (inpkt->payload.p[0] == '1') { + light = '1'; #ifdef ARDUINO digitalWrite(led, HIGH); #else printf("ON\n"); #endif - return coap_make_response(scratch, outpkt, (const uint8_t *)"1", 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN); + return coap_make_response(scratch, outpkt, (const uint8_t *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN); } else { + light = '0'; #ifdef ARDUINO digitalWrite(led, LOW); #else printf("OFF\n"); #endif - return coap_make_response(scratch, outpkt, (const uint8_t *)"0", 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN); + return coap_make_response(scratch, outpkt, (const uint8_t *)&light, 1, id_hi, id_lo, COAP_RSPCODE_CHANGED, COAP_CONTENTTYPE_TEXT_PLAIN); } - } - const coap_endpoint_t endpoints[] = { {COAP_METHOD_GET, handle_get_well_known_core, &path_well_known_core}, diff --git a/microcoap.ino b/microcoap.ino index 803fcf5..148b6ce 100644 --- a/microcoap.ino +++ b/microcoap.ino @@ -14,8 +14,8 @@ static uint8_t mac[] = {0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02}; EthernetClient client; EthernetUDP udp; -uint8_t packetbuf[UDP_TX_PACKET_MAX_SIZE]; -static uint8_t scratch_raw[16]; +uint8_t packetbuf[256]; +static uint8_t scratch_raw[32]; static coap_rw_buffer_t scratch_buf = {scratch_raw, sizeof(scratch_raw)}; void setup() @@ -59,11 +59,19 @@ void loop() int sz; int rc; coap_packet_t pkt; + int i; if ((sz = udp.parsePacket()) > 0) { udp.read(packetbuf, sizeof(packetbuf)); + for (i=0;i Date: Thu, 2 Jan 2014 13:35:51 +0100 Subject: [PATCH 5/9] Option length calculation fixed according to coap-18 Fixed an incorrect use of the option length parameter to calculate option delta values > 13. According to CoAP draft 18 section 3.1, both len and delta can have values greater than 13. A quick test for 13 < len < 269 was performed using libcoap. --- coap.c | 40 ++++++++++++++++++++++++++++++---------- coap.h | 3 ++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/coap.c b/coap.c index 28e3dc3..6994cbc 100644 --- a/coap.c +++ b/coap.c @@ -82,37 +82,57 @@ int coap_parseToken(coap_buffer_t *tokbuf, const coap_header_t *hdr, const uint8 int coap_parseOption(coap_option_t *option, uint16_t *running_delta, const uint8_t **buf, size_t buflen) { const uint8_t *p = *buf; - uint8_t len; - uint16_t delta; + uint8_t headlen = 1; + uint16_t len, delta; - if (buflen < 1) // too small + if (buflen < headlen) // too small return COAP_ERR_OPTION_TOO_SHORT_FOR_HEADER; delta = (p[0] & 0xF0) >> 4; len = p[0] & 0x0F; // These are untested and may be buggy - if (len == 13) + if (delta == 13) { - if (buflen < 2) + headlen++; + if (buflen < headlen) return COAP_ERR_OPTION_TOO_SHORT_FOR_HEADER; delta = p[1] + 13; p++; } else - if (len == 14) + if (delta == 14) { - if (buflen < 3) + headlen += 2; + if (buflen < headlen) return COAP_ERR_OPTION_TOO_SHORT_FOR_HEADER; delta = ((p[1] << 8) | p[2]) + 269; p+=2; } else + if (delta == 15) + return COAP_ERR_OPTION_DELTA_INVALID; + + if (len == 13) + { + headlen++; + if (buflen < headlen) + return COAP_ERR_OPTION_TOO_SHORT_FOR_HEADER; + len = p[1] + 13; + p++; + } + else + if (len == 14) + { + headlen += 2; + if (buflen < headlen) + return COAP_ERR_OPTION_TOO_SHORT_FOR_HEADER; + len = ((p[1] << 8) | p[2]) + 269; + p+=2; + } + else if (len == 15) return COAP_ERR_OPTION_LEN_INVALID; - else - if (len > 12) - return COAP_ERR_OPTION_TOO_BIG; if ((p + 1 + len) > (*buf + buflen)) return COAP_ERR_OPTION_TOO_BIG; diff --git a/coap.h b/coap.h index e1729bd..5373c68 100644 --- a/coap.h +++ b/coap.h @@ -120,7 +120,8 @@ typedef enum COAP_ERR_OPTION_TOO_BIG = 7, COAP_ERR_OPTION_LEN_INVALID = 8, COAP_ERR_BUFFER_TOO_SMALL = 9, - COAP_ERR_UNSUPPORTED = 10 + COAP_ERR_UNSUPPORTED = 10, + COAP_ERR_OPTION_DELTA_INVALID = 11, } coap_error_t; /////////////////////// From 717029e7af159df654c4fd843dffdafc630e731c Mon Sep 17 00:00:00 2001 From: Jan-willem De Bleser Date: Mon, 6 Jan 2014 08:32:43 +0100 Subject: [PATCH 6/9] Dynamically build CoRE discovery response at setup --- coap.h | 1 + endpoints.c | 59 +++++++++++++++++++++++++++++++++++++++++++++------- main-posix.c | 2 ++ 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/coap.h b/coap.h index 5373c68..623ecb2 100644 --- a/coap.h +++ b/coap.h @@ -139,6 +139,7 @@ typedef struct coap_method_t method; coap_endpoint_func handler; const coap_endpoint_path_t *path; + const char *core_attr; } coap_endpoint_t; diff --git a/endpoints.c b/endpoints.c index 881200a..2689658 100644 --- a/endpoints.c +++ b/endpoints.c @@ -1,28 +1,32 @@ #include -#include +#include #include "coap.h" static char light = '0'; +const uint16_t rsplen = 1500; +static char rsp[1500] = ""; +void build_rsp(void); + #ifdef ARDUINO #include "Arduino.h" - static int led = 6; void endpoint_setup(void) { pinMode(led, OUTPUT); + build_rsp(); } #else #include void endpoint_setup(void) { + build_rsp(); } #endif static const coap_endpoint_path_t path_well_known_core = {2, {".well-known", "core"}}; static int handle_get_well_known_core(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt, uint8_t id_hi, uint8_t id_lo) { - static char *rsp = ""; return coap_make_response(scratch, outpkt, (const uint8_t *)rsp, strlen(rsp), id_hi, id_lo, COAP_RSPCODE_CONTENT, COAP_CONTENTTYPE_APPLICATION_LINKFORMAT); } @@ -60,9 +64,50 @@ static int handle_put_light(coap_rw_buffer_t *scratch, const coap_packet_t *inpk const coap_endpoint_t endpoints[] = { - {COAP_METHOD_GET, handle_get_well_known_core, &path_well_known_core}, - {COAP_METHOD_GET, handle_get_light, &path_light}, - {COAP_METHOD_PUT, handle_put_light, &path_light}, - {(coap_method_t)0, NULL, NULL} + {COAP_METHOD_GET, handle_get_well_known_core, &path_well_known_core, "ct=40"}, + {COAP_METHOD_GET, handle_get_light, &path_light, "ct=0"}, + {COAP_METHOD_PUT, handle_put_light, &path_light, NULL}, + {(coap_method_t)0, NULL, NULL, NULL} }; +void build_rsp(void) +{ + uint16_t len = rsplen; + const coap_endpoint_t *ep = endpoints; + int i; + + len--; // Null-terminated string + + while(NULL != ep->handler) + { + if (NULL == ep->core_attr) { + ep++; + continue; + } + + if (0 < strlen(rsp)) { + strncat(rsp, ",", len); + len--; + } + + strncat(rsp, "<", len); + len--; + + for (i = 0; i < ep->path->count; i++) { + strncat(rsp, "/", len); + len--; + + strncat(rsp, ep->path->elems[i], len); + len -= strlen(ep->path->elems[i]); + } + + strncat(rsp, ">;", len); + len -= 2; + + strncat(rsp, ep->core_attr, len); + len -= strlen(ep->core_attr); + + ep++; + } +} + diff --git a/main-posix.c b/main-posix.c index a47da43..dd73cf9 100644 --- a/main-posix.c +++ b/main-posix.c @@ -24,6 +24,8 @@ int main(int argc, char **argv) servaddr.sin_port = htons(PORT); bind(fd,(struct sockaddr *)&servaddr, sizeof(servaddr)); + endpoint_setup(); + while(1) { int n, rc; From ec21a26131cb6fb118415c3aa3df686c038d626f Mon Sep 17 00:00:00 2001 From: Daniel Vargas Date: Wed, 26 Feb 2014 03:00:19 -0300 Subject: [PATCH 7/9] go_build revised: inject options improved, observe option added. --- coap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++------------ coap.h | 2 ++ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/coap.c b/coap.c index 6994cbc..b211887 100644 --- a/coap.c +++ b/coap.c @@ -160,7 +160,7 @@ int coap_parseOptionsAndPayload(coap_option_t *options, uint8_t *numOptions, coa int rc; if (p > end) return COAP_ERR_OPTION_OVERRUNS_PACKET; // out of bounds - + //coap_dump(p, end - p); // 0xFF is payload marker @@ -268,6 +268,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) size_t i; uint8_t *p; uint16_t running_delta = 0; + // build header if (*buflen < 4) return COAP_ERR_BUFFER_TOO_SMALL; @@ -281,24 +282,44 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) buf[2] = pkt->hdr.id[0]; buf[3] = pkt->hdr.id[1]; + // http://tools.ietf.org/html/draft-ietf-core-coap-18#section-3.1 // inject options p = buf + 4; for (i=0;inumopts;i++) { - uint8_t delta; + uint8_t optDelta, len, delta = 0; + if (p-buf > *buflen) - return COAP_ERR_BUFFER_TOO_SMALL; - delta = pkt->opts[i].num - running_delta; - if (delta > 12) - return COAP_ERR_UNSUPPORTED; // FIXME - if (pkt->opts[i].buf.len > 12) - return COAP_ERR_UNSUPPORTED; // FIXME - *p++ = (delta << 4) | (pkt->opts[i].buf.len & 0x0F); - if ((p+pkt->opts[i].buf.len) - buf > *buflen) - return COAP_ERR_BUFFER_TOO_SMALL; + return COAP_ERR_BUFFER_TOO_SMALL; + optDelta = pkt->opts[i].num - running_delta; + coap_option_nibble(optDelta, &delta); + coap_option_nibble(pkt->opts[i].buf.len, &len); + + *p++ = (0xFF & (delta << 4 | len)); + if (delta == 13) + { + *p++ = (optDelta - 13); + } + else + if (delta == 14) + { + *p++ = ((optDelta-269) >> 8); + *p++ = (0xFF & (optDelta-269)); + } + if (len == 13) + { + *p++ = (pkt->opts[i].buf.len - 13); + } + else + if (len == 14) + { + *p++ = (pkt->opts[i].buf.len >> 8); + *p++ = (0xFF & (pkt->opts[i].buf.len-269)); + } + memcpy(p, pkt->opts[i].buf.p, pkt->opts[i].buf.len); p += pkt->opts[i].buf.len; - running_delta = delta; + running_delta = pkt->opts[i].num; } opts_len = (p - buf) - 4; // number of bytes used by options @@ -316,6 +337,22 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt) return 0; } +void coap_option_nibble(uint8_t value, uint8_t *nibble) +{ + if (value<13) + { + *nibble = (0xFF & value); + } + else + if (value<=0xFF+13) + { + *nibble = 13; + } else if (value<=0xFFFF+269) + { + *nibble = 14; + } +} + int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, coap_responsecode_t rspcode, coap_content_type_t content_type) { pkt->hdr.ver = 0x01; diff --git a/coap.h b/coap.h index 623ecb2..6d8db48 100644 --- a/coap.h +++ b/coap.h @@ -57,6 +57,7 @@ typedef enum COAP_OPTION_URI_HOST = 3, COAP_OPTION_ETAG = 4, COAP_OPTION_IF_NONE_MATCH = 5, + COAP_OPTION_OBSERVE = 6, COAP_OPTION_URI_PORT = 7, COAP_OPTION_LOCATION_PATH = 8, COAP_OPTION_URI_PATH = 11, @@ -152,6 +153,7 @@ int coap_build(uint8_t *buf, size_t *buflen, const coap_packet_t *pkt); void coap_dump(const uint8_t *buf, size_t buflen, bool bare); int coap_make_response(coap_rw_buffer_t *scratch, coap_packet_t *pkt, const uint8_t *content, size_t content_len, uint8_t msgid_hi, uint8_t msgid_lo, coap_responsecode_t rspcode, coap_content_type_t content_type); int coap_handle_req(coap_rw_buffer_t *scratch, const coap_packet_t *inpkt, coap_packet_t *outpkt); +void coap_option_nibble(uint8_t value, uint8_t *nibble); void coap_setup(void); void endpoint_setup(void); From 73252426377f276b0168918d8a27eeaa5df8a5a8 Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Tue, 29 Apr 2014 15:49:10 +0100 Subject: [PATCH 8/9] Works on Mega, works on Uno with tweaks. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 833d158..6f17761 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ See http://tools.ietf.org/html/draft-ietf-core-coap-18 Endpoint handlers are defined in endpoints.c - * Arduino demo (Uno + Ethernet shield, LED + 220R on pin 6, PUT "0" or "1" to /light) + * Arduino demo (Mega + Ethernet shield, LED + 220R on pin 6, PUT "0" or "1" to /light) * POSIX (OS X/Linux) demo * GET/PUT/POST * No retries From fc8144d5213de362601f02de0cd189dcdae7a28b Mon Sep 17 00:00:00 2001 From: Toby Jaffey Date: Wed, 2 Jul 2014 22:17:34 +0100 Subject: [PATCH 9/9] Tiny, but useful. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6f17761..3e2e24b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ microcoap ========= -A toy CoAP server for microcontrollers. +A tiny CoAP server for microcontrollers. See http://tools.ietf.org/html/draft-ietf-core-coap-18 Endpoint handlers are defined in endpoints.c