Mobile Home Automation
SAMI LABABIDI © 1998

1. Introduction
Is this new or "experimental" technology? Certainly not, in fact, the equipment used has been used in office buildings, shopping malls and luxury homes for over a decade! High technology is closer than you think. The automated doors on the Starship Enterprise seem light years away, but you actually walk through one every time you go to the supermarket.

In its most simple form Home Automation is the ability to control lighting & household appliances remotely. Almost everyone already has a limited amount of Home Automation. Home Automation is analogous to earlier developments in factory and office automation. It includes the remote control and monitoring of domestic appliances, home security and energy management.

There is a technology called X10 which although invented in the UK in 1978 by Pico Electronics of Glenrothes, Scotland, is almost totally unheard in the UK. It is however, very widely used in the USA. X10 uses existing mains wiring in your house to carry "messages" to special light switches and plug-in modules. These messages consist of 2 parts...An "address" and a "command". In total there are 256 X-10 Addresses and commands include OFF, ON, DIM and BRIGHT. The light switches replace your ordinary switches and can be used in exactly the same way, however they also respond to the messages sent over the wiring. Each module has two switches to set its address. When a message is sent the module looks at the address and if it matches the address set on the switches the device will respond to the command.

Several types of "Controller" exist to "Talk" to the modules. The most basic is the "Mini Controller" which can control 8 addresses by means of press-buttons. This plugs into a mains socket and sends the messages when a button is pressed. More than 1 module can have the same address so if for example you had 3 table lamps in a room you could control them simultaneously with 3 lamp modules set to the same address, or individually by setting the modules to different addresses. An Infra Red version of this controller is available which when used in conjunction with a suitable remote control handset enables 16 addresses to be controlled from the comfort of your favourite armchair.

The "Mini Timer" resembles a small digital alarm clock and has the ability to send messages at a predetermined time. Imagine turning on the coffee pot 5 minutes before you get up so that when you stumble downstairs bleary eyed a pot of freshly made coffee awaits you!

The latest piece of the X-10 jigsaw to hit these shores is the CM11E which is a small white box resembling a 3 way adaptor which plugs into the mains and your PC. Using suitable software the CM11E is programmed from your PC to perform whatever function you require at whatever time you require. At this point the PC can be disconnected, however you can leave the PC on all the time and have direct control of all your X-10 devices from the keyboard. The PC screen also provides feedback of any X-10 messages on your wiring so if someone in the kitchen sends a command to turn off the outside lights, your PC screen shows the status of the lights change from ON to OFF. Very Cool!

2. Aim of project
Imagine being able to control all the electrical appliances of your home from virtually any place your are in the world! For example, say one cold winter day, you are stuck in traffic on the motorway after a long day at work. By pressing a few keystrokes on your mobile phone, you activate a macro which turns on the heating, prepares your Jacuzzi, switches on your electrical fireplace and lava-lamps at your premises.

In today's times the GSM mobile terminal has become one of the items that is constantly with us. Just like our wallet/purse, keys or watch, the GSM mobile terminal provides us with a communication channel that enables us to communicate with the world. The want for a person to be reachable or to call anyone at any time is very appealing.

Using the cybernetic concept of action space, we in fact extend the action space of the human with the mobile terminal, enabling the subscriber to talk to another subscriber and thus exchange information, issue or receive commands.

In this project, we will explore ways of extending this notion of Home Automation by applying mobility to it using various technologies that are available in our information age. These technologies include mobile communication devices and the Internet which are becoming part of our everyday lives.

3. X10
3.1. What is X10 ?
X10 is a communications protocol for remote control of electrical devices. It is designed for communications between X10 transmitters and X10 receivers which communicate on standard household wiring. Transmitters and receivers generally plug into standard electrical outlets although some must be hardwired into electrical boxes. Transmitters send commands such as "turn on", "turn off" or "dim" preceded by the identification of the receiver unit to be controlled. This broadcast goes out over the electrical wiring in a building. Each receiver is set to a certain unit ID, and reacts only to commands addressed to it. Receivers ignore commands not addressed to them.

