CHAPTER 12 ■ IOT PLATFORMS
Figure 12-28. T e s t t r i g g e r
Code (Arduino)
Next you are going to write the code for connecting Arduino to the Internet using WiFi,
reading soil moisture sensor data, and publishing it to a Xively channel.
Start your Arduino IDE and type the code provided here or download it from the 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 five sections.
- External libraries
- Internet connectivity (WiFi)
- Read sensor data
- Xively (publish)
- Standard functions
External Libraries
The first section of code, as provided in Listing 12-1 , includes all the external libraries
required to run the code. This sketch has multiple dependencies—for Internet
connectivity you need to include the <WiFi.h> (assuming you are using a WiFi shield)
and for Xively connectivity, you need to include <HttpClient.h> and <Xively.h>. You
can download <Xively.h> from https://github.com/xively/xively_arduino.