Reader small image

You're reading from  Arduino IoT Cloud for Developers

Product typeBook
Published inNov 2023
PublisherPackt
ISBN-139781837637171
Edition1st Edition
Right arrow
Author (1)
Muhammad Afzal
Muhammad Afzal
author image
Muhammad Afzal

Muhammad Afzal is a senior software engineer, with more than 14 years of experience working on web-based and IoT systems in multinational organizations. He always enjoys working and solving real-world business problems with technology. He provides freelance services to IoT-based product companies to write technical reviews and projects, and he also provides consultancy to organizations. In his free time, Muhammad creates videos and courses for YouTube and Udemy. He also runs a maker movement in his region for young students to boost their interest in adopting the latest technologies.
Read more about Muhammad Afzal

Right arrow

Enabling Communication between Different Devices

This chapter is dedicated to thing-to-thing communication (TTC), which is a very important concept and requirement in the field of the Internet of Things (IoT). You can also call it Device-to-Device (D2D) communication. D2D communication plays a vital role in complex systems where one device’s operations are totally dependent on another device. For example, say you want to control your room’s AC according to outdoor weather conditions; here, D2D communication plays a vital role by sending the outdoor temperature to the room’s AC controller device so it knows whether it needs to cool or heat the room according to the weather outside.

Arduino IoT Cloud provides a cloud variable synchronization feature across multiple things, as well as for dashboards, which helps us to build complex systems easily. This chapter explains the usage of the synchronization feature for the implementation of cloud graphical user interfaces...

Technical requirements

The following are required to complete this chapter’s exercise:

  • Complete Chapter 4 of this book
  • MKR Wi-Fi 1010
  • 1x 5 mm red LED and 1x 5 mm green LED
  • A breadboard
  • Jumper cables

We will use the Arduino Web Editor for coding, which includes a large collection of development boards and sensor libraries, and Arduino IoT Cloud for thing and dashboard setup. The chapter code is available in the official book GitHub repository by following this link: https://github.com/PacktPublishing/Arduino-IoT-Cloud-for-Developers.

What is D2D communication in the IoT cloud?

D2D communication in the context of IoT and the IoT cloud refers to the ability of IoT devices to directly exchange data or information with each other without relying on a central server or cloud-based service as an intermediary. This form of communication is also known as Peer-to-Peer (P2P) communication among IoT devices.

Here are some key points to understand about D2D communication in the IoT cloud:

  • Direct communication: In traditional IoT architectures, devices send data to a cloud platform, where it is processed and potentially shared with other devices. D2D communication allows devices to talk to each other directly, bypassing the cloud when necessary.
  • Low latency: D2D communication can reduce latency because data doesn’t have to travel to a remote server and back. This is crucial in applications where real-time or near-real-time responses are required, such as in industrial automation or connected vehicles.
  • ...

The benefits of Arduino IoT Cloud thing-to-thing communication

Arduino IoT Cloud is a platform that’s designed to simplify the development and management of IoT projects using Arduino boards and other compatible hardware. When it comes to TTC in the context of Arduino IoT Cloud, there are several benefits:

  • Ease of integration: Arduino IoT Cloud provides a user-friendly interface for connecting and configuring IoT devices, making it easier to establish communication between devices. Users can quickly set up and manage the connections between their Arduino boards and other IoT devices.
  • Remote control: You can use TTC to control one Arduino device from another. For example, you could use one Arduino device to control a light bulb in another room.
  • Scalability: Arduino IoT Cloud allows you to scale your IoT projects easily. You can add new devices to your network and configure their communication parameters without extensive programming, making it suitable for both...

Hardware components – sensors and development boards

In this chapter, we are going to explore how to sync cloud variables across multiple Arduino IoT Cloud things. So, here we will use the same thing, including a development board and sensors, that was used in Chapter 4. For this chapter’s demonstration, we are going to use Arduino MKR Wi-Fi 1010 along with two 5 mm LEDs, a red one and a green one. The complete project is summarized in Figure 7.1.

Figure 7.1 – Project architecture

Figure 7.1 – Project architecture

As shown in Figure 7.1, we use one WeMos D1 mini development board, which is based on ESP8266, and the whole project is demonstrated in Chapter 4. The purpose of using different types of boards in this chapter is to demonstrate how easy it is to sync the cloud variables across different types of development boards. In the next section, we will talk in detail about project architecture.

Project architecture

In this section, we will discuss how cloud variable synchronization works. As shown in Figure 7.1, we have taken the project from Chapter 4. In that project, we set up a device that monitors outdoor temperature, humidity, and air quality. Now, we want to share the outdoor temperature with our indoor device, which is the MKR Wi-Fi 1010. To make things easier, we just used LEDs with MKR Wi-Fi 1010, which is shown in Figure 7.2. Our indoor device will turn on the red LED if the temperature exceeds the specified threshold and turn on the green LED if it comes down below a specified threshold. You can also use relays instead of LEDs to control the heating and cooling system of your room.

