Now that we are aware of the building blocks for a typical IoT solution, we will look at the two different types of architecture for building solutions, their pros and cons, and which setup is suitable for what application.
End-to-end architecture
Using cloud computing
Microsoft Azure defines cloud computing as:
In IoT, cloud computing is used when the devices talk directly to the cloud. Take a look at this IoT stack built using cloud computing:
The sensor data needs to reach the cloud finally. So, what means do we have? We can connect an Ethernet cable to our controller to talk to a router and then send the data via the router or use a Wi-Fi module to interface with a local router access point. We can also use a GSM module to send the data via a GSM network.
Pros and cons of using cloud computing in the IoT
Now let's quickly look at the pros and cons of this approach:
- Pros:
- If we have only one or two devices in an environment (for router-based communication)
- If devices are closely positioned to each router (for wireless and router-based communication)
- If the network strength of the SIM/GSM is better than good (for GSM-based communication)
- If the battery life of the smart device is not a factor, as both GSM and Wi-Fi modules consume high power (for wireless-based communication)
- Cons:
- If there is no internet access, these devices are literally dumb devices. No rules or schedules can be run on these devices if they are offline. No intelligence can be gathered.
- If more devices are connected in the same environment, then we may not have enough Ethernet ports on a router or the router capability to access more devices as Wi-Fi clients (for router-based communication).
- If the devices are far away from the router, they cannot contact the router or may struggle to keep their connection alive (for wireless and router-based communication).
- If a particular GSM network is patchy in an area, the connectivity with the cloud is a major issue, again making this device a dumb device till the internet comes on.
- GSM and Wi-Fi modules consume a lot of power and are not capable of running on a battery for long (not even 6 months).
The biggest issue among all this is the necessity for these devices to be always connected to the internet. If the network goes down, these devices will still function but the data they gather will be quite useless.
Imagine a smart home with about 40 to 50 smart devices deployed; here, all of them need to be connected to power at all times and moving them around might not be an option. Placing them at remote places where there is no power is a breaking factor. The distance between the Wi-Fi router and the device needs to be small.
In developing nations, both internet connectivity and power may be a challenge. This approach may not be a suitable approach for those nations.
These are some of the key challenges when working with cloud computing and IoT.
Now, let us look at fog computing.
Using fog computing
Fog computing, fog networking, or fogging is a computation paradigm where the cloud comes closer to the earth or the fog layer. This layer has the computational infrastructure needed to run most essential operations and has all the features that a typical cloud would have but runs locally.
The primary difference between cloud computing and fog computing is that the sensor/actuator network does not heavily rely on the internet to work.
Take a look at this IoT stack built using fog computing:
In the stack, the sensor nodes do not directly talk to the gateway. Instead, they talk to an Edge Router, which is responsible for locally collecting all the data from various sensors, and this Edge Router sends the data to the Cloud when the network is available.
We can think of the edge router as a mini-cloud which can execute almost all basic functions such as storing data, running rules, executing schedules, and managing the devices offline if the internet is not available.
Pros and cons of using fog computing in the IoT
Now let's quickly look at the pros and cons of this approach.
- Pros:
- Ideal for multiple devices connected to a network.
- The range between the edge router and hub is not a factor because these smart devices or edge nodes use long range or mesh-based communication.
- All the edge nodes run a protocol such as Bluetooth, Zigbee, or Z-Wave, which are power-efficient and can run a CR2032 battery for years together.
- The availability of the internet is not a factor for this smart network to work. The edge router is capable of taking on the role of a mini-cloud to emulate all its features.
- Cons:
- The biggest con in a system like this is the necessity for a consumer to buy an edge router even though they would like to use just one node
- Inventory management for an organization would be higher because they need to maintain multiple devices now
- The initial purchasing cost is on the higher side as the user needs to purchase the edge router along with the actual smart device
If we are looking at building a system where there are plenty of devices connected close to each other and they need to work seamlessly irrespective of the internet connection, then fog computing is better.
Edge computing
Do take a look at Edge Computing vs Fog Computing here: https://medium.com/@rshariffdeen/edge-computing-vs-fog-computing-5b23d6bb049d. This article talks about the subtle differences between fog- and edge-based computing.
Which is better?
Fog computing pushes intelligence towards the smart devices, reducing the amount of data that needs to go to the cloud and decreasing operational latency between the user and the smart device. Cloud computing is a centralized system that can scale on demand and can perform on-demand analysis in real time, among other things.
Here is a table from Cisco's blog, written by Maher Abdelshkour, explaining the differences between cloud and fog computing:
Another table with a high-level comparison follows:
To summarize, depending on the scale, cost, and real-time nature of the application you are planning to deploy, you can pick between cloud computing and fog computing.