Irrespective of how people and companies view IoT, everybody agrees that it will dwarf the internet we see today in very near future. Industry estimates that there will around 50 billion connected devices by 2020. With so many connected devices talking among themselves we need very robust protocols which will work in the real world
HTTP is the workhorse of the world wide web. Its the common standard according to which all the browsers communicate with all the servers. Can devices use HTTP for communication?
Usually HTTP runs on the top of TCP and has a big header
A bare minimum GET request for HTTP 1.1 is
GET / HTTP/1.1
The above request fetches the resource at ‘/’. Each new line character is 2 bytes long (CRLF) and the last line should be a new line character, so there is an overhead of 25 characters to fetch a single resource
The minimal reply is also similarly long, its
HTTP/1.1 200 OK
thats for replaying with a single character ‘a’. That is an overhead on 64 characters.
Each extra byte that needs to be transmitted incurs a cost on the battery life which is a very precious commodity for embedded devices
We have to keep in mind that all the data is passed as clear text without any encryption across the channel, HTTPS is used is used to overcome the problem of security but this adds another overhead of the SSL/TLS channel, handshake and certificate examination.
In the real world scenario where the communication channels and often unreliable and bandwidths limited, this much overhead is too much of a baggage.
Apart from that, HTTP essentially works under request response model, where clients can only push data to a server and there is no way for the server to connect back to the client unless the client also implements the server. This is an excellent way to get data from many and not the best when you want one to many communication moreover it would be impossible for a remote sensor to be aware of the events in real time.
So HTTP clearly cannot be used used and we need a protocol which is more suited for IoT.
Constrained Application Protocol (CoAP) is one such protocol which is designed for the constrained devices. The protocol extensively uses bit fields and mappings from strings to integers to reduce the number of bytes, moreover packets are easy to generate and can be parsed easily. It lets the clients get the updates in realtime by extending the HTTP request model and adding the ability to observe a resource.
CoRE, the group which designed the protocol has also defined mapping of CoAP with HTTP, this makes it easier to build proxies which will give access to CoAP resources via HTTP.