We already have one complete thing in Arduino IoT Cloud that is working, but now we need to create another thing for MKR Wi-Fi 1010 named Indoor MKR Wi-Fi 1010 with a bunch of cloud variables. We will then sync the temperature cloud variable of the Indoor MKR Wi-Fi 1010 thing with...

Setting up a Thing

After setting up the hardware, it’s time to set up a thing in Arduino IoT Cloud. For this project, we need three cloud variables. Later on, we will associate MKR Wi-Fi 1010 with our thing. Next, we will perform the Wi-Fi network configuration. Figure 7.3 shows a complete overview of the Thing:

Figure 7.3 – Indoor device MKR Wi-Fi 1010 thing setup

Figure 7.3 – Indoor device MKR Wi-Fi 1010 thing setup

Set up a new thing called Indoor Device MKR Wi-Fi 1010. In Figure 7.3, the following steps are marked with red boxes. Follow these steps to create variables, associate a device, configure the network, and, finally, write the code:

  1. Firstly, we need to set up three cloud variables for the green LED, the red LED, and temperature (which will be synced with another thing cloud variable). A more detailed discussion of cloud variables is in the upcoming section.
  2. After that, we need to associate the device with the Thing. In the current project, we are using MKR Wi-Fi 1010...

Implementation of GUI using synchronized cloud variables

After uploading the code to the device, it’s time to set up a dashboard for web and mobile to visualize the data with different widgets. Figure 7.11 demonstrates the visualization of readings with different widgets.

Figure 7.11 – Thing dashboard

Figure 7.11 – Thing dashboard

We have three different readings, Temperature, Humidity, and Air Quality, from the Sense the Environment thing and two readings, RedLED and GreenLED, from the Indoor Device MKR Wi-Fi 1010 thing. As the temperature from the Indoor Device MKR Wi-Fi 1010 thing is synced with the Sense the Environment thing, we are only displaying one temperature value here. For every reading, we use different widget controls to demonstrate how they all work. But for the LED status, we used an LED widget control.

The main thing to note about this dashboard is that we are using values from two different things but the same dashboard to visualize the values. This...

Limitations of cloud variable/property synchronization

Arduino IoT Cloud offers a platform for IoT device management and communication, including TTC between devices. While it provides valuable features for connecting and managing IoT devices, there are some drawbacks to consider:

  • Latency: TTC can introduce latency, which is the delay between when a change is made to a variable on one device and when it is reflected on the other device. This can be a problem for applications that require very low latency, such as controlling a robot in real time.
  • Offline device challenges: Devices that are temporarily offline may miss important messages or updates from other devices. Ensuring that devices can catch up on missed communications when they reconnect to the network can be complex to implement.
  • Dependency on internet connectivity: Arduino IoT Cloud relies on an internet connection for communication between devices. If the internet connection goes down, the devices may lose...

What next?

We still have a lot of options available to explore, but now it’s your turn to use different sensors and development boards to do some more experiments and learn from them. In this chapter, we have only used one Temperature cloud variable synced between two things, but you can try using this feature to sync multiple cloud variables with multiple things. Next, create a dashboard for multiple things to visualize all the values in one place. We configured simple LEDs to turn on and off according to the temperature, but you can also use relays to control the heating/cooling system of your indoor home/office and warehouse environment, or you can create an alarm in case of a temperature increase using this TTC feature.

Summary

In this chapter, we explored D2D communication and the benefits of Arduino IoT Cloud for thing-to-thing communication. We discussed how to develop a solution for thing-to-thing communication. We also explored how easy it is to sync the cloud variable with other things just using a GUI. We set up a dashboard, where we linked the widget controls with multiple thing cloud variables. Finally, we discussed the limits of Arduino IoT Cloud thing-to-thing communication in detail.

In the next chapter, we are going to explore how to use the Arduino IoT Cloud SDK. This chapter is for developers who are eager to learn how to use Arduino IoT Cloud programmatically and develop custom solutions using Arduino IoT Cloud or integrate Arduino IoT Cloud with third-party platforms.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Arduino IoT Cloud for Developers
Published in: Nov 2023Publisher: PacktISBN-13: 9781837637171
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Muhammad Afzal

Muhammad Afzal is a senior software engineer, with more than 14 years of experience working on web-based and IoT systems in multinational organizations. He always enjoys working and solving real-world business problems with technology. He provides freelance services to IoT-based product companies to write technical reviews and projects, and he also provides consultancy to organizations. In his free time, Muhammad creates videos and courses for YouTube and Udemy. He also runs a maker movement in his region for young students to boost their interest in adopting the latest technologies.
Read more about Muhammad Afzal