3.2. X10 transmitters
The simplest X10 transmitter is a small control box with buttons. The buttons select which unit is to be controlled, and which control function is to be sent to the selected units (e.g. "turn on", "all units off", etc). There are also clock timer transmitters which can be programmed to send X10 commands at certain times. Some of these can be programmed with buttons on the timer; some must be connected to a computer to select the times. There are other special purpose transmitters that send certain X10 commands at sunup or sundown or upon detecting movement.

3.3. X10 receivers
The simplest X10 receiver is a small module with an electrical plug (to connect to a standard wall outlet), an electrical outlet (to provide controlled power to the device it's controlling) and two dials (to set the unit ID code) on it. An appliance module has relay inside which switches power to its outlet on or off in response to X10 commands directed to it. A lamp module is similar, but has a triac instead of a relay and will respond to dimming commands as well as on or off commands. Other receivers can be wired into wall outlets or into lamp fixtures.

3.4. Maximum number of appliances
X10 specifies a total of 256 different addresses: 16 unit codes (1-16) for each of 16 house codes (A-P). Several receivers could be set to the same house code and unit code so a single command issued by an X10 transmitter could control multiple receivers in parallel.

3.5. X10 protocol
Each ONE bit in a legitimate X10 transmission is a 1 millisecond (mS) pulse code modulated burst of 100KHz on the AC line, and each ZERO is the absence of that burst. The exact length of the burst may not be too critical in most applications. The burst is sent three times for each bit, once at each AC zero-crossing (accounting for zero-crossing in 3-phase). That means once each 2.778 mS. The next bit is sent on the following zero-crossing. This is done to get the quietest time on the AC line for the receiver, whatever phase of the AC it's on. The zero crossing gives the best signal-to-noise ratio for data transmission because everything should be shut down then (i.e. the voltage is low).


In addition, each bit is sent both true and complemented, and each code sequence is sent twice. That's a lot of bit redundancy, and just barely enough to make it past the noise on the line, depending on actual conditions.

A single normal command takes eleven cycles of the AC line to finish. All legal commands must first start with the header 1110, a unique code as described below. The header bits take two cycles at one bit per half cycle. The next four cycles are the four-bit House Code, but it takes eight bits total because each bit is sent true then complemented. This is similar to biphase encoding, as the bit value changes state half-way through the transmission, and improves transmission reliability. The last five AC cycles are the Unit / Function Code, a five bit code that takes ten bits (again, true then complemented).

For any codes except the DIM, BRIGHT and the data following the EXTENDED DATA function, there's a mandatory three cycle pause before sending another command DIM and BRIGHT don't necessarily need a pause, and the data after the EXTENDED DATA command absolutely MUST follow immediately until all bytes have been sent. The EXTENDED DATA code is handy, as any number of eight-bit bytes may follow. The data bytes must follow the true/complement rule, so will take eight cycles per byte, with no pause between bytes until complete. The only legal sequence that doesn't conform to the true/complement rule are the start bits 1110 that lead the whole thing off, likely because the modules need some way to tell when it's OK to start listening again.

A full transmission containing everything looks like this (see table below for the actual command codes):

 
1 1 1 0  H8 /H8 H4 /H4 H2 /H2 H1 /H1  D8 /D8 D4 /D4 D2 /D2 D1 /D1 F /F
(start)        (House code)                 (Unit/Function code)
So, to turn on Unit 12 of House code A, send the following:
1 1 1 0 0 1 1 0 1 0 0 1 1 0 0 1 1 0 1 0 0 1 (House A, Unit 12)
then wait at least three full AC cycles and send it again, then wait three and send:
1 1 1 0 0 1 1 0 1 0 0 1 0 1 0 1 1 0 0 1 1 0 (House A, Function ON)
again wait three cycles and send it the last time.

Total transmission would have been 264 discrete bits (don't forget the 3-phase) and would take 53 cycles of the AC line, or about .883 seconds. It's perfectly allowable to stack the Unit or Function codes together, so sending Unit 2 Unit 3 Unit 12 ON (separated by 3 cycles minimum) will turn on all 3 units. Stacking ON and OFF codes is annoying and flashes the lights quickly (roughly 4 Hz).

X10 Command Codes

Note 1: Hail Request is transmitted to see if there are any other X10 compatible transmitters within listening range.

Note 2: In a Pre-Set Dim function, the D1 bit represents the MSB of the level and the 4 House code bits represent the 4 least significant bits. No known X10 device responds to the Pre-Set Dim function.

Note 3: The Extended Data code is followed by eight-bit bytes which can be any data you might want to send (like temperature). There must be no delay between the Extended Data code and the actual data bytes, and no delay between data bytes.

Note 4: The X10 RF to AC Gateway model RR501 is a two-way module. If the RR501 is addressed by transmitting its House Code and Unit Code and then the STATUS REQUEST is transmitted, the RR501 will respond by transmitting Status ON if it's turned on, or Status OFF if it's off.

3.6. Alternative protocols
X10 has three competitors:

  1. European Installation BUS (EIB). The EIB system requires one line called bus, along which all devices communicate.
  2. Consumer Electronic Bus (CEB). The CEB needs a Local Area Network to run on. Devices connected to the LAN communicate with a special language called Common Application Language (CAL).
  3. Lonworks. Similar to CEB, Lonworks requires a special network used for devices to communicate with each other. Network can handle as much as 30,000 devices.

3.7. Why X10 Technology?
There are two main reasons why we chose the X10 protocol.

  1. It is easy. Power line communication is patented. There is no need for 'control wires' or 'buses'. The modules simply plug in or replace existing switches, there is no complicated wiring. It is easily expandable to over 250 modules and it has the widest range of home control products available.
  2. It is affordable. You can build a system for very little expense, and expand the system over time to suit your needs.

3.8. TW523 Interface
The TW523 interface is an X10 module which interfaces computers directly to the power line to send and receive X10 commands. The TW523 is a low level two-way interface to the power line. It contains a PIC controller to decode incoming signals and store them for transmission to the host computer.


TW523 Interface

The computer interfaces to the TW523 through a RJ-11 modular phone jack which has the following signals: signal (not AC) ground, receive output, zero-cross output and transmit input. All signals are optocoupled, and the outputs are open-collector. A logic high (greater than 4V) on the transmit input modulates the AC line with the 100KHz carrier wave. The zero-cross output is a square wave coincident with the 50Hz AC line. The receive output is an envelope of the X-10 signal, and is low when the 100KHz signal for `bit=1' is present during a valid code.

The signal applied to the transmit input must encompass all of the bits for all 3 phases of the line (i.e. 3 bits per half AC cycle). The computer must follow the full transmission protocol detailed later, but only needs to send the proper envelope for the transmission as the TW523 converts the digital envelope into bursts of 100KHz carrier.

The receive output is buffered through the PIC in the TW523. The first valid X-10 code cycle on the AC line alerts the PIC (and is lost to the controlling computer). During the second code cycle (all codes in X-10 protocol are sent twice), the TW523 outputs a low when there is 100KHz carrier on the AC line, and only during the bit time for the local AC phase. The signals for the other two AC phases are not echoed to the controlling computer. The output is open-collector at all other times. The logic is reversed; when there's a valid `bit=1' (100KHz carrier), the output is low, and high otherwise. Since the TW523 responds to all signals on the AC line, it also echoes any sent by the controlling computer, allowing for collision detection similar to that used by the Ethernet protocol.

3.9. TW523S10
3.9.1. Overview
The TW523S10 is a small unit that interfaces between a TW523 and a RS232 serial port of a computer. It handles all the critical protocol timings on sending and receiving X-10 signals. The unit is the size of a DB25 shell with a 25-pin female connector on one end and a 4-pin RJ11 connector on the other. It is powered by the host serial port and thus do not require any external power. With the device, any computer equipped with a RS232 serial port may send and receive X-10 signals under programming control using simplified ASCII like commands.

3.9.2. Communications
The interface runs half duplex, meaning that the TW523S10 and the user cannot send data at the same time. There is a simple protocol that is exchanged between the TW523S10 and the user.

When the TW523S10 sends a poll request type command (three most significant bits zero 000xxxxx) the user has up to 100ms to respond, else the TW523S10 will re-send the poll. When responding to this poll, the user sends a poll reply type command (three most significant bits zero 000xxxxx) so the TW523S10 knows when the user is finish sending.

There are dual X-10 transmit buffers so the user can send up to two X-10 commands in a row. Likewise when receiving X-10 data, there are dual buffers so up to two X-10 commands can be queued. Each X-10 buffer position contains House, Unit or Function and Repeat amounts.

3.9.3. TW523S10 Commands
The TW523S10 may send any of the following commands:

The TW523S10 may send any of the following commands:

	Poll Request

	0 0 0 x x x x x
	          |  |  |  |  |
 	          |  |  |  |  set when a received X-10 code is buffered
 	          |  |  |  set with X-10 receive activity (or delay timer)
 	          |  |  set when X-10 transmit buffers are full 
 	          |  set with X-10 transmitting (or queued buffers)
  	          set when there is a error status that should be read
Once this command has been sent, it is safe for the user to send any reply data. Note that when the X-10 receive activity bit is set, the user should NOT send House, Unit/Function or Repeat codes to ensure a X-10 receive buffer overflow condition will not occur.
	Error Status

	0 0 1 x x x x x
	         |   |  |  |  |
 	         |   |  |  |  set if the TW523S10  cannot detect a working TW523
 	         |   |  |  set when the X-10 receive buffer has overflowed
 	         |   |  set when X-10 transmit buffers have overflowed 
 	         |   set when a bad user command has been received
  	         set with a RS232 framing error

	This command details the error type from the poll command.

	House Code 

	1 0 0 0 x x x x
The four bits indicate the House code. Details follow. This is sent in response when the user asks to read the received X-10 data.
	Unit Code

	1 0 1 0 x x x x
The four bits indicate the Unit code. Details follow. This is sent in response when the user asks to read the received X-10 data, following the House code.
	Function Code

	1 0 1 1 x x x x
The four bits indicate the Function code. Details follow. This is sent in response when the user asks to read the received X-10 data, following the House code.
	
	Repeat Amount

	1 1 0 0 0 0 1 0
This code is sent to indicate that the TW523 has received two X-10 repeated commands. This is sent in response when the user asks to read the received X-10 data, following the Unit or Function code.

3.9.4. User Commands
The user may send any of the following commands:

Poll Reply

	0 0 0 0 0 0 0 0	- simple null reply

	0 0 0 0 0 0 0 1	- request TW523S10  error status

	0 0 0 0 0 1 1 1	- request TW523S10  X-10 receive (House, Unit/Function, Repeat)
After sending any one of these replies, the user must wait for the next poll request before sending more data.
	House Code 

	1 0 0 0 x x x x
The four bits indicate the House code. Details follow. This is sent in when the user wants to send X-10 data.
		
	Unit Code

	1 0 1 0 x x x x
The four bits indicate the Unit code. Details follow. This is sent in when the user wants to send X-10 data. Must be sent after House Code.
	Function Code

	1 0 1 1 x x x x
The four bits indicate the Function code. Details follow. This is sent in when the user wants to send X-10 data. Must be sent after House code.
	
	Repeat Amount

	1 1 0 x x x x x
The five bits (range 2 -> 1f) indicate the number of times the X-10 House Unit/Function codes should be sent. Only Dim and Bright codes should be sent more than once. Must be sent after Unit or Function code.
	Delay X-10 Transmit

	1 1 0 0 0 0 0 0
This special command may be sent after a normal X-10 transmit command to "listen" to the X-10 line for four seconds. This would be particularly useful after sending a Status Request Function code. This command is queued on the X-10 transmit buffer. This code need not be preceded by House, Unit/Function.

3.9.5. Encoding table


Notes: The following are limitations of the TW523
* - If more than two continuous Dim or Bright codes are received, every third code is missed.
** - These continuous streams of data are not supported.

3.9.6. Protocol algorithm
The following flow chart details the serial protocol:

4. Using GSM for Mobile Home Automation

4.1. What is GSM ?
GSM, which stands for Global System for Mobile Communications, is a digital cellular radio network operating in over 200 countries world-wide. It provides almost complete coverage in western Europe, and growing coverage in the Americas, Asia and elsewhere.

Of special interest is the capability of the GSM network to be used for data computing. Most people think of voice calls when they think of cellular phones. But because GSM is digital, you can connect your GSM-enabled phone to your laptop computer and send or receive e-mail, faxes, browse the Internet, securely access your company's LAN/intranet, and use other digital data features including Short Messaging Service.

The unique roaming features of GSM allow cellular subscribers to use their services in any GSM service area in the world in which their provider has a roaming agreement. That means the phone you use in France could work in Germany, Australia, Finland and even China, depending on your provider's roaming agreements.

GSM-enabled phones have a "smart card" inside called the Subscriber Identity Module (SIM). The SIM card is personalized to you and you alone. It identifies your account to the network and provides authentication, which allows appropriate billing.

4.1.1. Short Message Service
Short Message Service (SMS) is an integrated paging service that lets GSM cellular subscribers send and receive data right on their cellular phone's LED display, up to a maximum of 160 characters. Combine this with your laptop, and you can receive urgent email, fax notifications, news and stock quotes -- all without even dialing the phone. You can receive messages even when you are making a call.

The structure of an SMS message includes the mobile number the message is originating from, time, date, country code, length and the actual message.

4.2. SMS-X10 Gateway Overview
4.2.1. Outline The SMS-X10 Gateway enables the user to remotely execute X10 commands to control their premises using SMS as a communication medium. As an example, the user can be roaming in Italy on holiday and turn on his bedroom lights in London by sending an SMS message to the X10-SMS Gateway at his premises. The message can be one of the following format: "HouseID UnitId FunctionID" or an alias can be setup for example "bedroom1 lights on" == "A 12 ON".

4.2.2. X10-SMS Gateway components

At the premises there is a computer connected to a GSM mobile phone and a TW523 module. A daemon program runs in the background polling the mobile for incoming SMS messages. Once a message is received, the program checks that it is a valid X10 message and verifies that it is coming from a trusted source, this is done by checking the header of the message where sender's mobile number is stored. The message is then decoded and a relative X10 command is built and sent through the TW523 into the electricity circuit. Our experiment was conducted using a PC running MS-DOS, but any reasonable platform and operating system could be used instead.

4.3. SMS-X10 Protocol
There are two message formats which were allowed in our experiment:

  1. "HouseID UnitID FunctionID". E.g. a 1 on. This message would turn on device with HouseID a and UnitID 1. The set of valid values are the following:
  2. Aliases can be set-up in a special file (alias.txt). E.g. "go-lava-lamp1 == a 2 on"
The protocol can be extended to allow scenarios. For example by sending one message you can turn on your lava lamps, start the Jacuzzi and turn on the stereo.

4.4. Security
There is a security file (users.txt) which contains the trusted mobile numbers which are allowed access to the SMS-X10 gateway of the premises. The mobile number of an SMS message is included in the header. During the validation process, that number is checked against that the entries in the security file. If the file contains the mobile number of the message then the X10 command is allowed execution, otherwise the message is discarded.

4.5. Daemon
The daemon is constituted of two programs SMSToFile and FileToX10.

4.5.1. SMSToFile
This program polls the mobile phone checking for new messages. When a new message has been received, it creates a file (*.spt) containing the contents of the message. It then deletes the message from the phone. This program was written using special libraries which are phone specific. In our experiment we used a Nokia 2110 and the libraries where obtained from the Nokia website.

4.5.2. FileToX10
This program searches for files of the form *.spt. These files are deposited by the previous program. Once a file is available, it firstly checks if the message is coming from a trusted source. This is done by checking the mobile number enclosed in the header of the message against the users.txt file described earlier. If the user is not valid the message is discarded. Else the message is decoded into the relative X10 command and eventually sent through the TW523. Here are some of the main procedures of that program:

Procedure which searches for files of the form *.spt

void CheckForFile()
{
	int j,i,count;
	char c;
	double elapsed_time;
	time_t start,finish;

	if (_dos_findfirst("*.spt",_A_NORMAL,&c_file) == 0) 
	{
		printf("FILE:%s of %ld bytes\n",c_file.name,c_file.size);
		process_sms_command();
			while (_dos_findnext(&c_file) == 0) 
			{
				printf("FILE %s of %ld bytes\n",c_file.name,c_file.size);
				process_sms_command();
			}
		oneloop++;
	}
	else
	{
		printf("no files to process\n");
		time(&start);
		elapsed_time = 0.0;
		printf("WAITING 3 seconds\n");
			while (elapsed_time < 3.0) 
			{
				time(&finish);
				elapsed_time = difftime(finish,start);
			}
	}


}

This is part of the procedure which translates the message to X10 command
command 
void process_sms_command()
{
	double elapsed_time;
	time_t start,finish;
	FILE *fd;
	char spbuf[256];
	int i, numread,cmdcode;
	
  if(validate()){ // validates that user is authorized by checking users.txt
	if ((fd = fopen(c_file.name,"r")) != NULL) 
	{
		numread = fread(spbuf, sizeof(char), c_file.size, fd);
		fclose(fd);
		remove(c_file.name);
		cmd = spbuf[35];
		dev = spbuf[37] - '0';
		house = spbuf[36];
		printf("COMMAND WAS %c for house %c device %d\n",cmd,house,dev);
		cmdcode = -1;
	
		switch (cmd) {
			case 'ON': 
				cmdcode =19; 
				break;

			case 'OFF': 	
				cmdcode =27; 
				break;
			
			default: 	
				break;
		}

		printf("cmdcode = %d\n",cmdcode);
	
		if (cmdcode > -1) {
			PutX10(house,dev);
			PutX10(house,cmdcode);
		}

		time(&start);
		elapsed_time = 0.0;
		printf("WAITING 3 seconds\n");
	
		while (elapsed_time < 3.0) 
		{
			time(&finish);
			elapsed_time = difftime(finish,start);
		}

	}

	else 
	{
		printf("invalid command\n");
	}
  else
  {
	printf("Unauthorized access");
  }
}

This procedure calls TW523GS with appropriate argument
void PutX10 (char House, int Key)
{
  int Result;
  Result = TW523GS(0x8000 + (((int)(House) & 0x1F) << 8) + Key);
}

Actual function which sends the X10 command
int TW523GS(int DataIn)
{
   int temp;
    _asm  {
      MOV AX,DataIn
      INT SoftwareInterrupt
      MOV temp,AX
   }
    return temp;
}

5. Using the Internet for Mobile Home Automation

5.1. X10-Web Gateway
The X10-Web gateway enables user to remotely control and design their premises via a standard web browser. At the premises the hardware required is a computer, a TW523 and a TW523S10. The machine must be running a web server. In our experiment we used a SUN running Solaris.


When the user logs on their premises' homepage, a main menu is presented containing all the rooms of the premises. The user selects a room and is then presented with the X10 devices contained in that room. The interface allows the user to add and delete rooms and devices. When the user adds a device, information about the device must be entered including HouseID and UnitID. The user can issue commands by selecting a X10 command from a drop-down menu. Relative X10 commands then get issued by the X10-Web Gateway at the premises using the Common Gateway Interface (CGI).

5.3. "FireX10" CGI program
5.3.1. Description
This CGI program receives 3 arguments: HouseID, UnitID and FunctionID. It then decodes them into the relevant X10 serial commands using the encoding table show in section 3.9.5. and then sends them through the TW523S10.

5.3.2. Detail
Encoding tables:

int house_codes[16] = {0x86,0x87,0x84,0x85,0x88,0x89,0x8a,0x8b,0x8e,0x8f,0x8c,0x
8d,0x80,0x81,0x82,0x83};

int unit_codes[16] = {0xa6,0xa7,0xa4,0xa5,0xa8,0xa9,0xaa,0xab,0xae,0xaf,0xac,0xa
d,0xa0,0xa1,0xa2,0xa3};

int fn_codes[16] = {0xb0,0xb8,0xb4,0xbc,0xb2,0xba,0xb6,0xbe,0xb1,0xb9,0xb5,0xbd,
0xb3,0xbb,0xb7,0xbf};

Main procedure, reads the environment variable QUERY_STRING which gets decoded into relevant serial commands then putX10 procedure is called
main(argc,argv)
{
	int argc;
	char **argv;
	char *par1n;
	char *par1v;
	char *par2n;
	char *par2v;
	char *par3n;
	char *par3v;
	char *cd;
	cd = getenv("QUERY_STRING");
	par1n = strtok(cd,"=");
	par1v = strtok(NULL,"&");
	par2n = strtok(NULL,"=");
	par2v = strtok(NULL,"&");
	par3n = strtok(NULL,"=");
	par3v = strtok(NULL,"&");

	printf("Content-type: text/plain\n\n");

	house = (unsigned char) house_codes[(par1v[0]-'A')];
	unit = (unsigned char) unit_codes[atoi(par2v)-1];
	xfn = (unsigned char) fn_codes[atoi(par3v)-1];

	printf("Converted parameters: %x %x %x\n",house,unit,xfn);

	initialise_comms();
	putX10();
}
 
Checks if these if the poll request coming from TW523S10 is 0x0 (ready to transmit) then sends the relevant serial commands.
int putX10()
{
	unsigned char rstr[12];
	int len;

	len = read(serial_fd,buf,1);

	if (len == 1) {
	printf("DATA = %x\n",(char)buf[0]);
		switch (buf[0]) {
	        case 0x10: rstr[0] = 1; write(serial_fd,(char *)rstr,1); break;
	        case 0x0: printf("sending cmd... \n");
	                  rstr[0] = house; rstr[1] = unit; rstr[2] = 0xc2;
	                  rstr[3] = house; rstr[4] = xfn; rstr[5] = 0xc2; rstr[6] = 0;
	                  write(serial_fd,(char *)rstr,7); sleep(1); exit(0); break;
	        default:  break;
		}
	}
}

Initialises comms and opens device
initialise_comms()
{
    /* open streams and init hardware */
    int err = 0, result;

    if ((serial_fd = open(serial_device_name, O_RDWR ))< 0 ) {
	    perror("SMS: could not open serial line");
        exit(1);
    }
    if (tty_raw(serial_fd) < 0) {
        fprintf(stderr, "couldn't put device in raw mode\n");
        exit(1);
    }

    //this sets baud rate and port settings
    int tty_raw(fd); 
    int fd;

    struct sgttyb temp_mode;

    if (ioctl(fd, TIOCGETP, &temp_mode) < 0) {
    	perror("TIOCGETP: ");
    	return(-1);
    }

    tty_mode = temp_mode; 
    temp_mode.sg_flags |= RAW;
    temp_mode.sg_flags &= ~ECHO;
    temp_mode.sg_ospeed = B300;
    temp_mode.sg_ispeed = B300;
 
    if (ioctl(fd, TIOCSETP, &temp_mode) < 0) {
    	perror("TIOCSETP: ");
    	return(-1);
    }
    return(0);

}

5.4. Security Security is a very important issue when we are dealing with the Internet. It is therefore essential to have a login / password facility when the user logs on the X10-SMS Gateway. Extending the notion of security one step further we can have users placed in different security groups with different privileges.

5.5. Screen shots

6. Extensions

6.1. X10-SMS Gateway without status alert
The X10-SMS Gateway could be extended as to alert the user if something has failed at their premises. In section 3 we showed that some receiver modules can be polled for status requests. 'Vital' electrical devices could be equipped with such module which are continuously polled at time intervals for their status. If a 'vital' device is manually switched off or if there is a failure, the X10-SMS Gateway could send an SMS message to the user alerting them that device X is malfunctioning.

6.2. X10-SMS Micro-Controller
We have demonstrated previously the ability to issue X10 commands using the X10-SMS gateway. The aim of the X10-SMS Micro-Controller is to replace the PC by a miniature device. This device would consist of a PIC chip and have two physical ports. One serial port to connect to the GSM phone and the other is a RJ-11 port which connects to the TW523.


The Micro-Controller would take over the job of the X10-SMS Gateway. The Micro-Controller could eventually replace the TW523 as well as the computer.

6.3. Graphical Web Interface
The X10-Web Gateway could be extended to allow the user to have a graphical view of their premises. The interface should allow the user to graphically see the status of some devices. A Java applet would be ideal for such an application. The user should also be allowed to 'drag and drop' devices into rooms.


Example of such an interface

7. Conclusions
Home Automation has been taken into a new dimension. We have clearly demonstrated that Mobile Home Automation is the birth of a brand new era open to endless possibilities.

Mobile Home Automation can be applied for your convenience. For example, living in a city such as London where the temperature can greatly vary between the morning and the evening, Mobile Home Automation can be very beneficial. Say you leave to work in the morning on a hot summery day and during the day you start to realize that the temperature aiming to go below freezing, you can then remotely turn on the heating at your home.

Mobile Home Automation can be used for critical applications. For example when UNIX servers crash, the only way that they be reset is by power them off and on. If the administrator is offsite and a critical server crashes, it could therefore be reset from anywhere at anytime!

We have clearly showed the concept of the X10-SMS Gateway and a prototype of the X10-SMS Micro-Controller has been built but unfortunately due to time constraints was not fully operational.

We have shown how Mobile Home Automation can be performed using our two main mediums of communication in this information age: the mobile phone and the Internet.

8. Acknowledgments
I would like to give special thanks to my supervisor Dr. Janko Mrsic-Flogel for all his patience, time, support and motivation throughout the project. I also would like to thank Stuart Cox for helping build a prototype of the X10-SMS Micro-Controller.

9. References


[1] Nokia, www.nokia.com
[2] Unwired Planet, www.uplanet.com
[3] Homation Systems, www.homation.com/
[4] Home Automation Inc, www.homeauto.com/
[5] Krazy Keith's World of DIY Home Automation, www.btinternet.com/~krazy.keith/
[6] Laser Business Systems, www.io.com/~lbs/
[7] Savoy Automation, www.tiac.net/users/dnelson/index.html
[8] GPA Technology, www.winpos.com
[9] Kevin Holley GSM Page, www.parsley.demon.co.uk/
[10] UK Home Automation, www.ukha.demon.co.uk
[11] WAP Forum, www.wapforum.com
[12] Redoak, www.redoak.co.uk
[13] Homepage for comp.home.autaumation, http://web.cs.ualberta.ca/~wade/HyperHome/
[14] Smart Home, www.smarthome.com
[15] X10 FAQ, http://hometeam.com/homation/x10faq/index.html
[16] X10.com, www.x10.com
[17] Hans X10 Page, www.io.com/~hattersj/
[18] European Installation BUS, www.eiba.be
[19] Consumer Electronic Bus, www.cebus.com
[20] Lonworks, www.lonworks.echelon.com
[21] GSM Cellular Radio Telephony, Joachim Tisal
[22] Home Automation Market and Technology Networks, Joe Tidd
[23] Ian Harries Homepage, www.doc.ic.ac.uk/~ih
[24] Red Rat Infrared Remote Control for PC, www.dodgies.demon.co.uk/
[25] Peter Warriner, www.ncl.ac.uk/~n07tv/index.html
[26] Living Control, www.av-tech.co.uk/mrs/
[27] Home Toys, www.hoemtoys.com
[28] Baran-Harper Group Inc, www.baran-harper.com
[29] Lutron, www.lutron.com
[30] Custom Solutions, www.csi3.com
[31] Thomas Dolsky's Sytem, www.tomtek.com/HA/index.html
[32] Mister House, www.isl.net/~winter/house/Welcome.html
[33] The Farquhar Family, http://home.sprynet.com/sprynet/lfar/
[34] Home Automation Magazine, www.homeautomator.com/homevision.htm
[35] Home Team, www.hometeam.com
[36] Tom's House, www.traxsoft.com/emp/tc/myhouse.htm
[37] Zeus Intelligent Home Control, www.traxsoft.com/emp/tc/zeushome.htm
[38] Trigger's Home Automation, www.geocities.com/ResearchTriangle/7793/
[39] Stephen W. Nolen's Home Automation System, www.protowrxs.com/ha/