Building Arduino Projects for the Internet of Things

(Steven Felgate) #1

CHAPTER 3 ■ COMMUNICATION PROTOCOLS


■ Note For hardware and software requirements and circuit instructions, refer to the


“Arduino Uno Wireless Connectivity (WiFi)” section in Chapter 2.


Code (Arduino)


Next you are going to write the code for connecting Arduino to the Internet using WiFi
and sending test data to a server using HTTP.
Start Arduino IDE and type the following code or download it from book’s site
and open it. All the code goes into a single source file ( *.ino ) in the same sequence as
provided here, but in order to make it easy to understand and reuse, it has been divided
into four sections.



  • External libraries

  • Internet connectivity (wireless)

  • Data publish (HTTP)

  • Standard functions


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


The first section of the code includes all external libraries required to run the code. Code
in this section is the same as Listing 2-6.


Internet Connectivity (Wireless)


The second section of the code defines variables, constants, and functions that are going
to be used for connecting to the Internet. Use the code from Listings 2-7 , 2-8 , and 2-9
(Chapter 2 ) here.


Figure 3-1. Hyper Text Transfer Protocol (HTTP)

Free download pdf