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

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

5 337 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 2 ■ APPLIANCE HACKING 78 This might be to record the sound with vox_record.sh: #!/bin/bash LOGFILE=/var/log/voxrecordpid DIR_INCOMING=/usr/local/media/voxrecord if [ "$1" == "start" ]; then FILENAME=`mktemp -p $DIR_INCOMING`.wav arecord -f cd -t wav $FILENAME >/dev/null >/dev/null 2>&1 & PID=$! echo $PID >$LOGFILE fi if [ "$1" == "stop" ]; then PID=`cat $LOGFILE` kill $PID rm $LOGFILE fi or play back each sound in the directory with vox_play.sh: #!/bin/bash DIR_INCOMING=/usr/local/media/voxrecord for F in "$DIR_INCOMING"/*.wav do play $F done or even delete them all through vox_delete.sh: #!/bin/bash DIR_INCOMING=/usr/local/media/voxrecord rm -f $DIR_INCOMING/* Naturally, there is a lot more scope here to support the deletion of individual recordings, and so on. But this represents the idea. ■ Note The Minerva system abstracts these ideas out into Minx, which eliminates the need for separate executables for each Arduino application. Minerva will be covered in Chapter 7. CHAPTER 2 ■ APPLIANCE HACKING 79 Joysticks for Input Joysticks, particularly old ones, make wonderful input devices because they interface with the parallel port on most standard sound cards and are physical rugged. This enables the buttons to be reused, particularly as foot pedals, to control software. Indeed, this provides a very cheap way of adding a dictation module to your machine, without the need for an Arduino providing the input. In addition to triggering individual events on a Linux machine, such as requesting a weather report or the state of the machine, it can also feed messages to other applications. mplayer, for example, can operate in slave mode, allowing commands to be fed to it from the standard input or a named pipe. Similarly, the X Window TV-viewing software, xawtv, comes with xawtv-remote to change channel and volume (as per most remote controls), giving you capture on/off and screenshot facilities. This makes it possible to freeze frame magic shows to see how they do it! You can read the joystick directly from /dev/js0, but it is usually better to use an abstraction, like the Simple DirectMedia Layer (SDL). This allows you to port the code elsewhere if necessary, avoid the vagaries that come with a reliance on the device hierarchy, and make it easier for others to add and adapt your code. The code to read and process the joystick is a very simple loop of C code: #include <SDL/SDL.h> int main() { if (SDL_Init(SDL_INIT_JOYSTICK) < 0) { fprintf(stderr, "Couldn't initialize SDL: %s\n", SDL_GetError()); exit(1); } SDL_JoystickEventState(SDL_ENABLE); SDL_Joystick *pJoystick = SDL_JoystickOpen(0); SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_JOYBUTTONDOWN: // Use event.jbutton.which, event.jbutton.button, event.jbutton.state break; } } SDL_JoystickClose(pJoystick); return 0; } The button presses can naturally trigger software internally or make use of the Minerva Minx system I mentioned earlier to execute separate external scripts (Minerva is covered fully in Chapter 7). Some joysticks can also be used as output devices, through an technique known as force feedback, available under Linux with libff. This functionality is provided through one of two drivers, HID driver (hid-lg2ff) or I-Force driver (iforce.ko), which cover a number of the force feedback devices on the market. Alas, not all of them are included, so it is best to check compatibility first (http://sourceforge. net/apps/mediawiki/libff/index.php?title=SupportedDevices). The use of force feedback is primarily for games, because the game causes a slight jolt of the device, through a small motor in the joystick, CHAPTER 2 ■ APPLIANCE HACKING 80 when the player is attacked or dies. The vibrate option on mobile phones and pagers works in the same way. There is very little scope for shaping the vibration in any advanced or meaningful way, and very few (if any) games in Linux support the library. However, fftest (from the ffutils project at http://sourceforge.net/projects/libff/files/ffutils) may be hacked to provide a small rumble when an e-mail arrives. Other Input Controllers Game development has never been a strong selling point to the Linux community; consequently, the libraries available (and the resultant quality of the games) have been few in number. This has led to a sporadic approach to the problem of device control. One good example of this is the separation between SDL (for good solid joystick processing, but with force feedback currently available only in an unstable SVN branch) and fflib (for force feedback). There is currently just one project that is attempting to close this divide, and it’s called the Object Oriented Input System (OIS); you can find it at http://sourceforge.net/projects/wgois/. OIS is planning on abstracting away all the device (and driver) specific elements of user input devices (including keyboard, mice, and joysticks) and providing a unified API to them. Although this is admirable for the games developers, it doesn’t help us a great deal except for the recent introduction of code that supports the Nintendo Wii’s remote wand (aka the Wiimote). This peripheral operates through Bluetooth and can determine the area of the screen it’s pointing at by imaging into its sensor the infrared LEDs held in a bar attached to the top or bottom of the screen. This can also determine its orientation and acceleration. This makes it a very suitable controller for complex applications running on a TV screen, where a mouse is not suitable but an equivalent means of control is needed. There is also the CWiid tool set (part of the www.wiili.com project), which provides a mouse driver wrapper, allowing unported mouse-based applications to be controlled by the Wiimote. Hacking Laptops The price of netbooks, with solid-state storage and preinstalled Linux software, are now so low that their cost isn’t much greater than the top-of-the-range stand-alone photo frames. And as a bonus, you get a better processor, video playback, network connectivity (often wireless), and VoIP software. This makes the netbook an ideal home automation panel, with many uses. Obviously, older laptops can also be used for hacking. Any that are lacking a hard drive, have dead batteries, or have broken keyboards are particularly good value since the cost of new parts makes them too expense to rebuild, and having a laptop reliant on a tethered power line is not such a problem for home automation users as it is for others. Their use as a control panel is obvious, because the screen and keyboard halves can be folded flat and mounted to any wall or surface quite easily. Or, the keyboard base (with the lion’s share of electronics) can be hidden away underneath a desk or worktable, with just the screen poking out. It can then be controlled with a joystick input or, more impressively, a touchscreen. Touchscreens can be added retroactively to most laptops. They exist as a transparent membrane that fits over the screen and a PS/2 socket that mimics the behavior of a mouse delivering X and Y coordinates and left-button up and down messages. It should be noted that the software interface must be suitably programmed, since the membrane cannot detect the mouse position unless there is pressure on it, and there is no input for a right mouse button. Fortunately, most web interfaces are generally suitable. CHAPTER 2 ■ APPLIANCE HACKING 81 ■ Note The touchscreen membranes cannot be cut to the size of your laptop; they must be bought presized, so check carefully before purchasing, and remember that screen size is measured diagonally across the LCD screen itself, not the visible area. Your Own X10 Devices Even some hardened geeks balk at the idea of creating hacks with mains electricity. 11 But with a little care and attention, you can add X10 control to any mains-powered device, such as water heaters, heaters, garage door motors, and so on. You can even wire them directly to standard consumer equipment (like modems and printers) to reboot or power cycle them. Building an entire X10 unit to control a motor, for example, is so far beyond the scope of this book that it wouldn’t be fair to try. Instead, I will show an inline appliance module, such as the AM12W, which handles the dirty work of processing the protocol and results in a set of closed contacts between two of its connections. It works in the same way as the AM12 you saw in Chapter 1 (although slightly cheaper), but instead of controlling the flow of current to a plug socket, it controls the flow between the mains and the X10 unit and between the unit and the device. Figure 2-8 shows this wiring. Figure 2-8. Connecting an AM12W to a mains-powered device 11 Since January 1, 2005, in England and Wales, the Building Regulations Part P specifies that only certified engineers can carry out this particular electrical installation work. If it not carried out by such a person, then the work must be certified upon completion. Other countries may have similar laws. CHAPTER 2 ■ APPLIANCE HACKING 82 This works for any unit that is remotely controlled only through X10. To support a local switch (either in the on/off variety or a momentary push button), a better choice of module is the AD10. This also supports a manual override on the device, shown as the blue button in Figure 2-9. Figure 2-9. The AD10 module Figure 2-10 shows the wiring; although both types of button are featured here, only one would be used in practice. Figure 2-10. Wiring an AD10 to a mains-powered device The main advantage of this module over the AM12W is that the switches used are standard electrical ones and not the (more expensive) X10 variety. . technique known as force feedback, available under Linux with libff. This functionality is provided through one of two drivers, HID driver (hid-lg2ff) or I-Force driver (iforce.ko), which cover a number. wrapper, allowing unported mouse-based applications to be controlled by the Wiimote. Hacking Laptops The price of netbooks, with solid-state storage and preinstalled Linux software, are now so low. preinstalled Linux software, are now so low that their cost isn’t much greater than the top-of-the-range stand-alone photo frames. And as a bonus, you get a better processor, video playback, network

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