O'Reilly logo

Arduino Networking by Marco Schwartz

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sending data to Xively

We are now going to build the Arduino sketch for this project. The goal is to measure data on the Arduino board, connect with the Xively server, and send the data.

The first step is to include the following required libraries:

#include <SPI.h>
#include <Ethernet.h>
#include "DHT.h"

Enter the MAC address of your board:

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xFE, 0x40 };

We can then define the pin and the type of the DHT sensor as follows:

#define DHTPIN 7
#define DHTTYPE DHT11

Create an instance on the sensor, as shown in the following line:

DHT dht(DHTPIN, DHTTYPE);

Create an instance of the Ethernet client:

EthernetClient client;

We also define a default IP address for the board:

IPAddress ip(192,168,1,50);

In the sketch, we also ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required