Coap Client and Server

Dependencies:   DebugLib EthernetInterface cantcoap mbed-rtos

Dependents:   COAP coap

Fork of yeswecancoap by Sille Van Landschoot

YesWeCanCoap

Is a small coap client and server library for mbed based on the cantcoap library.

Import librarycantcoap

This is CoAP library with a focus on simplicity. It offers minimal CoAP PDU construction and decoding to and from byte buffers.

yeswecancoap server enables easy implementation of coap resources, each with a dedicated function. When the function is registered by the server, it will do the rest.

Coap server example

Repository: YesWeCanCoap-example

Coap client example

under construction

Revision:
6:0c477f5b79ff
Parent:
5:1924c60356d0
Child:
7:1bed29e1b0a4
diff -r 1924c60356d0 -r 0c477f5b79ff server.cpp
--- a/server.cpp	Wed Oct 21 08:25:17 2015 +0000
+++ b/server.cpp	Wed Oct 21 08:51:38 2015 +0000
@@ -32,7 +32,7 @@
     uint8_t token[TOKEN_BUFFER_SIZE];
     uint8_t tokenLength;
 
-    Request *req = new Request((uint8_t*)buffer,256, size);
+    CoapPDU *req = new CoapPDU((uint8_t*)buffer,256, size);
     if(req->validate()) {
         req->printHuman();
 
@@ -45,13 +45,13 @@
     for(int i = 0; i < resources.size(); i++){
         if(strcmp(uriBuffer, resources[i].uri) == 0){
                
-            Response *res = new Response();
+            CoapPDU *res = new CoapPDU();
             res->setType(Response::COAP_ACKNOWLEDGEMENT);
             res->setCode(Response::COAP_CONTENT);
             res->setMessageID(req->getMessageID());
             res->setToken(token,4);
             
-            resources[i].function(req, res);
+            resources[i].function((Request*)req, (Response*)res);
                     
             server.sendTo(client, (char*) res->getPDUPointer(),res->getPDULength());
             delete res;