Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arduino Networking
Arduino Networking

Arduino Networking: Connect your projects to the Web using the Arduino Ethernet library

eBook
€11.99 €17.99
Paperback
€21.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Arduino Networking

Chapter 2. Sending Data to a Web Server

In the previous chapter, we made sure that your Arduino Ethernet shield could actually connect to your local network and to the Web. In this chapter, we are going to build on that, and build our first application using the Ethernet shield.

We are going to see in more detail how the Ethernet client works by measuring data from a digital sensor and sending this data to a web server. In this chapter, this web server will be a server running on your own computer.

These will be the major takeaways from this chapter:

  • First, we are going to choose the temperature and humidity sensor that we will also use later in the book. We are also going to install the different software components that are required for this chapter, especially the library to plot data on your computer.
  • Then, we are going to build the Arduino code that will perform measurements and send these measurements to the web server running on your computer.
  • After that, we'll start building...

Hardware and software requirements

On the hardware side, you will of course need the Arduino Uno board and Arduino Ethernet shield.

You will also need a sensor to measure some data. As this book is about how to use the Ethernet shield and not how to measure data from sensors, you can actually take any sensor of your choice.

I used a DHT11 sensor, which is a digital temperature and humidity sensor. I chose this sensor for this chapter and for many chapters of the book since it is a very cheap sensor and easy to interface with Arduino. Along with the DHT11 sensor, you will also need a 4.7k Ohm resistor.

You can also use other kind of sensors. You can use analog sensors, which return a signal depending on the measured data. For example, the TMP36 sensor is an analog temperature sensor that returns a voltage proportional to the ambient temperature.

Other kind of sensors you can use here are sensors based on the SPI or I2C protocols, which are digital communication protocols that are easy to use...

Sending data to a server

It is now time to build the sketch for our first application using the Arduino Ethernet shield. But first, we need one more piece of data: the local IP address of your computer. Inside the Arduino sketch, we are going to specify where the Arduino Ethernet shield has to send the data.

Finding your IP address is easy, but it depends on your operating system. If you are using OS X, you can find your IP address inside Network Preferences.

Sending data to a server

If you are using Windows, you will find the information you need under the Network Settings in your Control Panel:

Sending data to a server

Another way under Windows is to go to Start, then Run, and type cmd. Then, inside the console, type ipconfig and hit Enter. Your computer's IP address will be displayed.

If you are using Linux or OS X, you can simply go to a terminal and type:

ifconfig

This command should print your IP address inside the terminal window. It will in general be something like eth0 or en0. This is what I had on my machine:

en0: flags=8863...

Log incoming data in a database

In this section, we are going to use PHP to build the server-side part of the project. If you are a complete novice in PHP, I recommend the following resource to learn the basics of the language:

http://php.net/manual/en/tutorial.php

First, we are going to see the content of the datalogger.php file. This file will handle the requests coming from the Arduino board, log the data in a database, and answer with a simple message. Note that this file has to be in a folder named datalogger on your web server. We will see the important parts of the code. To get the complete code for this section, please refer to the GitHub repository of the chapter. Note that all the PHP code should be between the <php … ?> tags.

The file starts by receiving the data from the GET request sent by the Arduino Ethernet shield:

$temperature = intval($_GET["temp"]);
$humidity = intval($_GET["hum"]);

We also instantiate the connection with the SQLite database...

Displaying the results

We are now going to use the data that was logged in the database and display it on a graph for more convenience. For this task, we are going to use a JavaScript library called flot, which is already included in the code for this chapter. This library provides nice functions to plot data on a web page, and also allows you to plot data in real time, so you will see the graph being automatically updated as more data comes in.

Everything will happen inside an HTML file called plot.html. We will only see the most important parts of the code here. Please refer to the GitHub repository of the chapter to get the complete files. Inside this file, you first have to include the files required for the flot library:

<script src="flot/jquery.js"></script>
<script src="flot/jquery.flot.js"></script>
<script src="flot/jquery.flot.time.js"></script>

You also need an element in the HTML page that will host the graph. This...

Summary

In this second chapter of the book, we built our first application based on the Arduino Ethernet shield and Ethernet client class. We did some basic measurements on the Arduino board, sent these measurements on a local web server, and finally displayed this data in real time on a graph.

To proceed further with this chapter, I invite you to carefully repeat all the steps of this chapter to really understand well how the Arduino Ethernet shield communicates with the PHP code running on your computer. You can also add more sensors to the projects and log this data inside the database. Also, you can try to plot several variables at once on different graphs.

