Internet Toaster Project
- SIP library Integration with x10 API -

Koji Kikkawa
Columbia University
1214 Amsterdam Avenue New York, NY 10027
USA
kk522@columbia.edu

Abstract

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 realize controlling x10-connected appliances from SIP clients. Through the work of this project, I have developed integration of SIP library with x10 API so that SIP clients can use.

Introduction

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 control device with SIP message, "DO" method is used, which was proposed in the draft of the ietf group. Since the SIP clients are linked SIP library [3]to handle SIP messages, I add "DO" methods to the SIP library. In the "DO" method, x10 APIs are called to get and set the data for x10 devices.
x10 API is a function that allows Unix workstation to control devices by transmitting information over power lines. There is a x10 driver program for Unix made by Tanji[4], I have redefined x10 APIs and implemented them because it is a command based program. I have some modification to the x10 driver program so that SIP library can call to get and set the data for x10 devices.

In this project, I have made the following software, which are developed and tested on sun Solaris machine.

  • x10 APIs for Unix and test program
  • "DO" command handler for to libsip++ and embedding x10 APIs
  • Scripts for siptc(turn lamp on/off/dim)

    Architecture

    System Structure

    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 siptc and sipc work on other Unix workstations.


    Fig. System Structure

    Software architecture

    The software architecture is shown in the following figure. Siptc, SIP client program for SIP, reads a script, which contains SIP messages (e.g. "Lamp on"), and sends DO commands to sipua. After receiving the DO command, sipua calls OnIncomingRequest() function and passes DO commands to the function. Then the function calls x10 APIs and gets data according to the commands such as on/off/dim/bright/version/info/date. If the x10 API is successful, OnIncomingRequest() returns the response to the client with OK status. Otherwise, OnIncomingRequest() returns the error response.


    Fig. Software Architecture

    Program Documentation

  • System requirements
    Required OS: Solaris, Linux
    Required Software: sipua,libsip++,x10 API
    Required Hardware: x10 Adapter(CM11A,LM465,RR501)
    

    x10 API

  • Features of x10 API
    x10 API is a function to control x10 devices, which can control
     the following commands,
    - Turn On/Off/Dim/Bright 
    - Get device information
    - Get x10 API version
    - Get x10 device time
    
  • Definition of x10 API
    Function name:  int x10command(char *ptr, void* out)
    
    Description:  Function for sending commands for x10 control
    
    Parameter:   char *ptr   command string for x10
     version                 prints the version
     date                    returns date in date(1) input format
     info                    gets current settings
     turn ann[,nn...] on|off|dim|bright [vv]
                           changes state of housecode a, unit nn by vv
    Parameter:   void *out  output data
     version                 char *
     date                    char *
     info                    struct dev_info *dev_info_ptr
     turn                    struct dev_info *dev_info_ptr
    
    Return value:  -1 Fail    0 Success
    
    NOTE: /* structure for x10 device info */
    struct dev_info{
      int Irev, Idays, Ihours, Iminutes, Ijday, Iseconds;
      int Istatdim, Istatmon, Iaddmon;
      unsigned char Ihcode;
    };
    
    
  • Test program for x10 API
    Siptest is the test program for x10 API for debugging.
    
    Operation example)
    %siptest               : Execute command
    %input>info            : Get device info
    %input>date            : device date
    %input>version         : x10 API version
    %input>turn a1 off     : turn module a1 off
    %input>turn a2 on      : turn module a2 on
    %input>turn a2 dim 10  : dim module a2 
    %input>q               : exit
    
  • Installation instructions to build x10 library(libx10.a)
    This operation is done in Solaris(muni)
    %cd sipua/x10
    %make -f Makefile.sun
    %cp x10config ~/.x10config
    NOTE: .x10config is the configuration file for x10.
           copy to HOME directly as a new name
    
  • Configuration file for x10 API
    -.x10config
    ".x10config" is used for configuration x10 API and setting some variables
     and to define aliases for your x10 modules. See the details for setting
     comments of the .x10config. For example, TTY is /dev/ttyb in Solaris
     and /dev/ttyS0 in linux.
    
  • Files related to x10 API
    x10sip.c      x10 API for control
    x10cont.h     header for x10 API
    siptest.c     test program for common function for x10 control
    Makefile.sun  Makefile for sun
    Makefile.linux Makefile for linux
    .x10config     configuration file for x10.Other files   original files
    info.c      x10 API for control
    version.c      x10 API for control
    turn.c      x10 API for control
    date's      x10 API for control
    Other files   original files from [2]
    

    Modification to libsip++

  • Features
    To handle "DO" command, I implemented OnDo() in DoIncomingRequest()
     in sipintf.cpp. OnDo() has the following features,
    - parses DO messages and reads house code,
    - calls x10 API,
    - supports DO commands such as info, version, date, turn on/off/dim/bright,
    - response SIP message to SIP client,
    - print out device information, and
    - error handling
    
  • Files related to libsip++
    sipintf.cpp   implementation for OnDo()
    x10cont.h     header for x10 API
    x10cmdint.h   header for x10 API
    sipnamemap.csv    map for house code and device name
    dolampon      script file for siptc
    Other files   original files from libsip++[1]
    
  • Installation instructions to build sipua and libsip++
    This operation is done in Solaris(muni)
    %cd sipua
    %mkdir sun
    %cd sun
    %../configure -with-db=/proj/irt-gc4/cinema/sun5 
     -with-ldap=/proj/irt-gc4/cinema/sun5 
    %make sipua
    
    NOTE: When you make sipua and libsip++.a, you have to link libx10.a
    
  • Configuration file for libsip++
    - sipnamemap.csv
    "sipnamemap.csv" is used for mapping house codes and device names. 
    The format of the file is as follows,
    ----------------------
    # sipnamemap.csv
    #Housecode,sipname
    a1,lamp
    a2,smalllamp
    ----------------------
    
  • Operation
    This operation is done in Solaris(muni)
    
    Server: %sipua -p port
    
    See details of sipua at sipua
    
    Client: %siptc -u -s server -p port scriptfile
    
    ------------------------------------------
    NOTE:
    1. When you execute sipua with libsip++, serial device should be read
     and written (For example, TTY is /dev/ttyb in Solaris and /dev/ttyS0
     in linux.)
    2. To execute sipua correctly, sipnamemap.csv should be in the same
     directly as sipua.
    3. In sipua/sipd/test, there are scripts for sending do command, 
    such as "dolampon", "dolampoff". you can test it with siptc.
    4. When x10 does not seem to work, kill zombie process whose name is sipua.
    
  • SIP Message Format
    The requests and responses for DO commands such as on/off/dim/bright/info/
    version/date) are as follows. In these example, client and server are muni machine.
    ------------------------------------------
    Request from client to server
    (On/Off/Dim/Bright/info/version/date commands)
    ------------------------------------------
    DO sip:lamp@muni.cs.columbia.edu SIP/2.0
    From: sip:kk522@columbia.edu
    To: sip:lamp@muni.cs.columbia.edu
    Via: SIP/2.0/$T $H:$P
    Call-ID: 123@ibm.com
    CSeq: 208 DO
    Contact: sip:kk522@128.59.19.251:5060
    Content-type: application/dmp
    Content-Length: 114
    
    <?xml version="1.0"?>
    <DMPAction>
    <Device>lamp</Device>
     <Control>
        <Action>On</Action>
     </Control>
    </DMPAction>
    
    ------------------------------------------
    NOTE: 
    1. The message starts with DO.
    2. Device name is the name between <Device> and </Device> tags.
       The house code of the device name is defined in the sipnamemap.csv file.
    3. Action is the name between <Action> and </Action> tags.
       Actions are as the followings,
       To turn on lamp, the action is either of "On" or "on."
       To turn off lamp, the action is either of  "Off" or "off."
       To dim lamp, the action is either of  "Dim value" or "dim value."
       To bright lamp, the action is either of "Bright value" or "bright value."
       To get info of the device, the action is "info."
       To get date of the device, the action is "date."
       To get version of the device, the actions is "version."
    4. The body of the message is defined as xml format.
       Please see the details in the reference.
    
    ------------------------------------------
    Response from server to client
    (On/Off/Dim/Bright/info commands)
    ------------------------------------------
    Received t=977537674.825 from=128.59.19.27:38037:
    SIP/2.0 200 OK
    Via: SIP/2.0/UDP ind.cs.columbia.edu:38035
    From: sip:kk522@columbia.edu
    To: sip:lamp@muni.cs.columbia.edu
    Call-ID: 123@ibm.com
    Cseq: 208 DO
    Date: Sat, 23 Dec 2000 02:14:34 GMT
    Server: SIPUA-Columbia-University/1.0
    Content-Length: 687
    Content-Type: application/dmp
    
    <?xml version="1.0"?>
    <DMPResponse>
    <Device>lamp</Device>
     <ControlResponse>
          <Variable>Irev</Variable>
             <Value>1</Value>
          <Variable>Ihours</Variable>
             <Value>0</Value>
          <Variable>Iminutes</Variable>
             <Value>0</Value>
          <Variable>Idays</Variable>
             <Value>242</Value>
          <Variable>Ijday</Variable>
             <Value>102</Value>
          <Variable>Ihcode</Variable>
             <Value>m</Value>
          <Variable>Iaddmon</Variable>
             <Value>0x0000</Value>
          <Variable>Istatmon</Variable>
             <Value>0x0000</Value>
          <Variable>Istatdim</Variable>
             <Value>0x0000</Value>
     </ControlResponse>
    </DMPResponse>
    ------------------------------------------
    NOTE:
    1. The message starts with DO.
    2. <ControlResponse> tag contains <Variable> tags, which have 
      multiple variables as the followings.
      Irev: revision
      Ihours,Iminutes,Idays, Ijdays: time that CM11A adapter has.
      Ihcode: house code
      Iaddmon: last accessed device
      Istatmon: status of the monitored device
      Istatdim: status of the dimmed device
    3.The body of the message is defined as DMP(Device Message Protocol) format. 
       Please see the details in the reference.
    
    ------------------------------------------
    Response from server to client (date command)
    ------------------------------------------
    Received t=977537895.835 from=0.0.0.0:33650:
    SIP/2.0 200 OK
    Via: SIP/2.0/TCP ind.cs.columbia.edu:33650
    From: sip:kk522@columbia.edu
    To: sip:lamp@muni.cs.columbia.edu
    Call-ID: 123@ibm.com
    Cseq: 208 DO
    Date: Sat, 23 Dec 2000 02:18:15 GMT
    Server: SIPUA-Columbia-University/1.0
    Content-Length: 171
    Content-Type: application/dmp
    
    <?xml version="1.0"?>
    <DMPResponse>
    <Device>lamp</Device>
     <ControlResponse>
          <Variable>Date</Variable>
             <Value>12345678</Value>
     </ControlResponse>
    </DMPResponse>
    ------------------------------------------
    Response from server to client(version command)
    ------------------------------------------
    Received t=977537873.304 from=0.0.0.0:33649:
    SIP/2.0 200 OK
    Via: SIP/2.0/TCP ind.cs.columbia.edu:33649
    From: sip:kk522@columbia.edu
    To: sip:lamp@muni.cs.columbia.edu
    Call-ID: 123@ibm.com
    Cseq: 208 DO
    Date: Sat, 23 Dec 2000 02:17:53 GMT
    Server: SIPUA-Columbia-University/1.0
    Content-Length: 174
    Content-Type: application/dmp
    
    <?xml version="1.0"?>
    <DMPResponse>
    <Device>lamp</Device>
     <ControlResponse>
          <Variable>Version</Variable>
             <Value>001</Value>
     </ControlResponse>
    </DMPResponse>
    
    
  • Error handling
    The error code for the SIP response is as follows,
    - Code 403  If the reqURI does not match the device in the content.
    - Code 404  If the device not found in the sipnamemap.csv.
    - Code 606  If the action not specified as the x10 API
    
  • Acknowledgements
    Thank you for continuous advise from Prof. Schulzrinne and PhD Xiaotao Wu. 
    Also Kundan Singh for teaching me libsip++ library.
    
  • Restrictions and problem
    - Retransmission with sipc communication
     When integrating this system with sipc as a SIP client, retransmission 
    may occur at sipc because libsip++ consumes time to respond the first
     message.
    
  • Future subjects
    - SUBSCRIBE and NOTIFY message handling
     This feature enables SIP clients to subscribe device to the libsip and
     to be notified when a certain event occurs at the device.
    - Integration with GUI sipc clients
     This feature enables sipc to control x10 devices directly by sending "DO" 
    or "SUBSCRIBE" commands.
    

    Task List

    Koji Kikkawa: Development and testing for both x10 API and modification of libsip++

    References

  • [1],X10 Protocol
  • [2],Session Initiation Protocol(SIP)
  • [3],SIP Library with C++ interface Kundan Singh,Columbia University, 1214 Amsterdam Avenue New York, NY 10027
  • [4], Daniel Tanji,HEYU! x10 control for Linux, Pleasanton Ca, 94588 USA.
  • [5],Device Message Protocol(DMP) An XML based format for Wide Area Communications with Networked Appliances, IETF Internet Draft.

    Last updated by Koji Kikkawa