IOT NETWORKING
Welcome to the blog of Communication Protocols in IoT
IOT
What is IoT, Jul 16, 2021
The Internet of things (IoT) describes the network of physical objects—a.k.a. "things"—that are embedded with sensors, software, and other technologies for the purpose of connecting and exchanging data with other devices and systems over the Internet. In the consumer market, IoT technology is most synonymous with products pertaining to the concept of the "smart home".
Pretty much any physical object can be transformed into an IoT device if it can be connected to the internet to be controlled or communicate information.
In order to make an IoT device, the following are required:
- Embedded system - (normally a microcontroller) is required to interact with the physical object. It is responsible for collecting sensor data if any and controlling the object.
- Communication system - is required for sending collected data over the internet and to receive commands from the user to control the object.
The networking of the systems is an integral part of IoT. There are many different technologies that can be used to connect the different devices, for example:
- Cellular - GSM(Global Service for Mobile), 2G, 3G and 4G technologies.
- WiFi (Wireless-Fidelity) - utilizes the IEEE 802.11 standard through 2.4GhZ UHF(Ultra High Frequency)) and 5GhZ ISM(Industrial Scientific and Medical) frequencies
- Bluetooth - works on the same 2.4GHz UHF band as WiFi but it has a lower bandwidth. This encopmasses both the standard Bluetooth and BLE(Bluetooth Low Energy).
- Radio Frequency - Operate on the ISM RF bands. Protocols like ZigBee(IEEE 802.15.4 standard) or ZWave use a low-power RF radio embedded or retrofitted into electronic devices and systems.
- NFC (Near Field Communication) - operates on the unlicensed radio frequency ISM band of 13.56 MHz on ISO/IEC 18000-3 air interface. NFC involves an initiator and a target; the initiator actively generates an RF field that can power a passive target (an unpowered chip called a “tag”). It uses electromagnetic induction between two loop antennas located within each other’s near field, effectively forming an air-core transformer.
- LoRa (Long Range) - low-power spread spectrum modulation technique derived from chirp spread spectrum (CSS) technology.
Once the devices are interconnected, it is necessary for them to have a common "language" that all the devices in a given IoT ecosystem would share and be able to use for them to understand each other. Here is where the protocol comes in.
Communication protocols are formal descriptions of digital message formats and rules. They are required to exchange messages in or between computing systems. Some protocols used in IoT communication include:
- Raw sockets (UDP and TCP)
- HTTP (HyperText Transfer Protocol)
- MQTT (Message Queuing Telemetry Transport)
- CoAP (Constrained Application Protocol)
- XMPP (Extensible Messaging and Presence Protocol)
- AMQP (Advanced Message Queuing Protocol)
- LWM2M (Lightweight Machine to Machine)
- Websockets
The protocol defines how data is sent and received, but it does not define how the data is structured. This is done using a particular software architectural pattern. An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context. Examples include:
- REST(REpresentational State Transfer) API
- GraphQL API
- Falcor API
- JSON-Pure API
RAW UDP AND TCP
What is UDP and TCP, July 16, 2021
UDP(User Datagram Protocol) is a connectionless type of protocol such that the two communicating parties do not have to set up a connection before sending data among each other. The protocol is also very lightweight and speedy since its headers are very small (8 bytes). Though the protocol is not very reliable as it does not ensure the reception of sent packets.
TCP(Transport Control Protocol) is a connection oriented protocol such that the two parties have to set up a connection (using the three way handshake) before any data is sent between them. The headers are bigger than those of UDP at 20 bytes, making it slower and heavier. The protocol is reliable as it ensures delivery of packets.
UDP and TCP are transport layer protocols that provide applications with a way of packaging and sending data.
Normally, application layer protocols are built to rely on one of the two transport protocols. However, it is also possible to directly access raw data sockets that directly use the aforementioned transport layer protocols. This would involve making a custom application-layer protocol to define and differentiate between the requests and responses.
Other differences between UDP and TCP are illustrated below
REST API
What is a REST API, July 16, 2021
An API (Application Programming Interface) is a set of rules that defines how applications or devices can connect to and communicate with each other.
A REST or RESTful API is an API that conforms to the design principles of the REST, or representational state transfer architectural style. The only requirement is that they align to the following six REST design principles - also known as architectural constraints:
- Uniform Interface - All API requests for the same resource should look the same, no matter where the request comes from.
- Client-server decoupling - Client and server applications must be completely independent of each other with the only interaction being via the REST API.
- Statelessness - Each request needs to include all the information necessary for processing it.
- Cacheability - When possible, resources should be cacheable on the client or server side to improve performance and for scalability.
- Layered system architecture - The calls and responses go through different layers, and neither the client nor the server can tell whether it communicates with the end application or an intermediary.
- Code on Demand (optional) - In certain cases, responses may contain executable code (such as Java applets). In such cases, the code should only run on-demand.
When a RESTful API is called, the server will transfer to the client a representation of the state of the requested resource. The representation of the state can be in a JSON format, and probably for most APIs, this is indeed the case. It can also be in XML or HTML format.
REST is an architectural style which may use HTTP, FTP or other communication protocols but is widely used with HTTP.
REST doesn’t add any specific functionality to HTTP. But is an architectural style that was developed alongside HTTP and most commonly uses HTTP for its application layer protocol. REST was designed for communicating via HTTP requests to perform standard database functions like creating, reading, updating, and deleting records (also known as CRUD) within a resource.
HTTP
What is HTTP and how does it work, July 16, 2021
HTTP (HyperText Transfer Protocol) is a client-server application-layer protocol that was originally designed to provide a method for publishing and receiving HTML(HyperText Markup Language) pages on webservers.
HTTP functions as a request–response protocol in the client–server computing model using the TCP transport-layer protocol. The client is the application requesting for data or website (eg a web browser) while the server is the application hosting the data or website (the server provides responses to the requests it receives).
The main request methods or verbs defined in HTTP for exchanging data include:
- GET - retrieve data from the web server. This method requests that the target resource transfers a representation of its state.
- PUT - requests that the target resource creates or updates its state with the state defined by the representation enclosed in the request.
- POST - requests that the target resource processes the representation enclosed in the request according to the semantics of the target resource.
- DELETE - requests that the target resource deletes its state.
- PATCH - requests that the target resource modifies its state according to the partial update defined in the representation enclosed in the request.
When developing modern web-applications, the most commonly used application layer protocol is HTTP. It is suitable for serving hypermedia resources in a request-response fashion over the internet. However, when it comes to the Internet of things (IoT), it tends to perform poorly mainly because it was designed to be a reliable but heavy-weight protocol for the world-wide-web. The reasons behind its lack of suitability include:
- One-to-one communication - HTTP is designed for communication between 2 systems only at a time.
- Synchronous request-response - After requesting a resource to the server, the client has to wait for the server to respond. This blocks some system resources like threads, CPU cycles etc.
- Not designed for event-based communication - Most of the IoT applications are event based for example switching off a bulb.
- Scalability - HTTP connections utilize high system resources especially I/O threads. For every HTTP connection, the client/server has to open an underlying persistent TCP connection as well. The server's load increases with increasing devices.
- High Power Consumption - HTTP utilizes heavy system resources.
It is noted that the HTTP socket can be upgraded to a websocket to overcome the request-response limitation of HTTP. With a websocket, the server can send data at any time to the client without having to be requested for the data.
CoAP
What is CoAP, July 16, 2021
CoAP (Constrained Application Protocol) is a specialized web transfer protocol for use with constrained nodes and constrained networks in the Internet of Things. The protocol is designed for machine-to-machine (M2M) applications such as smart energy and building automation.
CoAP can be thought of like HTTP for IoTwith the main differences between HTTP and CoAP being:
- Instead of TCP, CoAP uses UDP.
- CoAP is a lot more light-weight due to its simplicity, and thus draws less power.
Like HTTP, CoAP is based on the wildly successful REST model: Servers make resources available under a URL, and clients access these resources using methods such as GET, PUT, POST, and DELETE.
CoAP is designed to easily translate to HTTP for simplified integration with the web, while also meeting specialized requirements such as multicast support, very low overhead, and simplicity.
CoAP has been designed to work on microcontrollers with as low as 10 KiB of RAM and 100 KiB of code space.
CoAP is designed to use minimal resources, both on the device and on the network.
- On the device, CoAP has been designed to work on microcontrollers with as low as 10 KiB of RAM and 100 KiB of code space.
- On the network, Instead of a complex transport stack, it gets by with UDP on IP. A 4-byte fixed header and a compact encoding of options enables small messages that cause no or little fragmentation on the link layer.
MQTT
What is MQTT, July 16, 2021
MQTT (Message Queuing Telemetry Transport) is a lightweight, publish-subscribe messaging transport protocol that is ideal for connecting remote devices with a small code footprint and minimal network bandwidth.
MQTT allows for messaging between device to cloud and cloud to device. This makes for easy broadcasting messages to groups of things. It makes use of a broker.
The MQTT broker is software running on a computer (running on-premises or in the cloud) which acts as a post office. MQTT doesn't use the address of the intended recipient but uses the subject line called “Topic”, and anyone who wants a copy of that message will subscribe to that topic. Multiple clients can receive the message from a single broker (one to many capability). Similarly, multiple publishers can publish topics to a single subscriber (many to one).
MQTT uses Transport Layer Security (TLS) encryption with user name, password protected connections, and optional certifications that requires clients to provide a certificate file that matches with the server’s. The clients are unaware of each other's IP address.
MQTT message types include: Connect, Disconnect and Publish.
MQQT offers QoS(Quality of Service) levels:
- At most once - fire and forget(no acknowledgements).
- At least once - acknowledged delivery(retry until acknowledged).
- Exactly once - assured delivery(two-level handshake to ensure only one copy of the message is received).
Alvyne Wamwea Mwaniki
Other Posts
Tags
IoT Internet of Things Networking Communication Protocols Internet Protocols