Chat freely about anything...

User avatar
By lobaro
#35003 Hello everyone,

we just released our free CoAP stack ("lobaro-coap") to the esp8266 platform.
Our CoAP implementation was primary designed for embedded hardware platforms and easy usage.

Features are:
    * easy to use “C” CoAP stack
    * open source (MIT)
    * complete request/response logic
    * complete retry logic
    * piggybacked & separate reponses
    * prepared for sleeping server
    * runs on static memory are with own memory allocator
    * no need for FreeRTOS SDK (but should be no problem)
    * only one UDP socket internally used
    * wifi credentials can be set via CoAP on esp8266 softAP interface

Give it a try at (also with ready to test binaries):
http://www.lobaro.com/lobaro-coap-on-esp8266/
and
http://www.lobaro.com/lobaro-coap/

Any comments and feedback are highly appreciated! 8-)

Tobi
User avatar
By engineerscientist
#40267 Hi Tobi,

I have been using your library for the last couple of days and I have successfully managed to create a bunch of resources to handle all of the server slide elements for my project, however I have been having some difficulty creating a simple client side implementation, so I was hoping that you could point me to a simple example or perhaps provide some advice on how to best solve the issue.

So far I have used the 'CoAP_CreateMessage', 'CoAP_StartNewClientInteraction' and 'CoAP_SendMsg' methods however I don't appear to be receiving any messages on the server side, but given a simple example I am sure I could work it out.

I have looked though your website (cool products btw), but as far as I can tell there are only examples for server side implementations. Any assistance would be much appreciated, and thank you very much for all your hard work in creating the library.
User avatar
By lobaro
#40303 Hi!
Thanks for your feedback!

Have you tried the function "CoAP_StartNewGetRequest(...)"? It's a easy wrapper for the most common used functionality of "COAP GET" using the CoAP_StartNewClientInteraction function just internally.

Code: Select allCoAP_Result_t _rom CoAP_StartNewGetRequest(char* UriString, uint8_t ifID, NetEp_t* ServerEp, CoAP_RespHandler_fn_t cb) {

   CoAP_Message_t* pReqMsg = CoAP_CreateMessage(CON, REQ_GET, CoAP_GetNextMid(),NULL, 0,0, CoAP_GenerateToken());

   if(pReqMsg != NULL) {
      CoAP_AppendUriOptionsFromString(&(pReqMsg->pOptionsList), UriString);
      return CoAP_StartNewClientInteraction(pReqMsg, ifID, ServerEp, cb);
   }

   INFO("- New GetRequest failed: Out of Memory\r\n");

   return COAP_ERR_OUT_OF_MEMORY;
}


It should be used with an callback like this:

Code: Select allCoAP_Result_t sendRequestCB(CoAP_Message_t* pRespMsg, NetEp_t* Sender) {
   INFO("Callback to request received!\r\n");
   return COAP_OK;
}

void sendRequest() {
   //send to remote CoAP server at //fe80:0000:0000:0000:0211:7d00:0030:8e3f with Port 5683
   NetEp_t receiver = {.NetType = IPV6, .NetPort = 5683, .NetAddr.IPv6.u8 = IPv6_IP(0xfe800000, 0x00000000, 0x02117d00, 0x00308e3f)};
   //NetEp_t receiver = {.NetType = IPV4, .NetPort = 5683, .NetAddr.IPv4.u8 = {192,168,4,4}};
   CoAP_StartNewGetRequest("/battery-vcc", 0, &receiver,  sendRequestCB);
}


Please tell me if this helps :)
User avatar
By engineerscientist
#40310 Thanks for getting back so quickly, to be honest I hadn't tried that since I was looking for a PUT example so I kinda glazed over that, but thanks to your help I have now got that implemented and have the ESP sending GET requests to the server.
I think part of the reason I couldn't work it out was I didn't know that callbacks were available in C. I have only used them in Javascript, so I was rather confused by why there was method names but without the brackets, but that makes sense now.