
382 MAKING THINGS TALK
void checkNetClient() {
// available() returns how many bytes have been received by the client:
if (client.available() > 0) {
// read a byte, convert it to a character, and add it to the string:
responseString +=char(client.read());
// add to a line of |'s on the screen (crude progress bar):
print("|");
}
// if there's no bytes available, either the response hasn't
// started yet, or it's done:
else {
// if responseString is longer than 0 bytes, the response has started:
if(responseString.length() > 0 ) {
// you've got some bytes, but now there's no more to read. Stop:
if(requestInProgress == true) {
// print the response:
println(responseString);
// note that the request is over:
requestInProgress = false;
// reset the string for future requests:
responseString = "";
}
}
}
}
Chapter 4
AIRNow Web Page Scraper
Language: PHP
Reads a web page and returns one line from it.
<?php
// url of the air quality index page for New York City:
$url =
'http://airnow.gov/index.cfm?action=airnow.showlocal&cityid=164';
$filePath = fopen ($url, "r"); // read the file at the URL
while (!feof($filePath)) // until the end of the file
{
$line = fgetss($filePath, 4096); // read each line
if ($readParticles == 1) { // previous was "observed at"