All Iot devices require a mechanism to send or receive data. There are numerous options available for connecting devices to the Internet, including wired and wireless options, Bluetooth, cellular networks, and many more. The option you choose depends on various factors, such as:
- Scale and size of the network where the application will run
- Amount of data that needs to be processed and transferred
- Physical location of the device
At the end of this chapter, you will be able to:
- Attach an Ethernet shield to Arduino and write Ethernet connectivity code
- Attach a WiFi shield to Arduino and write WiFi connectivity code
- Set up Arduino Yún to connect to WiFi
Internet Connectivity (Ethernet)
The second section of the code defines variables, constants, and functions that are going to be used for connecting to the Internet. As provided in Listing 2-2 , first you need to define the MAC address in the mac variable. For newer Ethernet shields, the MAC address might be printed on a sticker. You will also need to set a static IP address of Arduino for cases where it fails to get a dynamic IP from DHCP (Dynamic Host Configuration Protocol). Make sure the IP address you use is free, i.e., not currently in use by some other device on the network. Define the EthernetClient variable that will be used for connectivity.
Arduino Yún Wireless Connectivity (WiFi)
Yún is a more advanced model of Arduino that has been developed for the Internet of things. For beginners, Arduino Yún may be a little complex as compared to Arduino Uno, but it comes with built-in Ethernet and wireless capabilities so you do not need to buy additional shields
As mentioned in Chapter 1, this book uses Arduino Uno throughout. This section is only provided as a reference for readers who already have an Arduino Yún and still want to follow the real-life prototypes developed in this book. Even though Arduino Yún is not referenced in rest of the book, the code download contains Arduino Yún-compatible code as well.