YOMEDIA
ADSENSE
Apress - Smart Home Automation with Linux (2010)- P53
53
lượt xem 2
download
lượt xem 2
download
Download
Vui lòng tải xuống để xem tài liệu đầy đủ
Apress - Smart Home Automation with Linux (2010)- P53:Linux users can now control their homes remotely! Are you a Linux user who has ever wanted to turn on the lights in your house, or open and close the curtains, while away on holiday? Want to be able to play the same music in every room, controlled from your laptop or mobile phone? Do you want to do these things without an expensive off-the-shelf kit
AMBIENT/
Chủ đề:
Bình luận(0) Đăng nhập để gửi bình luận!
Nội dung Text: Apress - Smart Home Automation with Linux (2010)- P53
- CHAPTER 7 ■ CONTROL HUBS public static function getPages() { return array("Multimedia"=>"wmm.php", "News"=>"wfeeds.php", "Information"=>"wnews.php", "Life"=>"wlife.php", "Status"=>"wstatus.php", "Administration"=>"wsystem.php"); } public static function generate(&$appman) { if (self::$automaticInclude) { return $appman->getMasterBar(getPages()); } else { return ""; } } } ?> The details of this should be obvious! Since you can now build your own custom pages using the existing applets, let’s look at what applets are available. Existing Applets The supplied applets are split into several broad categories—media, lifestyle, information, and administration. Most applets use the Bearskin abstractions since one of the many benefits of using a loosely coupled component-based development model is that many small tools can be combined into larger ones. These web applets are one such case. Each applet presented here relies on underlying code and data from simpler front ends. With this in mind, the configuration of each applet will be given in its entirety, from basic data to web-oriented page, so as to give an immediate understanding of the entire data flow, without scattering the information between its subcategories of Bearskin command, abstraction, configuration, and so on. Media These applets allow you to control the playback of media in its various forms and include a CD player, a volume mixer, an MP3 jukebox, a VLC server and client, and a front end for displaying the TV guide. The CD player is a very simple abstraction of the Bearskin cdplayer command that allows control of the disc, as shown in Figure 7-3, along with the album and track names present. The bridge between the PHP applet code and the Bearskin system command is handled by zinc/system/cdplayer.inc, with zinc/conf/cdplayer.conf being used to indicate the location of the executable and device to use. 243
- CHAPTER 7 ■ CONTROL HUBS Figure 7-3. The server’s CD player being controlled through the Web The audio mixer follows the same idea as the CD player and simply calls out to the underlying Bearskin command, although its settings and parameters are configured by zinc/system/mixer.inc and zinc/conf/mixer.conf, respectively. There is an MP3 jukebox that allows you to explore the various directories under a given root, set at initialization with the following: $appman->AddApplet(new Warp_MP3Play_Applet("MP3 Player", "media/mp3")); If the folder name (second argument) begins with a /, then the path is absolute to the filesystem, whereas a relative path (as such shown here) means it’s relative to the web server itself (but not relative to the Minerva directory). The MP3 jukebox can either play the music on the server itself or be streamed across the Internet to the browser. (Follow the hints in Chapter 5 regarding media access to prepare this.) The consideration of the root folder is important here if you want to support streaming, since it can work only if the music directory is accessible by the web server, that is, it is underneath the Apache root server directory, such as /var/www/sites/homecontrol. To this end, you may need to create a symlink to your music collection and enable FollowSymLinks in the configuration. The TV guide uses the data downloaded every night by the Minerva user. It generates a large block of PHP code that stores program information for every show over the next three days inside $MINBASE/etc/users/public/tvresults.inc. This can be parsed out by the Bearskin commands such as tvonnow default and tvreport default public or processed by the applet directly. In addition to the list of all programs held by the public user, the daily crontab is able to search user- specific criteria and generate a customized schedule. It does this with a search string provided as a comma-separated list of terms, on a single line, in a file such as $MINBASE/etc/users/[username]/tvsearch/list. The tvsearch directory also may optionally contain two extra files. One is called e-mail and is the e-mail address to which this list is also sent; the other is sms, which is the SMS phone number to which a shortened form is sent. If the file in question doesn’t exist, then no message is sent. 244
- CHAPTER 7 ■ CONTROL HUBS Adding new TV channels requires the addition of disparate settings, since the TV configuration for the guide and control is unified into a single set of arrays held in $MINBASE/conf/tvconf.conf. #!/bin/bash tuner=( a1 a1 d1 d1 a1 d1 a1 a1 d1 ) channel=( 55 0 0 0 65 0 0 59 0 ) names=( BBC1 BBC2 BBC3 BBC4 "Channel 4" "Film Four" Five ITV TMF ) stations=( bbc1 bbc2 bbc3 bbc4 ch4 film_four five itv1 tmf ) As you can see, this holds the tuning information for the TV card (the channel number and whether it uses the analog or digital tuner), along with the station ID and its full, printable name. The only restriction on the station ID is that it must match the one being used to retrieve the TV guide data. In this case, this is discernible from the list at http://bleb.org/services/tv/data/listings/0. These data arrays are supplemented by the web-only data for the station icons, held in $MINBASE/media/images/tvguide. The filename stubs must match the IDs given earlier and end in .png to be correctly read by the applet. Furthermore, since these icons must be available to the web server, it is necessary to ensure a symlink exists from a web-friendly directory (such as warp/conf/tvguide/images) back to the original folder. By default, this is created by the Minerva installer, so you needn’t worry. The final media applets covered here support streaming video and come in a pair. The first is the VLC streaming applet that allows you to browse a series of predetermined folders (such as /net/media/videos) and select one for playback. This creates a media stream on the server and port specified in $MINBASE/conf/videostream.conf, which can then be read by a VLC client on any connected computer. The other half of the pair is a client applet that is able, by using a plug-in (available for Firefox when you install VLC), to stream the video clip into the browser window itself. ■ Note The streaming generally occurs over the local network only. To make it accessible from the outside, you need to open a port on your firewall or router to redirect traffic on the VLC port (8080, by default) to the given machine. Lifestyle These applets are generally for use in and around the house and include an X10 control panel for switching your appliances on and off in a very visual manner, as shown in Figure 7-4. 245
- CHAPTER 7 ■ CONTROL HUBS Figure 7-4. Using the web to switch your lights on or make a cuppa This has a number of configuration files because of its complexity, which I will cover now. (All paths are relative to the Minerva’s web home directory.) warp/conf/x10/x10.conf: This controls the mood or scenes bar that appears underneath the main X10 control map. This normally includes references like “all lights off” and “film mood.” You need to program a list of scenes and the code that will be run when the corresponding scene is selected. zinc/conf/x10floorplan.conf: This contains a list of X10 devices in the house and their respective floor index, X, and Y positions on the floor plan maps. These names must match the devices in either Hu format (such as E3) or by alias names, as provided in the heyu configuration file (/etc/heyu/x10.conf). This file also contains the names for each floor in the house. warp/applets/x10/img: In addition to the standard X10 graphics for lightbulbs and appliance switches, this directory should also contain the floor plan maps, stored as floor0.png, floor1.png, and so on. The calendar, shown in Figure 7-5, retrieves the Google Calendar information for both the public calendars and the current user. These are determined from the ical and gcal configuration files held in the user’s Minerva directory, $MINBASE/etc/users/[username]/external. The ical file is parsed to look for 246
- CHAPTER 7 ■ CONTROL HUBS today’s events, while the gcal file is used to present links to external calendar files. The clock used is a 4 piece of freeware Java, but you can easily change this to any design that takes your fancy. Figure 7-5. A calendar that extracts personal data from a public site The applet for cookery information is very simple, because it is a basic lexicon of cooker terms and basic conversion units, each loaded from a separate file found in warp/conf/cookery. If you plan on building an applet that is based around static text files, then this is a good starting point. The contacts applet provides full details of all your friends and relatives and is available on a per- user basis. Whenever a user is logged in, their contact information is read from the $MINBASE/etc/users/[username]/contacts.xml file, parsed, and presented in this applet. If they’re not logged in, then you will get those belonging to the public user. Finally, the photo frame applet is unique to the web conduit in Minerva. It reads a list of photographs from warp/conf/photoframe/photoframe.conf (the images themselves being held in a subdirectory called photos) and displays them one at a time, as shown in Figure 7-6. 4 Such as http://toki-woki.net/p/scroll-clock. 247
ADSENSE
CÓ THỂ BẠN MUỐN DOWNLOAD
Thêm tài liệu vào bộ sưu tập có sẵn:
Báo xấu
LAVA
AANETWORK
TRỢ GIÚP
HỖ TRỢ KHÁCH HÀNG
Chịu trách nhiệm nội dung:
Nguyễn Công Hà - Giám đốc Công ty TNHH TÀI LIỆU TRỰC TUYẾN VI NA
LIÊN HỆ
Địa chỉ: P402, 54A Nơ Trang Long, Phường 14, Q.Bình Thạnh, TP.HCM
Hotline: 093 303 0098
Email: support@tailieu.vn