Jump to content

Subscribing to events via Portal


Recommended Posts

Posted

I seem to be having an issue with this.  I can send commands to the portal easy enough, but I can not seem to get a response from the portal when setting up a subscription to listen for events.  This same code works find when subscribing to the ISY directly.

private void doSubscribe(String auth) {

    SSLSocket isySocketSSL;
    Socket isySocket;

    try {
      if (aisy.getSSLEnabled()) {
        isySocketSSL = ConnectionManager.getSSLSocket(aisy);
        writer = new OutputStreamWriter(isySocketSSL.getOutputStream());
        reader = isySocketSSL.getInputStream();
      } else {
        isySocket = ConnectionManager.getSocket(aisy);
        writer = new OutputStreamWriter(isySocket.getOutputStream());
        reader = isySocket.getInputStream();
      }
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }

    String subreq = "<s:Envelope><s:Body>" + "<u:Subscribe";
    subreq += " xmlns:u='urn:udi-com:service:X_Insteon_Lighting_Service:1'>";
    subreq += "<reportURL>REUSE_SOCKET</reportURL>";
    subreq += "<duration>infinite</duration>";
    subreq += "</u:Subscribe></s:Body></s:Envelope>";

    try {
      writer.write("POST /services HTTP/1.1\n");
      writer.write("Content-Type: text/xml; charset=utf-8\n");
      writer.write("Authorization: " + auth + "\n");
      writer.write("Content-Length: " + (subreq.length()) + "\n");
      writer.write("SOAPAction: urn:udi-com:device:X_Insteon_Lighting_Service:1#Subscribe\r\n");
      writer.write("\r\n");
      writer.write(subreq);
      writer.write("\r\n");
      writer.flush();
    } catch (IOException e) {
      e.printStackTrace();
      setRunning(false);
      return;
    }
    
    int content_length = 0;
    StringBuffer headerBuffer = new StringBuffer();
    int charValue;
    do { //Do once and then check for SID - REPEAT IF SID FOUND
      try {
//THIS IS AS FAR AS IT GETS - reader never gets any response data.
        while ((charValue = reader.read()) != -1) { //CONTINUE READING TILL END OF INPUT
          //DO STUFF
        }
      } catch (Exception e) {
        e.printStackTrace();
        Log.d(TAG,"Network Connection Lost");
        hasSID = false;
        if (listener != null)
          listener.onConnectionFailure();
      }
      headerBuffer.setLength(0);
    } while (hasSID);
    if (listener != null)
      listener.onConnectionFailure();
  }
Posted

Hi James,

 

1. What URL are you posting to?

2. Do you have Preferred ISY set in My Profile (my.isy.io/top right corner)?

 

With kind regards,

Michel

 

I was able to resolve this:  My SOAP knowledge is very limited so I don't really know shat I am doing with it.  

 

I changed my request to :

writer.write("POST /services HTTP/1.1\n");
      writer.write("Content-Type: text/xml; charset=utf-8\n");
      writer.write("Host: " + isy.getHost());
      writer.write("Authorization: " + auth + "\n");
      writer.write("Content-Length: " + (subreq.length()) + "\n");
      writer.write("\r\n");
      writer.write("\r\n");
      writer.write(subreq);
      writer.write("\r\n");
      writer.flush();

I guess I was adding some extra information that did not need to be included.  The ISY didn't mind, but it appears that the portal did.  

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...