Home networking has become popular in USA. The most popular
home networking protocol is x10 [1],
which has a lot of products in the market today. Also there is a
big demand for controlling home appliances from internet.
In addition to that Session Initiation Protocol(SIP)[2] for setting
up, controlling sessions has become popular in the field of
internet telephone calls and electric appliances. With its
feature of signaling message, it is suitable for controlling
devices from remote environment.
The goal of this project is to implement event notification
service for clients. Through the work of this project, I have
implemented SIP Subscribe method and Notify method.
In the SIP client and server system, clients request SIP
messages to servers and get response message from servers. SIP
message has header info, which includes tags for controlling
method, client properties and the body, which includes media info
for exchanging data between client and server. The details of the
SIP message format are shown in the references.
To subscribe a presence with SIP message, "Subscribe"
method is used, which was proposed in the draft of the ietf
group. I add "Subscribe" methods to the SIP library. In
the "Subscribe" method, the SIP gateway add, update, or
delete a subscription record stored in the xml file, and return
the current status of the device to the subscriber by calling x10
APIs.
To notify subscriber, the SIP gateway listen the device event. If
some device event happens, the listener thread will notify
subscriber by going through the subscription records in the xml
file.
In this project, I have made the following software, which are
developed and tested on sun Solaris machine.
Add "SUBSCRIBE" command handler to libsip++, and add
event listener to the sipua to implement the "NOTIFY"
method.
Koji Kikkawa implemented "DO" command for sip device control project.
System structure is shown in the following figure. CM11A(x10 adapter) is connected to Unix workstation(sun) via serial line and other CM11A adapters through power line. Electric appliances are connected to CM11A. SIPUA(SIP User Agent) works on the Unix workstation and client programs such as sipc work on other Unix workstations.
The software architecture is shown in the following figure. Sipc, SIP client program for SIP, sends SUBSCRIBE commands to sipua. After receiving the SUBSCRIBE command, sipua calls OnIncomingRequest() function and passes SUBSCRIBE commands to the function. Then the function authenticates the subscriber. After that, it calls OnSubscribe() to process the subscription request, like adding a new subscription record, updating a old subscription record, or deleting a old subscription record. At last, it returns the current status of the device to the subscriber. When the x10 controller detects the device status change, it notify the listener in the sip device control gateway. The listener calls OnNotify(), which checks the subscription records and send notification to the subscriber.
+-----------+ SUBSCRIBE +--------------+
| | ---------------------------> | |
| | | | x10 controller
| | 200 with status | SIP Device | +---+
| sipc | <---------------------------- | Control + ----- + +
| | | Gateway | +---+
| | NOTIFY | |
| | <--------------------------- | |
| | 200 | |
| | ---------------------------> | |
+-----------+
+--------------+
After authenticating user's identity, OnSubscribe will be called to process SUBSCRIBE request.
void OnSubscribe(request_t *r)
Description: Function to process SUBSCRIBE request. This function analyzes the request, add, update, or delete subscription record in subscriptions.xml, then send the device's current status to the subscriber.
When sipua runs, it calls notifyDealer to register a callback function. When the device's status changes, the listener call OnNotify to process it.
void notifyDealer()
Description: Register callback function, which process notification event
int OnNotify(char *func, char hc, int unit)
Description: Notify the subscriber. It gets all subscription records from the subscriptions.xml, analyzes it, then send notification to the related subscriber.
All configuration files are in the user's home directory's subdirectroy ./devicegateway.
devices.xml - map device's sip address to its x10 address, and refer to the device's events xml file
lamp.xml - include all lamp's events
subscriptions.xml - record all subscriptions
sipnamemap.csv - used for DO command
sipua/main.cpp
sipua/module.mk
libsip++/sipintf.cpp
libsip++/module.mk
x10/*
To make the sipgateway, Xerces-C is required. I install xerces-c1_4 in ~xl71/xerces_sol. You can copy it directly from this directory. The root directory of sipgateway is /proj/irt-gc6/xiaotaow/xl71/proj/sipgateway. All sip libraries are installed under this directory. x10 api is also installed under this directory.
First, you need to make the x10 library.
cd /proj/irt-gc6/xiaotaow/xl71/proj/sipgateway/x10
make -f makefile.sun
Then use make sipua to generate it.
cd /proj/irt-gc6/xiaotaow/xl71/proj/sipgateway
make sipua
sipua
The error code for the SIP response is as follows, - Code 400 Error XML content
- Code 404 Device Not Found or Events Not Found - Code 500 Internal Server Error
Thank you for continuous advise from Prof. Schulzrinne, PhD Xiaotao Wu, and PhD Kundan Singh.
We have test the sip gateway in muni.
Xu Li: Development and testing for sip gateway
Last updated by Xu Li