1. Trang chủ
  2. » Công Nghệ Thông Tin

Apress - Smart Home Automation with Linux (2010)- P37 pdf

5 162 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Prelim

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewers

  • Acknowledgments

  • Introduction

  • Appliance Control

    • Making Things Do Stuff

    • X10

      • About X10

      • General Design

      • Simple Case

      • Standard Case

      • Fully Automated

      • Assigning Addresses

      • Using Multiple House Codes

      • Device Modules

      • Controlling Lights

        • Lamp Module (LM12U)

        • Bayonet Lamp Module (LM15EB)

        • Wall Switch (LW10U)

        • MicroModule with Dimmer (LWM1)

        • DIN Rail Dimmer (LD11)

        • Appliance MicroModule (AWM2)

      • Controlling Appliances

        • Appliance Module (AM12U)

        • Appliance MicroModule (AWM2)

      • Internal Devices

      • Combination Devices

        • Electronic Curtain Rails: Retrofit

        • Electronic Curtain Rails: Prebuilt

      • Stand-Alone Controllers

      • Tabletop Transmitter Modules

        • Mini Controller (MC460)

        • Sundowner Dusk/Dawn Controller (SD7233/SD533)

        • Mini Timer (MT10U)

        • Maxi Controller (SC2800)

      • Handheld Transmitter Modules

        • Handheld RF Remote (HR10U)

        • Keyfob Remote (KR22E)

        • EasyTouch Panel10 RF

        • EasyTouch35 Universal Remote Control

      • In-Wall Transmitter Modules

      • Motion Sensors

      • Gateways and Other Exotic Devices

      • Computer Control

      • Heyu

        • Configuration

        • Sending Messages

        • Receiving Messages

        • Programming the EEPROM

    • C-Bus

      • About C-Bus

      • Differences Between X10 and C-Bus

      • Devices

      • Controlling Lights

      • Controlling Appliances

      • Controllers

      • Gateways

    • Networked Devices

      • Ethernet Devices

      • Networking Primer

      • Concepts

      • Addressing

      • Computer Names

      • Network Services

      • CCTV Cameras

      • Wireless Cameras That Aren’t

      • Custom Hardware

      • Linux Software

      • Stand-Alone BitTorrent Clients

    • Infrared Remote Control

      • All-in-One Remotes

      • IR Relays

      • Over the Aerial Cable

      • IR-RF-IR Gateways

      • IR Over IP

      • IR Control

    • Conclusion

  • Appliance Hacking

    • Converting Existing Technology

    • Software Hacks

      • Linksys NSLU2

      • Unslung

      • SlugOS

      • Developing on the Slug

      • Hacking Game Consoles

      • Sega Dreamcast

      • Sony PlayStation

        • PlayStation 1

        • PlayStation 2

        • PlayStation Portable

      • Microsoft Xbox

        • Running Linux

        • Xbox Media Center

    • Hardware Hacks

      • Linksys NSLU2

      • Always On

      • Overclocking

      • Serial Port

      • LEGO Mindstorms

      • Arduino as an I/O Device

      • Installation and Setup

      • Arduino Software

        • Reading Digital Inputs

        • Reading Analog Inputs

        • Sending Digital Outputs

        • Sending Analog Outputs

        • Creating Audio Outputs

      • Communication with a PC

      • Arduino Hardware

        • Ethernet Networking

        • Wireless Control

        • Sound

        • Motors

      • Example: The Arduino Welcome Mat

      • Example: The Arduino Dictaphone

      • Joysticks for Input

      • Other Input Controllers

      • Hacking Laptops

      • Your Own X10 Devices

    • Conclusion

  • Media Systems

    • Incorporating the TV and the HiFi

    • The Data Chain

      • Extracting the Data

      • Compact Disc

      • DVD

        • Rip As ISO

        • Rip As Movie Files

        • Issues with Movies

      • Cassette Tapes and Vinyl

    • Storage

      • Stand-Alone NAS Systems

      • Hard Drive Considerations

      • Networking Considerations

      • Extra Functionality

      • NAS with Media Playback

      • Configuring a Linux Box

      • Preparing a Machine

      • Preparing a Filesystem

      • Preparing a Master Server

    • Media Extenders

      • Stand-Alone Hardware

      • Hauppauge MediaMVP

      • Creating a Server

      • MediaMVP Media Center

        • Weather Reports

        • Video Transcoding

        • Other Functionality

      • The Xtremer

      • Squeezebox

        • Server Software

        • Other Software

      • Emprex ME1

      • Just Linux

      • The Operating System

      • The Software

        • MythTV

        • Freevo

        • Xbox Media Center

        • The Video Disk Recorder Project

    • Distribution

      • Local Processing vs. Remote Processing

      • AV Distribution

      • Switching

      • Splitting and Merging

      • Wiring Looms

      • Wireless AV Distribution

      • Matrix Switchers

    • Control

      • Local Control

      • Remote-Control Methods

      • Direct Control

      • Relay Control

      • Server Control

        • A Web Interface

        • SMS

    • Conclusion

  • Home Is Home

    • The Physical Practicalities

    • Node0

      • Function and Purpose

      • Determining the Best Room

      • Lawful Considerations

      • Necessary Considerations

      • Negative Effects

      • Human Considerations

      • Primary Options

      • Building the Rack

    • Servers

      • Purposes of Servers

      • CPU Power

      • Disk Space

      • Server Extensibility

      • Bandwidth Capabilities

      • Types of Server

      • Rack Mount

      • Desktop PC

      • Mini-ITX

      • Mini-PC

      • Custom Embedded

      • Power Consumption

      • Server Coordination

      • UPS

      • Backups

      • Hiding Your Home

    • Adding to Your Home

      • General Considerations

      • Wired Network

      • Wireless Points

      • Audio Cabling

      • Other Access Points?

    • Conclusion

  • Communication

    • Humans Talk. Computers Talk.

    • Why Comms?

    • IP Telephony

      • Skype

      • Asterisk

    • E-mail

      • Preparing E-mail in Linux

      • Sending E-mail

      • Autoprocessing E-mails

      • Security Issues

    • Voice

      • The Software for Voice Recognition

      • Remote Voice Control

      • Speech Synthesis

      • Piecemeal Samples

    • Web Access

      • Building a Web Server

      • Virtual Sites

      • Secure Server

      • Controlling the Machine

      • Media Access

    • SMS

      • Processing with a Phone

      • Custom Numbers and APIs

      • Sending Messages

      • Receiving Messages

    • Conclusion

  • Data Sources

    • Making Homes Smart

    • Why Data Is Important

      • Legalities

      • Screen Scraping

      • Data Through APIs

      • Distribution

    • Public Data

      • TV Guides

      • Train Times

      • Road Traffic

      • Weather

      • Forecasts

      • Local Reporting

      • Radio

      • CD Data

      • News

      • Reported Stories: Push

      • Retrieving Data: Pull

    • Private Data

      • Calendar

      • Webmail

      • Twitter

      • Posting Tweets with cURL

      • Reading Tweets with cURL

      • Reading Tweets with RSS

      • Facebook

    • Automation

      • Timed Events

      • Periodic Control with Cron Jobs

      • Occasional Control with At

      • Error Handling

    • Conclusion

  • Control Hubs

    • Bringing It All Together

    • Integration of Technologies

    • The Teakettle: An Example

    • Minerva

      • Overview

      • Linux Users Are Not HA Users

      • The Minerva User

      • The Public User

      • Device Abstractions

      • Typical Application Abstractions

      • Monexec

      • TODO: A Worked Example

      • Conduits

      • Echo

      • Email

      • Infrared Remote Control

      • Logging

      • SMS

      • Twitter

      • The Voice Conduit

      • Web Log

      • Window Alert

      • Administering Conduits

      • Messaging Conduits

      • Output Conduits: Transmission

      • Input Conduits: Receiving Messages

      • TODO: Building a Conduit

      • Message Relays

      • Time-Based Messaging

      • Other Uses for MTS

      • Location-Based Messaging

      • Cosmic

      • Configuration

      • Creating Modes

      • Web Applets

      • Zinc: Between Web and Native

      • Of Web Pages and Applets

      • Existing Applets

        • Media

        • Lifestyle

        • Information

        • Administration

      • Creating Your Own Applets

        • The WARP Directories

        • The Components of WebFace

        • The Basic Structure

        • TODO: Controlling the Applet

        • Global Configuration

        • Applet Configuration

        • Utilities

        • Release

      • Manifest

      • Marple

      • The Workings

      • Handling Protocols

      • Bearskin Compatibility

      • Utility Scripts

      • Status

      • User Tools

    • Topology Ideas

      • Networking

      • Wiring Looms

    • Conclusion

  • Index

    • ¦Numbers & Symbols

    • ¦A

    • ¦B

    • ¦C

    • ¦D

    • ¦E

    • ¦G

    • ¦F

    • ¦H

    • ¦I

    • ¦J

    • ¦K

    • ¦L

    • ¦M

    • ¦N

    • ¦O

    • ¦P

    • ¦Q

    • ¦R

    • ¦S

    • ¦T

    • ¦U

    • V

    • ¦

    • ¦W

    • ¦X

    • ¦Y

    • ¦Z

