Hardware Reference
In-Depth Information
it and put TextFinder inside. Restart Arduino, and the
TextFinder library should show up in the Sketch Import
Library menu. TextFinder lets you find a substring of text
from the incoming stream of bytes. It's useful for both
Ethernet and serial applications, as you'll see.
TextFinder is under consideration for inclusion in version
1.0 of Arduino, in which case you would not need to install
it. So check the Reference section of www.arduino.cc for
the latest updates.
Connect It
The program
starts out
by including the SPI and Ethernet
libraries, just as in the previous project.
Then define the output pins, the
minimum and maximum values for the
meter that you determined earlier, and
the time between HTTP requests using
constant integers.
/*
AirNow Web Scraper
Context: Arduino
*/
#include <SPI.h>
#include <Ethernet.h>
#include <TextFinder.h>
const int connectedLED = 2; // indicates a TCP connection
const int successLED = 3; // indicates a successful read
const int resetLED = 4; // indicates reset of Arduino
const int disconnectedLED = 5; // indicates connection to server
const int meterPin = 9; // controls VU meter
const int meterMin = 0; // minimum level for the meter
const int meterMax = 200; // maximum level for the meter
const int AQIMax = 200; // maximum level for air quality
const int requestInterval = 10000; // delay between updates to the server
Finding a Host's IP Address
This project uses numeric IP addresses rather than names. If you need to find a host's IP address, use the ping command
mentioned in Chapter 3. For example, if you open a command prompt and type ping -c 1 www.oreillynet.com , (use -n
instead of -c on Windows), you will get the following response, listing the IP address you need:
PING www.oreillynet.com (208.201.239.37): 56 data bytes
64 bytes from 208.201.239.37: icmp_seq=0 ttl=45 time=97.832 ms
If you can't use ping (some service providers block it, since it can be used for nefarious purposes), you can also use nslookup .
For example, nslookup google.com will return the following:
Server: 8.8.8.8
Address: 8.8.8.8#53
8 nslookup returns the Domain Name
Server it used to do the lookup as well.
Non-authoritative answer:
Name:
google.com
Address:
173.194.33.104
Any one of the addresses listed will point to it's associated name, so you can use any of them.
Search WWH ::




Custom Search