Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

CHAPTER 2 ■ INTERNET CONNECTIVITY



  1. As shown in Figure  2-16 , from Tools ➤ Port, select the port
    that says Arduino Yún.


Figure 2-16. Select the Arduino Yún port


Code (Arduino)


Now that your Arduino Yún is connected to a wireless network, you are going to write
the code that will allow your Arduino to send and receive data over the Internet. Since
Arduino Yún is already connected to the Internet, this is where the code will vary slightly.
Instead of adding code to connect, you will simply use the library <Bridge.h> to use the
wireless connection.
Start your Arduino IDE and either type the following code or download it from our
site and open it. All the code goes into a single source file ( *.ino ), but in order to make it
easy to understand and reuse it has been divided into three sections.



  • External libraries

  • Internet connectivity (Wireless)

  • Read sensor data


External Libraries....................................................................................................


The first section of the code as provided in Listing 2-11 includes all external libraries
required to run the code. For Arduino Yún, <Bridge.h> lets you access the already
established Internet connection. You are also going to use <Process.h> to print the
connection information. Your Arduino IDE has both these libraries installed.


Listing 2-11. External Libraries


#include <Bridge.h>
#include <Process.h>

Free download pdf