Announcement

Collapse
No announcement yet.

Can't seem to get an HTTP PUT working for some reason...

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

    Can't seem to get an HTTP PUT working for some reason...

    Hi there,

    I can't seem to figure out the errors I'm getting when trying to do an HTTP PUT to a website. I've pretty much followed the examples I've seen online. Do I not have something installed on my HS3 Zee 2 that I need to run this? I suppose I can just call a curl command but I would prefer to use native code to do this. Any thoughts?

    Thanks, Chris

    Code:
    IMPORTS System.IO
    IMPORTS System.Net
    
    Sub Main(Parm As Object)
    
    Dim httpWebRequest = DirectCast(WebRequest.Create("http://192.168.1.50:3000/state/circuit/toggleState"), HttpWebRequest)
    
    httpWebRequest.ContentType = "application/json"
    
    httpWebRequest.Method = "PUT"
    
    Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream().ToString)
    
            Dim json As String = "{""id"" : ""3""}"
    
            streamWriter.Write(json)
    
    End Using
    
    Dim httpResponse = DirectCast(HttpWebRequest.GetResponse(), HttpWebResponse)
    Using streamReader = New StreamReader(httpResponse.GetResponseStream().ToString)
    Dim responseText = StreanReader.ReadToEnd()
    hs.WriteLog("Response", responseText)
    
    End Using
    
    End Sub
    When I manually run this, I get the following logs:
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: 'End Namespace' must be preceded by a matching 'Namespace'.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Identifier expected.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Expected 'End'.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: Expected 'End'.
    Sep-07 5:35:52 PM Error Compiling script /usr/local/HomeSeer/scripts/back_ll_on.vb: End of statement expected.

    #2
    Whatever I did wrong, I guess I'll never know. I did this script instead and it seems to work although it didn't yesterday. Maybe I was tired...

    Code:
    Imports System.IO
    Imports System.Net
    Imports System.Web
    
    Sub Main(ByVal Parms As Object)
    
    Dim logName As String = "Pentair"
    Dim debug As Boolean = True
    Dim json As String = "{""id"" : ""3""}"
    
    If Debug Then hs.writelog(logName, "Command: " & json)
    
    Dim strURL as String = "http://192.168.1.50:3000/state/circuit/toggleState"
    Dim myWebReq As HttpWebRequest
    Dim myWebResp As HttpWebResponse
    Dim encoding As New System.Text.UTF8Encoding
    Dim sr As StreamReader
    
    Try
    Dim data As Byte() = encoding.GetBytes(json)
    myWebReq = DirectCast(WebRequest.Create(strURL), HttpWebRequest)
    myWebReq.ContentType = "application/json; charset=utf-8"
    myWebReq.ContentLength = data.Length
    myWebReq.Method = "PUT"
    Dim myStream As Stream = myWebReq.GetRequestStream()
    
    If data.Length > 0 Then
    myStream.Write(data, 0, data.Length)
    myStream.Close()
    End If
    
    myWebResp = DirectCast(myWebReq.GetResponse(), HttpWebResponse)
    sr = New StreamReader(myWebResp.GetResponseStream())
    Dim responseText As String = sr.ReadToEnd()
    
    If Debug Then hs.WriteLog(logName, "Response: " & responseText)
    
    Catch ex As Exception : hs.writelog(logName, "Error: " & ex.Message.ToString)
    
    End Try
    
    End Sub

    Comment


      #3
      Dim responseText = StreanReader.ReadToEnd()

      Comment


        #4
        Originally posted by rge View Post
        Dim responseText = StreanReader.ReadToEnd()
        Oh my. Thank you much. I looked at the code for an hour and didn't see it.

        Comment


          #5
          Dear sirs and those far more knowledgeable than I... I have spent the last two years waiting on Autelis to become a reality. I have read all the conversations and ... well it is time to move forward. I want to integrate my Hayward pool management with my Homeseer solution. In the end, I have found that Hayward offers a wifi solution that can be controlled via a web page. At first I thought... fine I should be able to control things from within Homeseer by just sending http commands. Multiple people told me ...no.. you to use our web page. In place of arguing, I thought if I could just spawn a web page, execute pool management, and then close it going back to my HSTouch UI... I thought this would be a viable option.

          So now after my long winded preface ... two things:
          • I am not able to locate a way to call a web page if someone could point to a solution I would appreciate it.
          • If someone thinks I can in fact execute specific http commands to a Hayward wifi control, please explain.
          Thank you.

          Comment


            #6
            I don't know how to do it, but it apparently can be done in HS3. HS4, iffy.

            https://forums.homeseer.com/forum/po...nnect-mister2t
            HomeSeer Version: HS4 Pro Edition 4.2.19.0 (Windows - Running as a Service)
            Home Assistant 2024.3
            Operating System: Microsoft Windows 11 Pro - Desktop
            Z-Wave Devices via two Z-Net G3s
            Zigbee Devices via RaspBee on RPi 3b+
            WiFi Devices via Internal Router.

            Enabled Plug-Ins
            AK GoogleCalendar 4.0.4.16,AK HomeAssistant 4.0.1.23,AK SmartDevice 4.0.5.1,AK Weather 4.0.5.181,AmbientWeather 3.0.1.9,Big6 3.44.0.0,BLBackup 2.0.64.0,BLGData 3.0.55.0,BLLock 3.0.39.0,BLUPS 2.0.26.0,Device History 4.5.1.1,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,HSBuddy 4.51.303.0,JowiHue 4.1.4.0,LG ThinQ 4.0.26.0,ONVIF Events 1.0.0.5,SDJ-Health 3.1.1.9,TPLinkSmartHome4 2022.12.30.0,UltraCID3 3.0.6681.34300,Z-Wave 4.1.3.0

            Comment


              #7
              Originally posted by ewkearns View Post
              I don't know how to do it, but it apparently can be done in HS3. HS4, iffy.

              https://forums.homeseer.com/forum/po...nnect-mister2t

              Thanks for looking into this but, unfortunately that is for the serial connection solution only.

              Comment


                #8
                Originally posted by morrisdlx View Post


                Thanks for looking into this but, unfortunately that is for the serial connection solution only.
                I think I have found it... Since I am not sure yet as to how to send specific commands to the Hayward Homenet unit, I have found that I can call an external application (MS Edge) and provide a specific URL. This allows me to use the HOMENET page for controlling pool and call the page from within homeseer.

                Comment


                  #9
                  If you don't like the overhead of a browser you can also use curl.exe.
                  That will give you more control over the response
                  - Bram

                  Send from my Commodore VIC-20

                  Ashai_Rey____________________________________________________________ ________________
                  HS3 Pro 3.0.0.534
                  PIugins: ZMC audio | ZMC VR | ZMC IR | ZMC NDS | RFXcom | AZ scripts | Jon00 Scripts | BLBackup | FritzBox | Z-Wave | mcsMQTT | AK Ikea

                  Comment

                  Working...
                  X