Nội dung

CHAPTER 5 ■ COMMUNICATION 163 You now have an alternate voice that, if installed correctly, can be proven with the Festival command (voice.list) (with the brackets). It should now show us1_mbrola as a suitable voice, so you can test it with the following: say us1_mbrola Hello automation When you’re happy you’ve found a voice you like, you can make it the default by setting VOX in the previous script: VOX=\(voice_us1_mbrola\) Having access to separate voices is good since people respond differently to different voices, according to the situation. The female voice, psychologists tell us, is good for information, issuing help, and reporting text, while humans respond better to commands given by a male voice. Within a household, you might have messages intended for different people spoken with different voices. If the listener knows the voice that’s theirs, it’s possible (through a auditory quirk known as the cocktail party effect) for them to isolate their voice among a lot of other auxiliary noise, including other spoken commands. The default voice (usually kal_diphone or ked_diphone) is raspy enough that it works well as the final alarm call of the morning. However, ensure that guests know you’re using it, because being woken up by something that’s the cross between Stephen Hawking and a Dalek is quite disconcerting. As well as simple phrases, you can ask Festival to read files to you either through the following: say default `cat filename` or through the following, which is more elegant: festival tts filename Although only text files are directly supported, there are a number of tools such as html2txt (can be used in conjunction with pdftohtml) to allow most documents to be read to you, maybe as part of your alarm call or while you’re cooking dinner and unable to read from a screen. ■ Note Try to keep vocal utterances as short as possible, splitting longer phrases up into separate calls to Festival, since long paragraphs often cause the voice to slow down and become unintelligible. It is also possible to build your own voices for Festival. Although the process is too involved and complex to discuss here, details are available through Carnegie Mellon’s FestVox project (http://festvox.org). If you want a custom voice, it’s easier to record one as an audio sample. CHAPTER 5 ■ COMMUNICATION 164 ■ Note Naturally, there are also commercial speech synthesis packages available, which is something that most open source devotees forget. One such example is available from http://cepstral.com whose web site also provides dynamic example voices. Piecemeal Samples Most automated train announcements are comprised of individual vocal snippets that are then rearranged into order by a computer. This provides a great range of possible phrases using a comparatively small set of original samples. With careful trimming of the sound files, they can sound very humanistic. The problem with this approach is that it is impossible to introduce hitherto unknown phrases into its lexicon. If you are using a human voice as an alarm clock, for example, you will know in advance every phrase and part-phrase that could be uttered. In the case of error reports from a software package, you probably won’t, particularly when it comes to filenames and user input. In these cases, you will probably have to acknowledge when the samples don’t exist and revert to Festival. To create a vocal alarm clock, for example, you first need to consider the samples you will need. This can be as expansive as you’re prepared to record for. Many countries have their own speaking clock service, accessible by telephone, that quote the time in ten-second intervals with many recording an entire 24-hour clock with each specific phrase. You also need to consider how grammatically exact you’d like to be. Does the phrase “1 seconds” annoy you? If so, you’ll need a specific sample for that. You also need to consider personal preferences, such as whether “15 minutes past” sounds better to your ears than “a quarter past,” and so on. Personally, I have a list of standard clock phrases that I consider important: • “the time is” • “p.m.” • “a.m.” • “midnight” • “o’clock” • “a quarter past” • “half past” • “a quarter to” All the other times can be comprised of the following phrases: • “minutes past” • “minutes to” • “past” • “to” CHAPTER 5 ■ COMMUNICATION 165 and the numbers 1 through 20, 30, 40, 50, and 60, the latter being needed for the occasional leap second when my pedantic geek friends come to visit! I also add specific samples for the following to remain grammatically correct: • “1 minute past” • “1 minute to” I can then retrieve the time with the following and piece them together with code: HOURS=`date +%I` MINS=`date +%M` The 100-line script is left as an exercise for you! 9 Although the programming is comparatively simple, the record processing is not so. You need to get your voice talent to record a few samples of the whole phrase to get a feeling for the rhythm patterns in their speech. You should then sample all the words 10 and trim the individual phrases to leave no dead space at the start, while still leaving a suitable gap at the end that matches the speakers’ rhythm when a second word is concatenated directly to the end. Having them say sample phrases first gives you an idea on their pacing so that in some cases you can ask them to leave a longer pause than normal after each item. With this in mind, ask them to read a longer list than you actually need. So for a number list ending at 60, ask them for 61. Unless they’re experienced actors, humans naturally drop their voice when reading the last element in a list, which sounds unnatural when it is suffixed with another digit. This whole process can take several hours for recording, rerecording, and editing. But it is worth having a personalized alarm clock for a distant partner or as a quirky 22nd-century gadget. If you record other phrases at the same time (such as “Good morning,” “Good night,” or “Oy, get out of my house!”), you can trigger the samples at other times and for other reasons. Web Access By far the most influential of all communication methods in the 20th and 21st centuries has been the World Wide Web. Also known as the Web, the interwebs, 11 the Internet (as a whole), and a series of tubes, the HTTP protocol is so ubiquitous that it now appears on the most lowly of handheld and mobile devices. This in itself makes it incredibly valuable, because you do not have to consider the technical issues around other protocols, specific code to manipulate them, or customized applications for each handheld device on the market. Using it control our house means that you, quite literally, have a home page. The Web, like everything you’ve seen, works with both client and server components. The client is more commonly known as the web browser, running on an arbitrary machine somewhere in the world, while the server processes requests from the web browser and is located on the home server machine. These requests are generally for static HTML web pages, but they can be scripts—written in virtually any 9 The vocal time script is available in the Minerva package as vtime. 10 Audacity is the still de facto standard for audio sampling and editing in Linux, in my opinion. 11 Flames in an e-mail to /dev/null, please! CHAPTER 5 ■ COMMUNICATION 166 language—to dynamically generate a page or run software locally. The server runs under a user such as www-data, meaning that any local processing will be done under the jurisdiction of this user, which may require that some software will require the appropriate permissions to access the necessary devices. This is often true of the audio device (for speech and music playback) and the serial ports (for X10 control). When producing a set of requirements for the web server, you must distinguish between what processing is to be done on the client and what’s on the server. As an example, if you think that it’d be a good idea to play MP3s from a web page, it’s important to know whether your intention is to listen to your music collection while at work or to organize a playlist while at home (perhaps during a party), where you can hear the server’s audio output but not necessarily access it physically. Building a Web Server The web server of choice for so much of the open source community is Apache. Currently at version 2, this project originated in 1992 and was called a “patchy” web server, because of its ad hoc development processes in the early years. It has since flourished into one of the most-used pieces of software in the world, running about 50 percent of all web sites on the Internet. The power of Apache comes from its flexibility with modules. This allows an efficient and secure core able to enlist the functionality of supplementary code that can be loaded and unloaded at will. Naturally, each module provides another opportunity to open unintentional security holes, so we’ll install only the modules you need. For these primary purposes, you need only the basic server and a scripting language. The Debian packages are installed with the following: apt-get install apache2 libapache2-mod-php5 Other distributions are similarly named. Once it’s installed, you can point your browser to localhost where you should see the “congratulations” web page, stored by default in /var/www, thus proving the web server works. You can then test the scripting module by creating a page called test.php containing the following: <?php echo phpInfo(); ?> Generally, the installation of these modules will also correctly configure them so that .php files are associated with the execution of the PHP module. If this is not apparent, you can enable the module with this: a2enmod php5 In the very unlikely event of these not working, a log is kept in /var/log/apache2/error.log. A lot of important traffic relies on a working web server, so it is worth the time to ensure it’s stable. Virtual Sites It is possible for one web server to serve web pages for more than one site, even if they are on the same IP address. This has been available since version 1.1 of the HTTP protocol (supported by all main browsers), which included the domain name into the request, as well as the IP address. In the home environment it’s quite uncommon but is useful because it allows you to split the incoming web traffic CHAPTER 5 ■ COMMUNICATION 167 into two parts to divert the curious. You can have one site for general access by friends and family, containing a blog with photographs of your dog and children, and a second for HA control. You can begin by setting up two domains, perhaps through Dyndns.org as you saw in Chapter 4, and making two distinct directories: mkdir -p /var/www/sites/homepublic mkdir -p /var/www/sites/homecontrol You then create two configuration files, one for each site. Follow the convention here of prefixing each site with a number. This allows you to name your publicly accessible as 000-public, meaning it will served first in the case of any web configuration problems, or the site is accessed with only an IP address. Dropping back to the public site in this fashion has less scope for damage but it makes it impossible to use the HA control web site to correct the problem. Most errors of this type, however, are fixable only through SSH, so they aren’t a problem. These two files are /etc/apache2/sites-available/000-default containing the following: <VirtualHost *:80> ServerName mypublicpresence.homelinux.org ServerAdmin webmaster@localhost DocumentRoot /var/www/sites/homepublic/ <Directory /var/www/sites/homepublic> Options Indexes FollowSymLinks MultiViews AllowOverride AuthConfig Order allow,deny allow from all deny from none </Directory> </VirtualHost> and /etc/apache2/sites-available/001-control containing the same thing but with homepublic replaced with homecontrol and an alternate ServerName. They are then enabled manually, and the web server is restarted with the trinity of the following: a2ensite 000-default a2ensite 001-control /etc/init.d/apache2 restart You now have access to two virtual sites that can be prepared accordingly, with modules and software that you’ll discover later. But even with this basic level of configuration, you can explicitly deny users from known bad IP addresses by adding whitespace-separated dotted quads on the deny line, instead of the phrase none. Or, more preferably, you allow only from those addresses you know to be safe, such as work, school, or family homes using the same format. The latter is more complex because home users are often assigned a dynamic IP address by their ISP, especially those relatives with dial-up connections. Consequently, you generally need to protect the site using a separate username and password. . /etc/apache2/sites-available/001-control containing the same thing but with homepublic replaced with homecontrol and an alternate ServerName. They are then enabled manually, and the web server is restarted with. /etc/apache2/sites-available/000-default containing the following: <VirtualHost *:80> ServerName mypublicpresence.homelinux.org ServerAdmin webmaster@localhost DocumentRoot /var/www/sites/homepublic/. mkdir -p /var/www/sites/homepublic mkdir -p /var/www/sites/homecontrol You then create two configuration files, one for each site. Follow the convention here of prefixing each site with a

Ngày đăng: 03/07/2014, 20:20