Internet of Things: Communication Models and APIs

Internet of Things: Communication Models and APIs

The Internet of Things is not a concept; it is a network, the true technology-enabled Network of all networks.” — Edewede Oriwoh

image.png

Source:- simplilearn.com

Internet of things, a term everyone knows but they are not aware of! Don't you think so? Many say the Internet of things is the future, many say it is a boon, but do we know actually what it is? Let's see what this term means and how important it is in our daily life.

IoT, aka the Internet of Things, is a fusion of two very important words. They are, Internet + Things = Internet of Things. So let's understand them one by one. Internet, this term is very very familiar to us, right? What is it? Internet stands for Interconnected Network. Internet is a massive global network of tablets, mobiles, laptops/PCs and servers. It is governed by specific protocols(Eg: TCP/IP suite). Just like Nokia connects people, the Internet connects servers around the world! The Internet is a way that allows people to ameliorate their lives.

yPXKyn.gif

Things, this word has many meanings in English Dictionary. What is the typical meaning? Thing is a word used to refer to a physical object, an action or idea, a situation or activity, in a case when one does not wish to be precise. Examples would be a bottle opener or an umbrella. But what is 'things' in IoT? Things are IoT devices having a unique identity. Things can be anything ranging from a thermostat on your wall to a freight container with a connected temperature sensor. IoT devices can exchange, collect, process the data either locally or by using cloud-based application backends. The 3 special words (SMA) related to IoT without which IoT is incomplete are sensing, monitoring and actuating(PS:- These functions are performed by Things in IoT).

By now, you must have understood that IoT consists of the Internet and Things. Now let's study IoT in brief.

Defining IoT

giphy (12).gif

Let me give you an existing cum unnecessarily lengthy definition of IoT:

"Internet of Things is the network of physical objects or ‘things’ embedded with electronics, software, sensors and connectivity to enable it to achieve greater value and service by exchanging data with the manufacturer, operator and/or other connected devices. Each thing is uniquely identifiable through its embedded computing system but is able to interoperate within the existing Internet infrastructure."

This is indeed very complex and Googlish ain't it? A person who doesn't know about IoT will definitely run away after reading this definition for sure😂. Instead of defining it to you, let me make you understand the term IoT for you. (PS:- Not a standard mugged up definition!). IoT is like spreading out the power of the Internet. It's about how we connect devices/things to the Internet to upgrade our daily life chores. Right now you are reading this article just because of the Internet, ignore the device been used. It's about picking every single thing in the world and connect those things to a universal global network called the Internet! IoT consists of an internetwork of devices and physical objects wherein a number of objects can gather the data at remote locations and communicate to units managing, acquiring, organising and analysing the data in the processes and services. It's like using the Internet to the fullest. Easy now ain't it?

Vision of IoT

giphy (13).gif

The vision of IoT is very simple. It is to make things smart/intelligent enough to make them function as if they are alive. Let me give you an example. Suppose I have an umbrella. If I want to know the weather report each morning what am I gonna do? Yes! I'm gonna embed a tiny device, which interacts with a web-based weather service and the device's owner (that is me) through the Internet the following communication can take place. A website regularly publishes the weather report. These reports will be received by my umbrella every morning and it will ping me alerts at intermittent intervals. These alerts/reminders can be demonstrated via LEDs. For example, If the weather is gonna be hot and sunny, the Yellow LED would glow. If the weather is gonna be rainy, the Blue LED would glow. The reminders would be sent to me(via text messages/Bluetooth) whether it is gonna rain or is it gonna be a sunny day. According to that, I can decide whether to carry or not to carry the umbrella using the Internet-connected umbrella. So simple ain't it?

image.png

Source:- www.iconfinder.com

Communication Models in IoT

Understanding how the different IoT devices communicate with each other is important and useful cause IoT devices are found almost everywhere now. Communication models are the way to understand it. IoTs enable people and things to be connected anytime, in any space, with anything and anyone, through any network and service.

Now let us understand the different communication models in IoT.

Request & Response Model

2.png

  • The communication takes place between a client and a server.

  • Whenever required, the client will request information from the server. This request is usually in the encoded format.

  • So in this model, basically a client sends requests to the server and the server responds to the requests. That is why it is called as Request-Response model.

  • After receiving the request from the client, the server decides how to respond, fetches the data from the database and its resource representation, prepares a response and ultimately sends the response to the client.

  • Request-Response model is a stateless model. Each request-response pair is independent of others.

  • Example is HTTP. HTTP operates as a query-response protocol between a client and a server. A web browser can be the client, and an application on a computer that supports a website can be the server. The client(browser) submits an HTTP request to the server and the server will return a response back to the client.

  • Other Example(s):- CoAP (Constrained Application Protocol)

Simple ain't it?

Publish-Subscribe Model(Pub-Sub)

image.png

Source:- slideshare.net

