Announcement

Collapse
No announcement yet.

.asp page to display all devices

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

    .asp page to display all devices

    In HS3 I was able to use the following code to list all my devices on an .asp page:

    Code:
    <%
    
    set EN = hs.GetDeviceEnumerator
    If EN Is Nothing Then
        response.write "Error getting Enumerator"
        response.end
    End If
    
    do
        set dv = EN.GetNext
        If dv Is Nothing Then exit Do
        response.write dv.name(Nothing) & "<br>"
    
    loop
    
    response.write "Finished"
    
    %>
    When I display this web page in HS4 I get the following error:

    Script error: Object required: 'EN'
    set dv = EN.GetNext
    If dv Is Nothing Then exit Do
    Some posts on the forum suggest that GetDeviceEnumerator has been eliminated in HS4; others say it still works. A few posts refer to a method called 'GetAllRefs' but I can't find any documentation other than what's written on Github, which to me is indecipherable.

    Can someone help me to get this simple code working on an .asp page? Thanks in advance for any advice ...

    #2
    GetDeviceEnumerator works fine...just not an asp web page.

    This works using an .aspx page:

    Code:
    <%@ Page Language="VB" %>
    <script runat="server">
    Public hs As Scheduler.hsapplication
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
    hs = Context.Items("Content")
    
    Dim EN As Scheduler.Classes.clsDeviceEnumeration
    Dim dv As Scheduler.Classes.DeviceClass
    
    EN = hs.GetDeviceEnumerator
    
    If EN Is Nothing Then
        response.write ("Error getting Enumerator")
        response.end()
    End If
    
    do
        dv = EN.GetNext
        If dv Is Nothing Then exit Do
        response.write (dv.name(Nothing) & "<br>")
    
    loop
    
    response.write ("Finished")
    
    End Sub
    
    </script>
    Jon

    Comment


      #3
      Originally posted by jon00 View Post
      GetDeviceEnumerator works fine...just not an asp web page.

      This works using an .aspx page:

      Code:
      <%@ Page Language="VB" %>
      <script runat="server">
      Public hs As Scheduler.hsapplication
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
      hs = Context.Items("Content")
      
      Dim EN As Scheduler.Classes.clsDeviceEnumeration
      Dim dv As Scheduler.Classes.DeviceClass
      
      EN = hs.GetDeviceEnumerator
      
      If EN Is Nothing Then
      response.write ("Error getting Enumerator")
      response.end()
      End If
      
      do
      dv = EN.GetNext
      If dv Is Nothing Then exit Do
      response.write (dv.name(Nothing) & "<br>")
      
      loop
      
      response.write ("Finished")
      
      End Sub
      This sounds interesting. I copied the code and saved it as a script. I did run it but nothing happened. I guess this is to run as a part of something else ?

      Comment


        #4
        No, you would save it in the html directory and call it something like devicelist.aspx

        You would then call devicelist.aspx from your Homeseer web server as a web page.
        Jon

        Comment


          #5
          Originally posted by jon00 View Post
          No, you would save it in the html directory and call it something like devicelist.aspx

          You would then call devicelist.aspx from your Homeseer web server as a web page.
          I saved it as Devicelist.aspx in the html directory. I then typed MyIP:Port/Devicelist.aspx in the address bar. I got a error page

          Server Error in '/' Application.
          Parser Error
          Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

          Parser Error Message: Unexpected end of file looking for </script> tag.

          Source Error:


          Line 1: <%@ Page Language="VB" %>
          Line 2: <script runat="server">
          Line 3: Public hs As Scheduler.hsapplication
          Line 4: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)

          Source File: /Devicelist.aspx Line: 2

          Comment


            #6
            Put this at the very bottom of the page after the 'End Sub'

            Code:
            </script>
            Jon

            Comment


              #7
              Yes thats working now. Interesting. I can imagine it be be useful having the device ref, room and device type with every device. Thats something I would have liked to have sometimes, especially on a bigger system.

              Comment


                #8
                Originally posted by mikee123 View Post
                Yes thats working now. Interesting. I can imagine it be be useful having the device ref, room and device type with every device. Thats something I would have liked to have sometimes, especially on a bigger system.
                That is what this was for: https://forums.homeseer.com/forum/3r...eer-3?t=178217

                Jon

                Comment


                  #9
                  Originally posted by jon00 View Post
                  Ok I'll grab that. Strange that I've never noticed it before

                  Comment


                    #10
                    Excellent, that worked for me - thanks so much. Is there a list somewhere of what functionality works on an .asp page and what requires .aspx? Just curious ...

                    Comment


                      #11
                      Yup, Jon's DeviceListViewer is really invaluable for not just finding the odd device but also all the info needed if you are writing any scripts or immediate commands.

                      Comment


                        #12
                        Jon, using the .aspx code you posted (which works in an .aspx page) is causing some other problems for me - basically, I need to convert a very long and complex script to aspx from asp, and I'd rather not go through that if I don't have to. Isn't there a way to enumerate and get access to all devices on an .asp page? It seems odd that this is not possible.

                        Thanks in advance for any help you or others can provide.

                        Comment


                          #13
                          I think the issue is that Scheduler.Classes.clsDeviceEnumeration is not referenced correctly in VBScript within HS4.

                          I very much doubt there will support changes for this as vbs/asp is dead in the water and has never worked on Linux either.

                          You could define this code in a vb.net script and use the hs.runscriptfunc in your asp page to return the result.
                          Jon

                          Comment


                            #14
                            Jon,

                            Thanks for the quick reply. I assume hs.runscriptfunc allows an asp page to call a vb.net script and take the output in a similar fashion to a function returning values? If that is correct, could you point me towards the documentation in HS4 for how to use this function? Of course, given the state of HS4 documentation I can't find that - would I just use the HS3 documentation?

                            Thanks.

                            Comment


                              #15
                              Correct for both points...the hs4 scripting documentation is not finished. The hs3 documentation is valid in HS4.
                              Jon

                              Comment

                              Working...
                              X