Announcement

Collapse
No announcement yet.

Creating an ASPX homepage for HomeSeer

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

    Creating an ASPX homepage for HomeSeer

    I'm trying to create a Default.aspx homepage, and I'd like to be able to debug it from VS2005.

    I've spent most of the day reading through the forums, but have not been successful getting a valid connection to homeseer.

    Hopefully someone else has been through this, and can see where I'm going wrong...

    When I run the code below, I get the following error:

    Error in UnRegisterChannel: The channel 'gtcp' is not registered with remoting services

    Here is the code:

    Imports HomeSeer:

    Partial Class _Default
    Inherits System.Web.UI.Page
    Public hsinterface As HomeSeer2.application
    Public hs As Scheduler.hsapplication
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If hs Is Nothing Then

    'hsinterface = New HomeSeer2.application
    hsinterface = CreateObject("HomeSeer2.Application")

    hsinterface.SetHost("localhost:81")

    Dim rval As String = hsinterface.Connect("default", "default")
    If rval = "" Then
    hs = hsinterface.GetHSRef
    End If
    hsinterface.Disconnect()
    End If
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    If hs.ison("A2") Then
    hs.ExecX10("A2", "off", 0)
    End If

    End Sub
    End Class

    #2
    See the HowTo section for more information. You can only debug using IIS. Global.asax is the key.
    website | buy now | support | youtube

    Comment


      #3
      If I wanted to forgo the debugging in VS2005, are there any How-To documents to tell me how to connect an ASPX page to HS?

      Does anyone have a snippet of sample code?

      Comment


        #4
        I tried the How To for IIS, using the Global.asax file here:
        http://forums.homeseer.com/showthread.php?t=113751


        I'm now getting a new error:

        Can not connect to the remote host "gtcp://localhost:8737". System error message: No connection could be made because the target machine actively refused it.

        Is this a configuration setting or something else that I'm missing?

        Comment


          #5
          Was HomeSeer running when you tried it? It sounds like HS was not running.
          website | buy now | support | youtube

          Comment


            #6
            HomeSeer was running as a service at the time.

            Would it make a difference if HomeSeer was not yet licensed? I've got several licensed copies running at my home and my family's homes, but I installed it yesterday on my laptop where I have Visual Studio 2005 installed. I have 29 days left on the trial.

            Comment


              #7
              No, that won't make a difference. But try it with HS running as an application. I wonder if there is a security issue with it running as a service.
              website | buy now | support | youtube

              Comment


                #8
                I'm not sure what changed, but after rebooting this morning, it started working as expected.

                I didn't reboot yesterday, but I did stop and start the homeseer service, and that didn't make a difference.

                Thank you, Rich, for all of your help.

                Comment


                  #9
                  Hopefully someone can quickly tell me what i'm doing wrong...

                  or that i'm hopelessly lost.

                  Trying to do the above in ms visual web developer express.

                  I am trying the code above

                  default.aspx.vb
                  Code:
                  [SIZE=2][COLOR=#0000ff]
                  Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] class1
                  [/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] hs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object
                  [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] hssystem [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object
                  [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] hsp [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object
                  End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class
                  Imports[/COLOR][/SIZE][SIZE=2] HomeSeer:
                  [/SIZE][SIZE=2][COLOR=#0000ff]Partial[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] _Default
                  [/SIZE][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] System.Web.UI.Page
                  [/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] hsinterface [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] HomeSeer2.application
                  [/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] hs [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Scheduler.hsapplication
                  [/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Page_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Load
                  [/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] hs [/SIZE][SIZE=2][COLOR=#0000ff]Is[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Nothing[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
                  [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#008000]'hsinterface = New HomeSeer2.application
                  [/COLOR][/SIZE][SIZE=2]hsinterface = CreateObject([/SIZE][SIZE=2][COLOR=#800000]"HomeSeer2.Application"[/COLOR][/SIZE][SIZE=2])
                  hsinterface.SetHost([/SIZE][SIZE=2][COLOR=#800000]"localhost:80"[/COLOR][/SIZE][SIZE=2])
                  [/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] rval [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = hsinterface.Connect([/SIZE][SIZE=2][COLOR=#800000]"default"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"default"[/COLOR][/SIZE][SIZE=2])
                  [/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] rval = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Then
                  [/COLOR][/SIZE][SIZE=2]hs = hsinterface.GetHSRef
                  [/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
                  [/COLOR][/SIZE][SIZE=2]hsinterface.Disconnect()
                  [/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
                  [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
                  [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Protected[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button2_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Object[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click
                  [/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] hs.ison([/SIZE][SIZE=2][COLOR=#800000]"A2"[/COLOR][/SIZE][SIZE=2]) [/SIZE][SIZE=2][COLOR=#0000ff]Then
                  [/COLOR][/SIZE][SIZE=2]hs.ExecX10([/SIZE][SIZE=2][COLOR=#800000]"A2"[/COLOR][/SIZE][SIZE=2], [/SIZE][SIZE=2][COLOR=#800000]"off"[/COLOR][/SIZE][SIZE=2], 0)
                  [/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
                  [/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
                  End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class
                  [/COLOR][/SIZE]
                  I have added (in the solution explorer)
                  classes.dll
                  hsp.dll
                  homeseer2.dll
                  scheduler.dll

                  from the c:\programfiles\hs2 directory.

                  I have added (in solution explorer)
                  global.asax from the link below.. (
                  http://forums.homeseer.com/showthread.php?t=113751

                  I hit f5..

                  and i get the following error

                  Compiler Error Message: BC30002: Type 'Belikov.GenuineChannels.GenuineTcp.GenuineTcpChannel' is not defined.

                  Maybe i can't do what i'm trying...

                  I am not running IIs.. Using the built in debug server in VWDexpress

                  The project is not in the HS directory.. it is in a directory off of c:\

                  If i could get this working... i'd be able to code and debug my aspx web pages in VWDE... which is much easier for me than notepad etc..

                  Any help is appreciated.

                  Thank you

                  Andrew
                  Regards,

                  Andrew B.

                  Comment


                    #10
                    First, make sure you are using HS 2.1, all the dll references you need are in the file interop.dll, scheduler.dll, HS2Util.dll, and HomeSeer2.dll. You don't need any other dll files. Some of the files you are referencing are from HS 2.0. Put a copy of all these DLL files into a folder named "bin" that is located in the same folder as your ASPX page. This will allow VS to find a reference to them.

                    Here is a simply ASPX page that runs under IIS or the HS web server (from the HS html folder)

                    PHP Code:
                    <&#37;@ Page Language="VB" %>
                    <script runat="server">
                        
                    ' Insert page code here
                        '
                        
                    dim hs as object
                        Sub Page_Load
                    (Sender As ObjectAs EventArgs)
                            
                    ' for use with the HS web server
                            hs = Context.Items("Content")
                            If hs Is Nothing Then
                                ' 
                    maybe running under IIS
                                hs 
                    = Global.ASP.global_asax.hs
                                
                    If hs Is Nothing Then
                                    Response
                    .Write("Could not get access to HomeSeer object, is HomeSeer running?")
                                
                    End If
                            
                    End If
                            
                    label1.text "HomeSeer Ver: " hs.version
                        end sub
                        
                        Sub ButSpeak_Click
                    (sender As ObjectAs EventArgs)
                            
                    hs.speak(txtspeak.text)
                        
                    End Sub
                    </script>
                    <
                    html>
                    <
                    head>
                    </
                    head>
                    <
                    body>
                        <
                    form runat="server">
                            <
                    p>
                                <
                    asp:Label id="Label1" runat="server" width="210px">Label</asp:Label>
                            </
                    p>
                            <
                    p>
                            </
                    p>
                            <
                    p>
                                <
                    asp:Button id="ButSpeak" onclick="ButSpeak_Click" runat="server" Text="Speak"></asp:Button>
                                <
                    asp:TextBox id="TxtSpeak" runat="server"></asp:TextBox>
                            </
                    p>
                            <
                    p>
                            </
                    p>
                            <
                    p>
                            </
                    p>
                            <!-- 
                    Insert content here -->
                        </
                    form>
                    </
                    body>
                    </
                    html
                    website | buy now | support | youtube

                    Comment


                      #11
                      I got rid of my compile error... i didn't add references correctly...

                      Now i can't connect...

                      on the connect line...

                      hsinterface.SetHost("localhost")
                      Dim rval AsString = hsinterface.Connect("andrew", "password")

                      the vwde pauses with a box that says:

                      Could not load file or assembly 'HS2Util, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

                      I feel better that at least i'm compiling/building without error..
                      Regards,

                      Andrew B.

                      Comment


                        #12
                        Make sure the file hs2util.dll is in the bin folder where your aspx page is located.
                        website | buy now | support | youtube

                        Comment


                          #13
                          Yipee ! (and thanks)

                          Rich,

                          Thank you very much..

                          I copied the DLLs to the bin folder...

                          And...

                          I used a different global.asax file.. (found in post #2 in this thread http://board.homeseer.com/showthread...sual+developer )

                          and it connects and works

                          I have to wait till i get home tonight to play some more...

                          But one question:

                          In my default.aspx.vb file the H.S. functions are called using lines like:

                          status = HomeSeer2.application.hs_server.DeviceStatus("V1")

                          this works fine.. but i want Status=hs.devicestatus("V1")
                          -------------------------------------------------------------
                          I tried a line at the start of the sub saying:

                          dim hs as new homeseer2.application

                          That lets me do:

                          status = hs.hs_server.devicestatus("V1")
                          (it works)
                          -------------------------------------------------------------
                          But when i tried

                          dim hs as new homeseer2.application.hs_server

                          status = hs.devicestatus("V1")

                          It throws up an error or warning (can't remember details..)

                          -------------------------------------------------------------------
                          It's probably something to do with the global.asax file i'm using... i'll dig more when i get home... but if it's an easy answer... could you point me in right direction?

                          Thanks again for the "Copy the DLL's".. that was the biggest stumbiling block so far...

                          Andrew
                          Regards,

                          Andrew B.

                          Comment


                            #14
                            What server is hosting this ASPX page? Is the the HS server or IIS? You many not need some that code.
                            website | buy now | support | youtube

                            Comment


                              #15
                              What server is hosting this ASPX page? Is the the HS server or IIS? You many not need some that code
                              Ahh... there's probably the question that solves it all...

                              I am using the visual web developer express built in server... (I think it's a iis clone) It launches for Debug only... it's not a "Real" server in that it can only serve things in the editor..

                              Can I/should I have it use the Homeseer server instead?

                              Maybe i should back up a touch..

                              The two things i REALLY want to do:
                              =================================================
                              First
                              Use Visual Web Developer express to write ASPX pages..

                              I love the code behind/GUI editor...... not to mention breakpoint debugs... and intellisense code...

                              I figured i would create the page using Visual Web Developer Express..

                              Debug using all the Visual Web Developer good stuff..

                              Then copy my .aspx file and .aspx.vb files to the Homeseer HTML directory...

                              Edit the .aspx.vb file to get rid of the class declarations needed to run under Visual Web Developer Express... (looks to be about 3 or 4 lines)

                              And Whamo... an aspx page... debugged in Visual web developer express..

                              -------------------------------------------------------------
                              Second

                              To write just plain old scripts...

                              Do exactly the above in the Page_Load() function of a blank webpage...

                              When finished debugging... (with all the nifty VWDE debug tools)

                              Copy the Page_load Function to the scripts directory.. (sans the code and class statements that are needed to run in VWDE)...

                              Change the name from "Sub Page_Load()" to "Sub Main(param as object)"

                              And voila... a new script file that was debugged easily.....

                              ==================================
                              The only downside is:

                              Code maintenance would consist of having a VWDE "website" for each script... and only doing code changes in Visual Web Developer Expresss...

                              yes... that's two copys of code One for development (in the VWDE Directory) and one for deployment.. (in the HS Scripts or HTML directory)...

                              But the advantages of a graphical editor with debug support far outweigh the hassles...

                              ----------------------------------------

                              So....

                              Am i way off base in that i shouldn't be even trying this because:
                              It's too much of a hassle...
                              It will never work....
                              Why don't you code in notepad.exe like everyone else?...

                              Or am i on the right track?

                              Thanks so much for taking the time with me on this...

                              If it can work and if i get it working as i want... i'll post a step by step with file attachments so that anyone "roughly familiar" with ASPX, Scripting, and Visual Web Developer Express could follow along...


                              Andrew
                              Regards,

                              Andrew B.

                              Comment

                              Working...
                              X