Announcement

Collapse
No announcement yet.

How to Setup a Basic .ASP Page to Access HS?

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

    How to Setup a Basic .ASP Page to Access HS?

    I'm looking for a working sample .ASP(Not ASPX) webpage to get started. I found the sample .ASPX page that HS provides but don't see an .ASP sample.
    Does anyone have a basic .ASP webpage that:
    1) Connects to HS
    2) Reads a Device Status
    3) Writes a value to a Device Status
    4) Has some Javascript code interacting with the VB code.
    Thanks for the help.
    The HS Server has a limited capability to handle .ASPX and I have a bunch already running--so I thought I would switch to .ASP which I understand is more reliable(from other Forum members)

    #2
    Originally posted by BobSpen View Post
    I'm looking for a working sample .ASP(Not ASPX) webpage to get started. I found the sample .ASPX page that HS provides but don't see an .ASP sample.
    Does anyone have a basic .ASP webpage that:
    1) Connects to HS
    2) Reads a Device Status
    3) Writes a value to a Device Status
    4) Has some Javascript code interacting with the VB code.
    Thanks for the help.
    No connection is required.

    See if the following can get you going:


    Code:
    Test.asp:
    
    <%
    Dim B1
    B1=request.form("button1")
    Response.write hs.GetPageHeader("", "", "", "", False, False, True, False, False)
    Response.write hs.GetPageHeader("", "Test Page", "", "", False, True, False, False, False)
    Response.write "Homeseer version: " & hs.version
    %>
    <br><br>
    <form method="post">
    <label for="button1">Input value: </label>
      <input type="text" id="button1" name="button1"><br><br>
    </form>
    <%
    If B1 <> "" Then
    Response.write "Value submitted: " & B1
     'hs.SetDevicevalueByRef 1234, B1, True
    end if
    %>
    Jon

    Comment


      #3
      Thanks jon00, I'll give it a go.....

      Comment


        #4
        Jon00,
        Been busy with other project and just now getting back to this. Your example works fine but when trying to extend it to the kinds of "selects" I would like to use it does not seem to fly. Couple of questions if you would be so kind:
        1) What's wrong with my code(attached)-using my device "285"(this device works with your code above)
        2) the action-reaction I really want is when loading the page, is to preload the "heating setpoint", the current temp, and the "cooling setpoint"; then when the user selects a heating or cooling setpoint, wait about 2-3 seconds before sending to HS and if user changes a setpoint within that 2-3 seconds send only the new selection. is that possible w/o javascript and if so how to mix VBScript and JavaScript on the same page.

        RGS ThermostatsTEST4.txt (Change .txt to .asp)

        Thanks so much for your help!
        Attached Files

        Comment


          #5
          Hi Bob,

          Please try the attached which should provide the functionality required. This demonstrates the use of JavaScript for the 3 second page submission delay.

          You need to change the device value ref ID's to suit your current temp and cool/heat setpoints .

          Let me know if it functions correctly....

          Attached Files
          Jon

          Comment


            #6
            It works perfectly. Thank you; Now I just have to understand how you did it.

            I have 3 thermostats in the home so I plan on replicating whatever code I end up with for one Thermo, twice more down the page. Other than name changes so each is unique, should I watch out for anything else?
            Thanks again, this really helps.

            Comment


              #7
              Originally posted by BobSpen View Post
              It works perfectly. Thank you; Now I just have to understand how you did it.

              I have 3 thermostats in the home so I plan on replicating whatever code I end up with for one Thermo, twice more down the page. Other than name changes so each is unique, should I watch out for anything else?
              Thanks again, this really helps.
              Not that I can see. Just copy the select/input using different names etc should suffice.
              Jon

              Comment


                #8
                Jon00,
                I jumped the gun a bit--it works perfectly AFTER the first selection of a heating or cooling setpoint. In other words the heating and cooling "selects" are not initialized with the first value from HS. Simple fix?
                Thanks

                Comment


                  #9
                  I can't reproduce but change this in the code to ensure that only values above 69 can be set:


                  Code:
                  If IsNumeric(H1) Then
                  If H1 > 69 Then hs.SetDevicevalueByRef HSetpointRef, H1, True
                  End if
                  
                  If IsNumeric(C1) Then
                  If C1 > 69 Then hs.SetDevicevalueByRef CSetpointRef, C1, True
                  End if
                  Jon

                  Comment


                    #10
                    jon00,
                    I think you discovered another part of the initialization problem. Before the code above you suggested adding, when the page first loads H1 and C1 are zero, and both HS devices (setpoints) were set to zero immediately. I'm having a problem understanding why send anything to HS before the form is changed? Before the code correction above, when I initially load the page(not a refresh) the "Selects" both display "80"; in Chrome,Edge, and IE. Your not seeing that?

                    Comment


                      #11
                      No, because I was using fixed values. The code change I suggested was because I suspected the device value was being set to 0 when first called.
                      Jon

                      Comment


                        #12
                        jon00,
                        Yes you were right. Can you briefly explain the sequence of code that gets run on the first page load? Same question for when a new option is selected. That's where I am not understanding.
                        Thanks

                        Comment


                          #13
                          When you first call the page, it will read the 2 form values (which should be blank or 0).

                          This values are not saved to the virtual devices because they need to be numeric and above 69 in value.

                          The current values are then read from Homeseer and displayed.

                          The drop-downs display the correct value because when matched (current temp vs drop-down temp, whilst creating the drop-down) the option value has the text 'selected' at the end. https://www.w3schools.com/tags/att_option_selected.asp

                          When you make a selection, it's onchange attribute is set to run a 3 second JavaScript timer which then runs a JavaScript form submit operation. Until the page is submitted, you can make changes to any drop-down as you wish.

                          The page refreshes, new form values read and updates the virtual devices (because they now have values above 69) and then loads the page again as described above.
                          Jon

                          Comment


                            #14
                            Thank you, that helps a lot.
                            One last question: What causes the "page refresh"? Is it the "submit" and is that why you put the setting of the virtual devices(and then the actual setting of the HS devices) at the beginning of the routine?

                            Comment


                              #15
                              Any html form which is submitted causes a page to refresh so it can post the changes. This is normally done manually through pressing a submit button on the page but in this case is done via JavaScript.

                              You need to set the virtual devices with the changes and then read those devices so that the page displays the correct values.
                              Jon

                              Comment

                              Working...
                              X