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

Committer:
sillevl
Date:
Tue Nov 17 16:44:39 2015 +0000
Revision:
29:62113a57353b
Parent:
19:6414961fb98d
added method to get the ip address

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dwini 8:0169da22e764 1 #pragma once
dwini 8:0169da22e764 2
dwini 8:0169da22e764 3 /*
dwini 8:0169da22e764 4 Waarom client per server
dwini 8:0169da22e764 5 Ten eerste moeten van een repons dan niet bepalen voor welke request hij juist was.
dwini 8:0169da22e764 6 Alles dat voor een bepaalde client / socket toekomt is voor die client.
dwini 8:0169da22e764 7 Dat betekent ook dat we niet eeuwig moeten wachten op een respons maar dat we async
dwini 8:0169da22e764 8 kunnen werken en werken met timeouts. We overlopen dan gewoon constant de clients die nog
dwini 8:0169da22e764 9 geen respons hebben gekregen.
dwini 8:0169da22e764 10 */
dwini 8:0169da22e764 11
dwini 8:0169da22e764 12 #include <string>
dwini 8:0169da22e764 13 #include <vector>
dwini 8:0169da22e764 14 #include "cantcoap.h"
dwini 8:0169da22e764 15 #include "coap.h"
dwini 10:77bd145ec06c 16 #include "response.h"
dwini 10:77bd145ec06c 17 #include "request.h"
dwini 8:0169da22e764 18
dwini 8:0169da22e764 19 enum Method;
dwini 8:0169da22e764 20
dwini 8:0169da22e764 21 class Client {
dwini 8:0169da22e764 22
dwini 8:0169da22e764 23 private:
dwini 8:0169da22e764 24 // ResourceRequest holding info of previous request
dwini 8:0169da22e764 25 struct ResourceRequest{
dwini 8:0169da22e764 26 uint32_t token_id;
dwini 8:0169da22e764 27 char* uri;
dwini 10:77bd145ec06c 28 void (*response_handler)(Request*, Response*); // Not sure if we need request and respons PDU's
dwini 8:0169da22e764 29 int method;
dwini 8:0169da22e764 30 CoapPDU * req_pdu;
dwini 8:0169da22e764 31 };
dwini 8:0169da22e764 32
dwini 8:0169da22e764 33 private:
dwini 8:0169da22e764 34 UDPSocket udp_socket;
dwini 8:0169da22e764 35 Endpoint coap_server; // One client per endpoint
dwini 8:0169da22e764 36 uint32_t new_token_id; // Matches requests and responses
dwini 8:0169da22e764 37 uint16_t new_message_id;
dwini 8:0169da22e764 38 std::string identifier; // Identifier is some trivial string used for console output
dwini 8:0169da22e764 39
dwini 8:0169da22e764 40 // List of unhandled previous requests
dwini 8:0169da22e764 41 std::vector<ResourceRequest> requests;
dwini 8:0169da22e764 42
dwini 8:0169da22e764 43 public:
dwini 8:0169da22e764 44 Client(const char * server, const int port, std::string identifier="Client");
dwini 8:0169da22e764 45
dwini 8:0169da22e764 46 public:
dwini 19:6414961fb98d 47 void sendRequest(char* uri, void (*response_handler)(Request*, Response*), CoapPDU::Code method);
dwini 8:0169da22e764 48 void checkForResponse(void);
dwini 8:0169da22e764 49
dwini 8:0169da22e764 50 };