Hardware Reference
In-Depth Information
if ($lastItem > $maxItems) {
$lastItem = $maxItems;
}
for($i=0;$i < $maxItems;++$i) { /* process items here */ }
As new stories are added, they do so at the beginning of the file. Should you want to capture everything, it is
consequently important to start at the end of the item list, as they will disappear sooner from the feed.
As mentioned earlier, the RSS contains only metadata, usually the title, description, and link to the full data. You
can retrieve these from each item through the data members:
$rss->items[$i]['link'];
$rss->items[$i]['title'];
$rss->items[$i]['description'];
They can then be used to build up the information in the manner you want. For example, to recreate the
information on your own home page, you would write the following:
$html .= "<a href=".$rss->items[$i]['link'].">".$rss->items[$i]['title']."</a>";
$html .= "<p>".$rss->items[$i]['description']."</p>";
Or you could use a speech synthesizer to read each title:
system("say default "+$rss->items[$i]['description']);
You can then use an Arduino that responds to sudden noises such as a clap or hand waving by a sensor (using a
potential divider circuit from Chapter 2, with a microphone and LDR, respectively) to trigger the full story.
You can also add further logic, so if the story's title includes particular key words, such as NASA , you can send the
information directly to your phone.
if (stristr($rss->items[$i]['title'], "nasa"))
system("sendsms myphone "+$rss->items[$i]['description']);
This can be particularly useful for receiving up-to-minute sports results, lottery numbers, or voting information
from the glut of reality TV shows still doing the rounds the world over. Even if it requires a little intelligent pruning
to reduce the pertinent information into 140 octets (in the United States) or 160 characters (in Europe, RSA, and
Oceania), which is the maximum length of a single unconcatenated text message, it will be generally cheaper than
signing up for the paid-for services that provide the same results.
Retrieving Data: Pull
This encompasses any data that is purposefully requested when it is needed. One typical example is the weather or
financial information that you might present at the end of the news bulletin. In these cases, although the information
can be kept up-to-date in real time by simulating a push technology, few people need this level of granularity—once
a day is enough. For this example, you will use the data retrieved from an online API to produce your own currency
reports. This can be later extended to generate currency conversion tables to aid your holiday financing since home
automation, as we've seen, doesn't stop at the front door. Even when you're abroad, you can make use of public data
sources to keep a check on your spending by performing currency conversion.
Search WWH ::




Custom Search