New BSD-licensed CoAP library

08 Oct 2013

Hi,

I wanted to use CoAP for DM and thought I'd use libcoap. After too long trying to understand how to use it, I got sick of wasting time so I wrote my own and made it work the way I expected libcoap to work:

	CoapPDU *pdu = new CoapPDU();
	pdu->setType(CoapPDU::COAP_CONFIRMABLE);
	pdu->setCode(CoapPDU::COAP_GET);
	pdu->setToken((uint8_t*)"\3\2\1\0",4);
	pdu->setMessageID(0x0005);
	pdu->setURI((char*)"test",4);

	// send packet 
	ret = send(sockfd,pdu->getPDUPointer(),pdu->getPDULength(),0);

...

	// receive packet
	ret = recvfrom(sockfd,&buffer,BUF_LEN,0,(sockaddr*)&recvAddr,&recvAddrLen);
	CoapPDU *recvPDU = new CoapPDU((uint8_t*)buffer,ret);
	if(recvPDU->validate()) {
		recvPDU->getURI(uriBuffer,URI_BUF_LEN,&recvURILen);
		...
	}

The focus of the library is on simplicity and allows the construction and parsing of CoAP PDUs to and from buffers.

Many embedded devices are going to have to process only a limited number of incoming and outgoing messages. For example a pump responding to on/off and sending it's status a few times per day. Clearly for such purposes, it isn't necessary to go overboard with a full stack that handles everything. Instead I only offer the ability to construct and parse CoAP PDUs. It is your job to send and receive the buffers.

The main project is hosted on github here:

https://github.com/staropram/cantcoap

Which contains an example client, call-back driven server, and test suite.

The goal for the example server is to respond to the ETSI plugtests hosted on http://coap.me

The mbed port of the library is here:

Import librarycantcoap

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

And an example (cellular) peer which just sits in a loop sending CoAP PUTs and printing the ACKs, can be found here:

Import programcantcoap_cellular_test

Simple client to illustrate the functionality of cantcoap library. The client sits in a while loop sending CoAP PUTs to a remote server and prints each acknowledgement.

This is in beta right now, expect it to evolve quite rapidly over the next few weeks.

Feedback would be especially welcome.

Cheers

Ashley