For those who are maintaining there own web pages on their own or hosted web servers using IIS asp.net, and would like to add HS3 automation to their web pages, here is what is needed.
Your IIS Web Application or Web Site must contain an Global.Asax file with event routines that run: (1) when your application is first loaded and run to connect to HS3 and create the .hs object (2) for each time a page is loaded, retrieve the .hs object from first step, (3) when your application is unloaded by server, disconnect and destroy all used resources.
Here is example using VS 2015 Community version:
Here is a very simple Default.aspx page code behind that just retrieves and displays the HomeSeer version info from the HS3 server:
This should be enough to point you in the correct direction.
I've attached the complete set of web site files if needed.
tenholde
Your IIS Web Application or Web Site must contain an Global.Asax file with event routines that run: (1) when your application is first loaded and run to connect to HS3 and create the .hs object (2) for each time a page is loaded, retrieve the .hs object from first step, (3) when your application is unloaded by server, disconnect and destroy all used resources.
Here is example using VS 2015 Community version:
HTML Code:
Global.Asax <%@ Application Language="VB" %> <%@ Import Namespace="Scheduler" %> <%@ Import Namespace="HomeSeerAPI" %> <%@ Import Namespace="HSCF.Communication.Scs.Communication.EndPoints.Tcp" %> <%@ Import Namespace="HSCF.Communication.ScsServices.Client" %> <%@ Import Namespace="HSCF.Communication.ScsServices.Service" %> <script runat="server"> Shared ghs As HomeSeerAPI.IHSApplication Public WithEvents client As HSCF.Communication.ScsServices.Client.IScsServiceClient(Of IHSApplication) Dim Hs3IpAddress As String = "192.168.1.71" Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) '' Fires when the application is started ' '' Get HS objects as this is the development environment ghs = OpenHsConnection(Hs3IpAddress) End Sub Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) '' Fires when the application is ending ' '' Disconnect and release resources ghs.WriteLog("WebAp Sample", "WebAp Sample disconnecting from HS3") CloseHsConnection() End Sub Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) '' Fires at the beginning of each request ' '' Add HS object to Context for the web pages Context.Items.Add("HsObject", ghs) End Sub Private Function OpenHsConnection(ipAddress As String) As HomeSeerAPI.IHSApplication Dim host As HomeSeerAPI.IHSApplication Dim hs As HomeSeerAPI.IHSApplication Dim Attempts As Integer client = ScsServiceClientBuilder.CreateClient(Of IHSApplication)(New ScsTcpEndPoint(ipAddress, 10400)) Attempts = 1 TryAgain: Try client.Connect() host = client.ServiceProxy Dim APIVersion As Double = host.APIVersion ' will cause an error if not really connected Catch ex As Exception If ex.Message.ToLower.Contains("timeout occurred.") Then Attempts += 1 If Attempts < 6 Then GoTo TryAgain End If If client IsNot Nothing Then client.Dispose() client = Nothing End If Return Nothing End Try Try ' create the user object, accessed from each Web Page hs = host hs.WriteLog("WebAp Sample", "WebAp Sample Connection to HS3 Successful") Catch ex As Exception Return Nothing End Try Return hs End Function Private Sub CloseHsConnection() ' disconnect from server for good here client.Disconnect() If client IsNot Nothing Then client.Dispose() client = Nothing End If End Sub Private Sub client_Disconnected(ByVal sender As Object, ByVal e As System.EventArgs) Handles client.Disconnected CloseHsConnection() End Sub </script>
Here is a very simple Default.aspx page code behind that just retrieves and displays the HomeSeer version info from the HS3 server:
Code:
Default.aspx.vb Partial Class _Default Inherits System.Web.UI.Page Friend hs As HomeSeerAPI.IHSApplication Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load '' Get HS object hs = Context.Items("HsObject") '' Retrieve and display HS Server Version If hs Is Nothing Then Response.Write("Could not connect to HS3") Else Response.Write("HomeSeer Version = " & hs.Version) End If End Sub End Class
I've attached the complete set of web site files if needed.
tenholde
Comment