Testing CoAP services and devices
Maybe some of you have already built devices with CoAP support, or you want to integrate a CoAP-enabled service into your solution. Or maybe you heard about CoAP, the Constrained Application Protocol, and want to find out more about its inner workings, especially trying it out on some hardware/software playground.
Now what actually are good tools to learn about CoAP and to test services or devices? While developing slyft, we needed testing infrastructure to test our own code. At present, i see two approaches. Either your totally happy on the command line, or you want to look at a UI. Luckily, there are some tools around that fulfill both cases. Let’s look at the command line first.
CoAPs Web site has a implementation section which lists quite a number of frameworks and libraries that support coap. And some of them do offer command line tools, too.
One of them is CoAPThon, by G.Tanganelli, release as OSS under the MIT License. It is written in Python which makes it directly exectuable on OSX and Linux, Windows should work too if Python 2.7 is installed properly.
It comes with a number of command line tools that are installed in
/usr/local/bin/, amongst other things are
coapserver.py is what its name implies, a sample coap server application with a number of endpoints. It binds to all IP addresses on the host, so devices (or test services) can access it:
$ coapserver.py --help coapserver.py -i <ip address> -p <port> $ coapserver.py CoAP Server start on 0.0.0.0:5683 ['/basic', '/storage', '/child', '/separate', '/etag', '/', '/big', '/encoding', '/advancedSeparate', '/void', '/advanced', '/long', '/xml']
coapclient.py, you can send CoAP request to some service, specify methods, add payload etc:
$ coapclient.py —help Command: coapclient.py -o -p [-P] Options: -o, --operation= GET|PUT|POST|DELETE|DISCOVER|OBSERVE -p, --path= Path of the request -P, --payload= Payload of the request -f, --payload-file= File with payload of the request $ coapclient.py -o GET -p coap://127.0.0.1/basic Source: ('127.0.0.1', 5683) Destination: None Type: ACK MID: 40162 Code: CONTENT Token: None Payload: Basic Resource
i.e. execute the above command and look at the output of
Another tool from the ruby world comes with the
coap gem, offering a client with more or less the same options as CoAPThon’s:
$ gem install coap $ coap --help Usage: coap [options] <method> <uri> --content-format, -c <string> Content format. --debug, -d Extra debug output. --output, -o <target> Redirect payload output. Target can be "-" for STDOUT or a file path. --payload, -p <string> Payload for POST and PUT as string. --payload-file, -f <file> Read payload for POST and PUT from file. --type, -t <type> Message type (con, non, ack, rst).
And there is the
coaping gem to simply ping a coap service:
$ gem install coaping $ coaping (…) usage: coaping addr [port [timeout [ntry]]] (RuntimeError)
Thanks to Mathias Kovatsch, there is Copper, a plugin for Firefox. It can be easily installed within Firefox’s Add-On section. Just search for Copper or Copper (Cu) and install it. Every time you enter a CoAP url in the location bar (i.e. coap://127.0.0.1/ if you run the coapserver.py from above), you see a UI where you can inspect all details of CoAP requests and responses, and tinker with various settings.
For those of you interested in packet inspection, i’d suggest using Wireshark. Wireshark is a network protocol analyzer, it can capture and inspect network traffic. It also supports CoAP, meaning you can capture your CoAP traffic and look at various aspects of CoAP packets, inspecting them in great detail. This in conjunction with the CoAP spec should give you a good understanding of the protocol at the bits & bytes level.
Happy hacking! Andreas