Announcement

Collapse
No announcement yet.

Web Service API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Web Service API

    Hey, I'd like to build a web app that interfaces with HomeSeer, but before I get too far along, I'm just wondering if there are any existing public interfaces, specifically web services already built into HS.

    I know this is going to sound kind of dumb, but I'm thinking about creating a Facebook application allowing only Facebook friends to turn on/off a specific light. Then, someday maybe I'll hook up a webcam or something so you can see that it's on or not.

    The reason I'm thinking of using Facebook as the front end instead of a simple public web app or HS itself, really comes down to security. I don't want everyone to have access to this, only people I"ve authorized as my "friends".

    I apologize for the basic question, hopefully there's already something built in I can use.

    Thanks!

    #2
    Note that the HS Webserver does not support web services. I put in a help desk request but it didn't seem it was going to be implemented. As a start if you are going to use web services, it looks like you are going to need to run IIS or basically something else besides the standard HS web server.

    Comment


      #3
      HomeSeer can do asp and aspx applications so unless you want a true web server that supports SOAP and WDSL then you should be able to create web apps that will act as a web service.
      💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

      Comment


        #4
        Agreed. I'm adding what amounts to a web service. Not using SOAP, but a roll your own xml based protocol.

        Comment


          #5
          Originally posted by Rupp View Post
          HomeSeer can do asp and aspx applications so unless you want a true web server that supports SOAP and WDSL then you should be able to create web apps that will act as a web service.
          I created an HS aspx web page that I am accessing remotely to get some HS info. The vb.net function I use is below. My problems are
          1) I have to execute it twice to be able to login. It fails with an error and I immediately execute it again it works without fail. I think that this is similar to having to login twice into HS remotely.
          2) Eachtime I execute the script my login user number on HS goes up. This the user you see on the login screen something like Homeseer1 or Homeseer34, etc. Eventually HS freezes and I have to restart it.

          Anyone have any example vb.net code to login to HS without these issues?

          Code:
              Private Function GetWebPageData(ByVal URL As String, _
                      ByVal UserName As String, _
                      ByVal Password As String, _
                      ByVal IsWindowsAuthentication As Boolean) As String
          
                  Dim request As HttpWebRequest
                  Dim response As HttpWebResponse = Nothing
                  Dim reader As StreamReader
                  Dim result As String = String.Empty
          
                  Dim address As New Uri("http://" & URL)
          
                  Try
                      ' Create the web request
                      request = DirectCast(WebRequest.Create(address), HttpWebRequest)
                      request.KeepAlive = True
          
                      If IsWindowsAuthentication = True Then
                          ' Add Windows Authentication to request
                          request.Credentials = New NetworkCredential(UserName, Password)
                      Else
                          ' Add Basic Authentication to request
                          ' Note: To pass both the username and password in basic mode, the values
                          ' need to be colon delimited (e.g. usernameassword) before the values
                          ' are base64 encoded.
                          Dim encPwd As String = String.Format("{0}:{1}", UserName, Password)
                          encPwd = Convert.ToBase64String(Encoding.ASCII.GetBytes(encPwd))
                          request.Headers.Add("Authorization", "Basic " & encPwd)
                      End If
          
                      ' Get response
                      response = DirectCast(request.GetResponse(), HttpWebResponse)
          
                      ' Get the response stream into a reader
                      reader = New StreamReader(response.GetResponseStream())
          
                      ' Read the whole contents and return as a string
                      result = reader.ReadToEnd()
                      If Not reader Is Nothing Then reader.Close()
                  Catch wex As WebException
                      ' This exception will be raised if the server didn't return 200 - OK
                      ' Try to retrieve more information about the network error
                      If Not wex.Response Is Nothing Then
                          Dim errorResponse As HttpWebResponse = Nothing
                          Try
                              errorResponse = DirectCast(wex.Response, HttpWebResponse)
                              result = String.Format("Error--The server returned '{0}' with the status code {1} ({2:d}).", _
                              errorResponse.StatusDescription, errorResponse.StatusCode, _
                              errorResponse.StatusCode)
                              hs.WriteLog("Get_rs_temps.vb", "GetWebPageData()-error = " & result)
                          Finally
                              If Not errorResponse Is Nothing Then errorResponse.Close()
                          End Try
                      End If
                      hs.WriteLog("Get_rs_temps.vb", "error = " & wex.Message)
                  Finally
                      If Not response Is Nothing Then response.Close()
                  End Try
          
                  Return result
          
              End Function
          James

          Running HS 3 on Win10 .

          Comment


            #6
            Maybe I'm oversimplying but for the web service I created I've created a function that handles the connection. Through IIS I have it setup so that the web service will only respond to to 127.0.0.1. Here's the function:

            Private Sub ConnectToHomeseer(ByVal sHSServerIPAddress As String, ByVal sHSServerUserName As String, ByVal sHSServerPassword As String)
            Dim Result As String

            Try
            '* Attempt to connect to Homeseer
            If Not blnHomeseerConnectionOpen Then
            '* No connection open yet so open it now.
            oHomeSeer.SetHost(sHSServerIPAddress)
            Result = oHomeSeer.Connect(sHSServerUserName, sHSServerPassword)

            If Result <> "" Then
            Throw New Exception("Homeseer Connection Failed: " & Result)
            Else
            hs = oHomeSeer.GetHSRef
            blnHomeseerConnectionOpen = True
            End If
            End If

            Catch ex As Exception

            End Try
            End Sub

            Comment


              #7
              I hadn't tried that approach. Will give it a try. Thanks for your post.
              James

              Running HS 3 on Win10 .

              Comment

              Working...
              X