001package ca.bc.webarts.tools.isy;
002
003import com.universaldevices.common.Constants;
004import com.universaldevices.resources.errormessages.Errors;
005import com.universaldevices.security.upnp.UPnPSecurity;
006import com.universaldevices.soap.UDHTTPResponse;
007import com.universaldevices.upnp.UDProxyDevice;
008
009
010
011/**
012 * This class is simple ISY Insteon Client which enables you to do everything (except trigger)
013 * that can be done from the applet through command prompt.
014 * @author UD Architect
015 *
016 */
017public class isyCmd  {
018  protected static IsyInsteonClient myISY = null;
019
020  public static boolean subscribe(String url)
021  {
022    if (myISY == null)
023      return false;
024    UDProxyDevice dev= myISY.getDevice();
025    if (dev == null || !dev.isOnline)
026      return false;
027    StringBuffer body=new StringBuffer();
028    body.append("<reportURL>");
029    body.append(url);
030    body.append("</reportURL><duration>");
031    body.append(Constants.UD_SUBSCRIPTION_DURATION);
032    body.append("</duration>");
033
034    UDHTTPResponse res = dev.submitSOAPRequest("Subscribe",body,UPnPSecurity.SIGN_WITH_HMAC_KEY,false,false);
035    if (!res.opStat || res.body == null)
036    {
037      Errors.showError(res.status,null,myISY.getDevice());
038      return false;
039    }
040    System.out.println(res.body);
041    return true;
042
043  }
044  /**
045   * @param args
046   */
047  public static void main(String[] args)
048  {
049    System.out.println("connecting to isy...");
050    myISY=new IsyInsteonClient(true);
051    Errors.addErrorListener(new MyISYErrorHandler());
052    try{
053      /**
054       * if UPnP use:
055       */
056    //  myISY.start();
057      //myISY.start("uuid:00:03:f4:02:af:74","https://udi.isy-mobile.com/desc");
058      myISY.start(); //myISY.getDevice().uuid,myISY.getDevice().getURLBase().toString());
059      while(myISY.getDevice()==null || !myISY.getDevice().isOnline)
060        Thread.sleep(5000);
061
062      System.out.println("Subscribing to "+myISY.getDevice().getURLBase().toString()+"/ORServer/events/"+myISY.getDevice().uuid);
063      if (!subscribe(myISY.getDevice().getURLBase().toString()+"/ORServer/events/"+myISY.getDevice().uuid))
064      {
065        System.out.println("Could not subscribe");
066      }
067
068      //myISY.start("uuid:00:03:f4:02:20:28","http://192.168.0.221/desc");
069      while (true)
070      {
071        Thread.sleep(10000);
072
073        /*myISY.changeNodeState("X10", "1", "A2");
074        Thread.sleep(5000);
075        myISY.changeNodeState("X10", "5", "B");
076        Thread.sleep(5000);*/
077
078      }
079      /**
080       * else use:
081       */
082      //myISY.start("uuid:00:03:f4:02:af:74","http://udi.isy-mobile.com");
083      //myISY.start("uuid:00:03:f4:02:af:80","http://isy.mbdatasystems.com");
084    }catch(Exception e){
085      e.printStackTrace();
086    }
087
088
089  }
090
091}