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

Apress - Smart Home Automation with Linux (2010)- P49 ppt

5 141 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 7 ■ CONTROL HUBS 223 localhost dev /dev/ttyS0 - - You will see how this is able to communicate with other machines in the “Marple” section later in this chapter. Additionally, all Bearskin commands support init as a command argument so that it can prepare temporary log files, adjust ownership permissions, and launch any daemons as necessary. Typical Application Abstractions The currently supported abstractions are held in $MINBASE/bin and include all the necessary functionality. I’ll cover these briefly, pointing out the subtleties as necessary: x10control: This is a simple abstraction that invokes heyu to switch lamps and appliances on and off and dim lights. Because the arguments are unified between all Bearskin commands, the invocation of this looks reversed to heyu, making a typical call look like x10control default on bedroom_light. cdplayer: For those still in love with those shiny plastic discs, this controls the CD player (with cdcd) and retrieves its track listing using the cddb-tool package. Because the retrieval of this data can be quite slow, the track data is temporarily stored in /var/log/minerva so that it can be queried instantly with commands such as cdplayer default currentname. mp3player: This is a general-purpose media player that also processes the ID3 tags inside the MP3 to report the current artist and album with mp3player default artist, for example. It uses /var/log/minerva to store this information, along with the current process ID, which allows you to move through the tracks with mp3player default next. It abstracts mplayer, while making use of mp3info to parse the ID3 tags. wavplayer: This is a simpler, primarily synchronous, audio player used for general house alerts using play. mixer: This adjusts the relative volumes of each channel in the audio mixer, the names of which have also been abstracted so that user-friendly words such as master, cd, and recording can be used. It allows you to set the volumes as either a relative or absolute value between 0 and 100 percent, even when the underlying mixer application doesn’t. The current implementation uses aumix. say: This is the most interesting abstraction, despite being the simplest, because this queries the default voice (stored as a name in $MINBASE/etc/defaults/festvox, if present) and invokes festival. When called on behalf of a specific user, it uses their customized voice settings. There is also a sayfile variant for longer phrases using Festival’s more efficient tss argument. announce: This is an important extension since its context is different. Namely, it’s used for announcements to the house that something (important) is happening. It wraps the call to say by playing a chime sound and lowers the volume of any music that might be playing, before making the announcement and returning the volume levels to normal. Because of the importance of such CHAPTER 7 ■ CONTROL HUBS 224 messages, the device should generally be different from that of mp3player to prevent audio device conflicts in some systems. 3 In the worst cases, this can require using a second sound card or making use of the sound card in an external machine that generally has no use for audio, such as a wall panel. The wavplayer is often configured to use this same device. tweet: This is a way of publishing an announcement via microblogging site Twitter. This can be used by multiple users in the house, since it queries a set of stored credentials for each user in $MINBASE/etc/users/[username]/external/twitter. irsend: This is a means to send predetermined infrared remote-control codes to the connected IR transmitter. It will then be picked up by any sensor in range. For this reason, most IR-enabled equipment is held in Node0 where a single transmitter can service them all. It takes two arguments, the name of the equipment and the message that needs to be sent, and retrieves the code from a file held in $MINBASE/etc/ir/[equipment]/codes/[command]. The format of the data in this file is governed by the name in $MINBASE/etc/ir/[equipment]/method. The <device> in each case will generally be default to indicate the default output stream, which is the set of devices attached to the server machine, mentioned earlier. ■ Note Most Bearskin commands are controlled by killing and restarting the Linux process. This means that in many cases you cannot amend the mp3player process from a user who didn’t initiate it. That is, if you began MP3 playback using the web interface, you can’t stop the music using Cosmic or the command line, unless the governing user has the user privileges to do so. Monexec Monexec is a script that is called manually by the various Bearskin commands mentioned earlier to log each action. When the CD player is started, for example, the cdplayer script calls the following: $MINBASE/bin/monexec cdplayer play That in turn invokes a script: $MINBASE/conf/exec/cdplayer/play 3 Always determine whether your sound card (and its drivers) allow you to play audio from several applications at once. CHAPTER 7 ■ CONTROL HUBS 225 This play script can then perform any imaginable task, such as tweeting the currently playing track or using another command (like say) to announce “Good night” when the bedroom light is turned out. It is for these reasons that a simple log file is not enough. Although, naturally, monexec can also log commands too. TODO: A Worked Example To cement these ideas, you are going to be the brand new writer of a brand new module! It will be the TODO application and will be a fully worked example consisting of a Bearskin command, output conduit, messaging system, and web applet. The design is such that when someone performs the following: todo add steev "Take out the rubbish" the message will be added to the list of tasks in steev’s area and will be available for review on a web page or at the command line, with this: todo list steev This output could even be piped through Festival as part of the alarm call in the morning! So to begin, you need to create a file such as $MINBASE/bin/todo and process the basic arguments: #!/bin/bash MINBASE=/usr/local/minerva CMD=$1; shift USER=$1; shift MSG=$* TODOFILE=$MINBASE/etc/users/$USER/todolist if [ "$CMD" == "add" ]; then date +"%Y-%m-%d $MSG" >> $TODOFILE fi if [ -f $TODOFILE ]; then if [ "$CMD" == "list" ]; then cat $TODOFILE elif [ "$CMD" == "clear" ]; then rm $TODOFILE fi fi You then need to ensure the script is executable with this and test it for a little while: chmod ugo+x todo (It’s OK—I’ve done the testing step for you!) That’s your first step done; once you’ve understood conduits, you’ll see how to add entries into your to-do list from elsewhere. CHAPTER 7 ■ CONTROL HUBS 226 Conduits All communication is two-way, so naturally there are both input and output message conduits. The concept of which part is input and which is output depends on the direction of communication, so you consider them from the point of view of the Linux server, meaning an output conduit is the one that sends messages to devices, primarily for reports and error messages, and an input conduit is one that the server receives from a human to tempt it into action. The current version supports the following conduits, retrievable from the command msgconduit list: • echo (output only) • email (in/out) • ir (output only) • log (output only) • sms (in/out) • twitter (output only) • vox (in/out) • weblog (output only) • winalert (output only) Each conduit has a directory hierarchy afforded to it, existing underneath $MINBASE/etc/msg. Each is identical in structure and may contain none or more of the following directories: addr: This contains two flat files formatted in the same way. The first is alias, which is a list of Minerva-oriented usernames and a conduit-specific address. This would be a mobile phone number in the case of the SMS conduit, for example. The second is contacts, which is a list of address for people you might want to contact but who are not Minerva users. This latter file is available only when sending messages to the output, thereby allowing you to send text messages to your friends but not permit them to query or change the state of your home appliances in any way. auth: This is reserved for future expansion, although it’s rarely used since most authentication is currently done through the $MINBASE/etc/user/[username] hierarchy. cmd: This directory contains a list of command aliases used with input conduits. In this way you can send short messages to the conduit, such as “wakeup,” which in turn runs a cmd/wakeup script, allowing it to perform several commands at once, without you having to explicitly specify them all. Additionally, the script could perform smart contextual operations, so commands such as lightson would determine your location and control the most applicable light. I’ll cover location deduction later in this chapter. xmit: This contains a file called cmd that is usually a symlink to an abstracted Bearksin command that processes the argument list whenever this conduit is used as an output. CHAPTER 7 ■ CONTROL HUBS 227 I’ll now cover the method by which each of these functions so you know how to add new ones in the future and utilize them to best effect. Echo Output only. This is the simplest to understand since it merely reflects all the input parameters to the current console. It is used primarily for debugging the conduits and address book. Email Input/output. Like most of the conduits that support input and output methods, the two are separated by a large expanse of code. For the input side of the conduit, procmail is triggered automatically from the mail server after parsing the incoming mail to determine whether it’s originated from someone who is able to send messages. This is covered fully in Chapter 5. The output conduit uses the standard mail program directly. Infrared Remote Control Output only. This calls the irsend code to determine the device and protocol necessary. Logging Output only. This writes all messages into /var/log/minerva/msglog and is also used primarily for debugging. SMS Input/output. The output conduit works through mxsms, which is symlinked to one of three possible driver scripts, mxsms-gnokii, mxsms-intelli, or mxsms-txtlocal, depending on who is providing the current output service. If adopting the ideas of Chapter 5, you can make mxsms a script in its own right to consider the priority of the transmitting user and determine which service to use. For input, you will have Apache triggering the code when a specific web page is downloaded from a remote SMS-PC gateway or from a custom script checking message through Gnokii (courtesy of crontab). Twitter Output only. . CHAPTER 7 ■ CONTROL HUBS 223 localhost dev /dev/ttyS0 - - You will see how this is able to communicate with other machines in the “Marple” section later in this chapter. Additionally,. bedroom_light. cdplayer: For those still in love with those shiny plastic discs, this controls the CD player (with cdcd) and retrieves its track listing using the cddb-tool package. Because the retrieval. album with mp3player default artist, for example. It uses /var/log/minerva to store this information, along with the current process ID, which allows you to move through the tracks with mp3player

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