These were the major takeaways from this chapter:

  • First, we interfaced a digital temperature and humidity sensor to the Arduino board so that we can send the measurements to a local web server using the Ethernet shield. We also installed some useful software components such as a library to plot data in a web page.
  • Then, we built an Arduino...
Left arrow icon Right arrow icon

Description

This book is intended for those who want to build their own network-connected projects using the Arduino platform. You will be able to build exciting projects that connect to your local network and the Web. You will need to have some basic experience in electronics and web programming languages. You will also need to know the basics of the Arduino platform as the projects mainly deal with the networking aspects of the Arduino Ethernet shield.

What you will learn

  • Interface the Ethernet shield with Arduino and to your Ethernet router
  • Learn the basics of the Arduino Ethernet library
  • Grab the content of a web page using the Ethernet shield
  • Measure data and send it to a server running on your computer
  • Create a data logging station with a web server running on the Ethernet shield
  • Send measured data to the cloud service Xively, so it can be monitored from anywhere
  • Discover how to use the Temboo web service to connect the Ethernet shield to more cloud services

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 21, 2014
Length: 118 pages
Edition : 1st
Language : English
ISBN-13 : 9781783986866
Vendor :
Arduino
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Aug 21, 2014
Length: 118 pages
Edition : 1st
Language : English
ISBN-13 : 9781783986866
Vendor :
Arduino
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 79.97
Arduino Robotic Projects
€37.99
Arduino Networking
€21.99
Arduino Home Automation Projects
€19.99
Total 79.97 Stars icon

Table of Contents

7 Chapters
1. Discover the Arduino Ethernet Shield Chevron down icon Chevron up icon
2. Sending Data to a Web Server Chevron down icon Chevron up icon
3. Data Logging Station Chevron down icon Chevron up icon
4. Controlling Objects from Anywhere Chevron down icon Chevron up icon
5. Internet of Things with Xively Chevron down icon Chevron up icon
6. Logging Data in Google Docs Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.9
(9 Ratings)
5 star 44.4%
4 star 11.1%
3 star 33.3%
2 star 11.1%
1 star 0%
Filter icon Filter
Top Reviews

Filter reviews by




RAUL LOPEZ Mar 23, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Really, great guide for beginning in networking with arduino
Amazon Verified review Amazon
Alison Taylor Dec 17, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Partner very impressed with this
Amazon Verified review Amazon
Steve Spence Nov 12, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
As much fun as it is connecting sensors to an Arduino, and displaying data on a LCD, lighting LED's, or other local actions, the real power is when you connect to a network. Whether it's a local network and you are communicating between them or collecting data in a central database (Raspberry Pi), or connecting to the internet and contributing local weather data to a server, or broadcasting data with email or Twitter, even pulling down information like emails, tweets, or scraping other websites for data for local display, there's a lot of fun to be had.One book that explains how this all works, and gives you easy to replicate (and understand) projects is "Arduino Networking" by Marco Schwartz. This book delves into the abilities of network connectivity, explaining how and why it works, and leaves your mind swirling with new applications, and the ability to execute them. It's a must have on any maker's shelf!
Amazon Verified review Amazon
Stefan Buttigieg Sep 10, 2014
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is explained in a very clear and step-wise way which makes it extremely easy for anyone to follow from the Arduino Hobbyist beginner to the most experienced. Mr.Schwartz has proven to be over and over again with the release of other books on this subject matter to be trustworthy.
Amazon Verified review Amazon
W Boudville Oct 10, 2014
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
For many of you Arduino enthusiasts, the project you work on will need a way to connect your hardware to a network. As a practical matter, that network is likely to be your local network or the Internet. This text gives a means, using the Arduino Ethernet shield. The slender nature of the book hints at how straightforward this can be.Given the hardware, the steps in the text's examples show how to upload data, including how to plot this in a rudimentary way on a terminal window. Back to basics indeed. For debugging, this makes the mininum needed. No fancy interactions with a web server. At least initially. But the text then goes onwards, to explain to to hook up to a web server. Chapter 3 actually makes the web on the Arduino motherboard. Impressive use of the memory and CPU now commonly available in Arduino !Another key variant is later in the book, when it shows how to use a web server on the Internet to remotely control your device. The advantages and uses are manifold. Albeit with the requirement that the device needs to be accessible from the Internet.Happy tinkering.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.