In this model, you will find three main entities:- Publisher, Broker and Consumer Let us see the roles of each of these 3 entities.

  • Publishers, send the data to the topics that are managed by the broker. They are the source of data.

  • The Man in the Middle, the Broker, has the responsibility to accept the data sent by the publisher and deliver that data to the consumers.

  • What is the task of the Consumers? Consumers will subscribe to the broker-managed topics.

  • Publishers aren't aware of who the consumers are.

  • Once the data is published on a topic, the broker sends this message to all consumers who have subscribed to the specific topic. It works a bit like YouTube. When you subscribe to a channel and tap the Bell icon, you'll get notifications if the YouTube channel posts a video.

A GOOD CHANCE TO SELF PROMOTE MY YOUTUBE CHANNEL😁.

SUBSCRIBE TO MY CHANNEL 👉🏻ELECTRONIC TECHNOCRAT👈🏻

  • Example(s):- MQTT (Message Queue Telemetry Transport), AMQP (Advanced Message Queue Protocol), DDS (Data Distribution Service).

Push-Pull Model

3.png

  • Here too, we have 3 entities:- Publisher, Queues and Consumers.

  • Push-Pull is a communication model where data producers push data into queues and consumers pull data out of queues.

  • What are Queues? They are used to separate out single producer-consumer communication.

  • At times, there might be some mismatch in the push-pull rates. Queues act as a buffer which helps in situations when there is a mismatch between the rate at which the producers push data and the rate at which the consumer pull data. So they work as a buffer and flow control mechanisms whenever there is any mismatch in the push-pull rates.

Exclusive Pair Model

4.png

  • It's a bi-directional, fully duplex communication model in which a dedicated communication link is set between the client and the server.

  • The connection remains open until the client sends a request to close the connection.

  • The client and server can send messages to one another after configuring the connection. As soon as the connection is terminated, no exchange of messages would take place between the client and the server.

  • The Server has the record of all the connections which has been opened.

  • This model is a stateful type.

  • Example(s):- Websockets.

What is Stateless and Stateful Protocols?

Stateless Protocol

  • It is a network model in which the client sends a request to the server and the server in return sends a response back according to the current state just like the Request-Response model.

  • The server is not obliged to keep the session information or the status of each communication partner for multiple requests.

  • They are very easy to implement on the Internet.

  • Stateless protocols work better when the crash occurs because no state needs to be restored, a failed server can simply reboot after a crash.

  • Examples:- HTTP (Hypertext Transfer Protocol), UDP (User Datagram Protocol), DNS (Domain Name System).

Stateful Protocol

  • In this protocol, suppose a client sends a request to the server and the server doesn't respond, then the client resends a request to the server.

  • Stateful protocols are logically heavy to implement on the Internet.

  • Stateful Protocol does not work better at the time of the crash because stateful servers must retain information about the state and session details of internal states.

  • Examples:- FTP (File Transfer Protocol), Telnet.

IoT Communication APIs

What are APIs?

  • An API is an interface used by programs to access an application.

  • It enables a program to send commands to another program and receive replies from the app.

  • IoT APIs are the interface points between an IoT device and the Internet and/or other network components.

Here we will talk about the REST-based API and the Websocket based API.

REST-based APIs

5.png

  • Representational state transfer (REST) is a set of architectural principles by which you can design Web services the Web APIs that focus on the system's resources and how resource states are addressed and transferred.

  • URIs(example:- example.com/api/tasks) are used to depict resources in the RESTful web service.

  • Client tries to access these resources via URIs using commands like GET, PUT, POST, DELETE and so on that are defined by HTTP.

  • In response, the server responds with a JSON object or XML file.

  • The REST APIs follow the request-response model.

The rest architectural constraints are as follows:

  • Client-server

Let me explain it to you by giving a suitable example. The client should not be concerned with the storage of data which is a concern of the server, similarly, the server should not be concerned about the user interface, which is the concern of the client. Separation makes it possible for the client and server to be developed and updated independently.

  • Stateless

The status of the session remains entirely on the client.

  • Cache-able

This property defines whether the response to any request can be cached or not. If a response can be cached, then a client cache is granted the right to reuse that response data for subsequent matching requests.

  • Layered system

A layered system defines the boundaries of the components within each specific layer. For example, A client is unable to tell whether it is connected to the end server or an intermediate node. As simple as that!

  • Uniform interface

This specifies that the technique of communication between a client and a server must be uniform throughout the communication period.

  • Code on Demand(Optional Constraint)

Servers may provide executable code or scripts for execution by clients in their context.

Websocket based APIs

6.png

  • Websocket APIs enable bi-directional and duplex communication between customers and servers.

  • Unlike REST, There is no need to set up a connection every now and then to send messages between a client and a server.

  • It works on the principle of the exclusive pair model. Can you recall it? Yes. Once a connection is set up, there is a constant exchange of messages between the client and the server. All we need is to establish a dedicated connection to start the process. the communication goes on unless the connection is terminated.

  • It is a stateful type.

  • Due to one time dedicated connection setup, there is less overhead, lower traffic and less latency and high throughput.

  • So Web socket is the most suitable IoT Communication APIs for IoT System.

I hope you understood what are the different IoT based Communication models and APIs. See you in the next article😀.

ty.gif

Did you find this article valuable?

Support Ninad Ingale by becoming a sponsor. Any amount is appreciated!