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:
2:a03dd7e58d8f
Parent:
1:ab04e3d36ade
diff -r ab04e3d36ade -r a03dd7e58d8f server.cpp
--- a/server.cpp	Tue Oct 20 18:57:05 2015 +0000
+++ b/server.cpp	Tue Oct 20 20:19:21 2015 +0000
@@ -13,9 +13,14 @@
     server.bind(5683);
 }
 
-void Server::add(char* uri, void (*fnc)(Request), Method method)
+void Server::add(char* uri, void (*fnc)(Request*), Method method)
 {
-    this->fnc = fnc;
+/*    Resource res;
+    res.uri = uri;
+    res.function = fnc;
+    res.method = method;
+    resources.push_back(res);
+    printf("added resource to server: %s (%d), function*: %d\r\n", res.uri, res.function, res.method);*/
 }
 
 void Server::waitForRequest()
@@ -42,7 +47,29 @@
     }
     delete recvPDU;
     
+/*    printf("#resources: %d\r\n", resources.size());
+    
+    printf("test: %s\r\n", resources[0].uri);
+    printf("test: %s\r\n", resources[1].uri);*/
+    
+    for(int j=0; j < resources.size(); j++){
+        printf("...");
+        char* uri = (char*)resources.at(j).uri;
+        printf("finding uri: %s",uri);
+        if(strcmp(uriBuffer, uri) == 0){
+            printf(" OK");
+            Request* req = new Request();
+            fnc(req);
+            delete req;
+        }
+        printf("\r\n");
+    }
+    
     if(strcmp(uriBuffer, "/hello") == 0){
+        Request* req = new Request();
+        fnc(req);
+        delete req;
+        
         CoapPDU *pdu = new CoapPDU();
         pdu->setType(CoapPDU::COAP_ACKNOWLEDGEMENT);
         pdu->setCode(CoapPDU::COAP_CONTENT);