Smart Home Automation Part II - Networked Devices
Although X10 and C-Bus both provide a good means of sending simple controls to simple devices, more complex communication requires something better. More specifically, it requires something with more bandwidth. When the command is “play this song,” it needs significantly more bandwidth. The most accessible way of supplying this is through a local Ethernet network, because it can send commands and data at high speeds without the distance limitations of USB, RS-232, or parallel cables. And unlike X10, two-way communication is provided for free as part of the specification.
Ethernet Devices
There are many devices that support communication through Ethernet, either to control it or to supply it with data. Some can work on their own without additional hardware, such as personal video recorders (PVRs) and media enclosures. Both consist of a method of storing the media and the technology for playback. Others require a server to supply it with data. The functionality of the device, and its use within an automated home, is always improved by utilizing networked capabilities. This means you will need a server, of some kind, for most future appliances. This elicits the distinction of two necessary parts—a front end and a back end—connected by a local area network, be it wired or wireless.The front end, or head unit, will generally consist of a device connected to a nearby HiFi or TV in order to play media located on a physically remote machine. Because such a unit is placed in the living room or bedroom, it should be small, silent, and attractive. Preferably, it should also be fairly cheap, because one front-end unit is needed for every room in the house that wants to participate in streamed media.
The back end, by contrast, is stored away from the main living areas (since it’s generally a big PC with a noisy fan) but able to supply media streams to all the head units within the house via the network.
I’ll cover various media-oriented head units in Chapter 3, although most of those shown could be re-created with a Linux machine running the appropriate software. However, the power usage, noise, and cost will generally be larger than a custom-built embedded device, even though many of those devices may be running Linux themselves! To connect the units, however, you need to know how to set up a network.
Networking Primer
To best utilize the devices here, you will need to configure a Linux machine as a suitable server. Most computer science books will begin their networking section by describing the OSI seven-layer model of networking...I won’t! Instead, you’ll learn only the necessary, practical steps of providing and configuring a suitable home network for automation.Note:
Each Linux example here, and throughout the book, is based around Debian and the packages within it. This is not advocacy on my part, merely practicality, because it’s what I use. Some distributions may place the files in slightly different places or have slightly different names, but the principles are always the same, and the equivalents are easy to find.
Concepts
A home network is a way for each computer in the house to share a set of common resources such as printers, scanners, and storage space. In this sense, it’s very much like an office network. Where the home differs is in the level of technology and, consequently, the expertise needed to run it. One of the main bugbears in office IT systems is the issue of security. With a home network, the relationships between the people using it are very much different, and social mores are brought to bear.
The standard network configuration has two parts—internal and external. The internal part is a network that connects all the house computers together, along with their peripherals, and makes them invisible to the outside world. These devices may be networked together through cables or wireless.
The external network is everything else! The big, wide Internet is generally unavailable the computers at home; it is available only by connecting to an ISP through a modem, broadband connection, 3G card, or similar device.
To connect these two sides of the network together, you need a router. Sometimes the router is a small box that comes as part of your DSL/cable/broadband package and automatically separates the internal and external traffic. Sometimes you’ll need to buy one. They have one RJ-45 socket carrying the external network traffic, into which you plug the network cable from the broadband modem, and one or more outputs to the internal network.
Alternatively, you can use a PC with two network cards—one configured to talk to the external network and one for the internal. If you have a 3G card, then this acts like your externally configured network card.
With the router existing in both internal and external networks, it is able to automatically keep both sets of traffic separate and block any data or software you don’t want moving between the two. Most routers are configured, by default, to allow all outgoing traffic but block all incoming traffic, except those on specific ports. The port is the route by which traffic protocols flow and is dereferenced by a number.
All web pages, for example, are requested on port 80. So if your router is blocking incoming traffic on port 80, you won’t be able to access your internal web server from outside your home’s internal network.
Depending on the number of machines on your network, you might also need a switch that provides additional network sockets, into which you can plug more computers. Although it is unlikely that many people will fill eight sockets with computers, it is not uncommon to have noncomputer devices that also use Ethernet to transmit data, thereby exhausting the available sockets.
Addressing
Every device on the network must have a unique address. There are two current forms of addressing, IPv4 and IPv6. IPv4 was the original form of describing addresses by means of a dotted quad, such as 89.16.172.66, and is used by virtually every machine and home device on the planet. IPv6 was introduced in 1998 by the Internet Engineering Task Force to overcome the various problems with IPv4, such as address exhaustion. However, its adoption is less than widespread, and many of the small, homeoriented devices do not use it, so I’ll be concentrating on IPv4.
For a machine to have an address, it must be given one, either by a human or by a suitably configured computer. It cannot randomly generate one in case the address conflicts with another machine on the network or is one of the reserved addresses, such as 127.0.0.1. All the networked machines in the home should exist within a specific range of addresses, known as a subnet, and should be assigned to one of the private address ranges provided by the IPv4 specification. This not only stops conflicts with other existing sites on the Internet but also ensures the data within these networks is secure and invisible to machines outside the network, because all routers, switches, and gateways do not recommunicate any traffic with a private address range outside the local network. These private address ranges are 10.x.x.x,8 172.16-31.x.x, and 192.168.x.x, where x can mean any value between 0 and 255. For the purposes of demonstration, I will assign my subnet to the 192.168.1.x range, giving me 2549 possible devices on the network. Most people use this for private networks because nearly all the routers sold for the home allocate addresses within this range. Also, most questions found on the various Internet forums will probably have answers detailed using the same addresses as you have.
Now knowing the address range of your network, you have to consider the individual addresses. The first one to assign is the router, which usually earns the 192.168.1.1 designation,10 followed by the Linux server, which I will assign 192.168.1.2.
Caution
Configuring properties such as IP addresses requires you to be logged in as root, so tread carefully!
You can provide a Linux machine a static address either by using the tools in your desktop GUI or by configuring the /etc/network/interfaces file directly:
- auto eth1
- iface eth1 inet static
- address 192.168.1.2
- netmask 255.255.0.0
- broadcast 192.168.1.255
- network 192.168.1.0
This tells the system to use the network card assigned as eth111 for the static IPv4 address 192.168.1.2, with all the standard parameters.
You can use this approach to assign static IPv4 addresses to every machine on your network— simply make note of which machine is given which number. However, this can become tiresome after a while, and many embedded devices don’t allow such control over the configuration. Either case requires you to upgrade to DHCP.
DHCP stands for Dynamic Host Configuration Protocol and is a way of configuring the networking facilities of each client machine on the network. The software comes in two parts, a client and a server. The client says simply, “I’m a machine; where is the network?” by transmitting a message onto the cable for all machines to hear. The server listens for any and all of these messages and responds by returning all the configuration data that the sender should use for networking, such as its IPv4 address, domain name, and so on.
Configuring a DHCP client in Linux is easy and involves replacing the earlier section of the /etc/network/interfaces file with the following:
auto eth1
iface eth1 inet dhcp
Creating a DHCP server takes a little more work but can often be avoided since many network routers include one, although it’s sometimes disabled by default. To prepare one in Linux, you should first install the DHCP server software with a command such as this:
apt-get install dhcp3-server
You can then edit the /etc/dhcpd.conf file to assign addresses to each machine. Prior to editing, you may need to run this:
ln -s /etc/dhcp3/dhcpd.conf /etc/dhcpd.conf
ln -s /usr/sbin/dhcpd3 /usr/sbin/dhcpd
The addresses of each machine can be assigned by following these steps:
- Giving it the next free number in a series, say 100–254. These are pooled addresses.
- Looking at the MAC address of the network card that sent the message (all MACs are unique) and giving it a specific address based on that number.
- Doing any combination of 1 and 2.
Pooled addresses are configured like this:
- subnet 192.168.1.0 netmask 255.255.255.0 {
- option routers 192.168.1.1;
- range 192.168.1.5 192.168.1.115;
- }
Otherwise, the number of machines in your house is probably limited, so static addresses add very little work and make it quicker to troubleshoot since you know in advance what IP each computer should have. A typical configuration would appear like this:
- host teddyspc {
- hardware ethernet 00:A1:68:8E:9E:AA;
- fixed-address 192.168.1.4;
- }
This host section can be included within the subnet section shown previously to create exceptions in the pooling rule.
You can determine which leases have been granted by typing the following:
more /var/lib/dhcp3/dhcpd.leases
Many other options are available in the DHCP server, but these provide enough to get everything working. I’ll cover the specific extra cases as appropriate.
0 Response to "Smart Home Automation Part II - Networked Devices"
Post a Comment