Announcement

Collapse
No announcement yet.

Immediate script command errors

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

    Immediate script command errors

    Running the latest HS4 version
    • Using an event to run a script or command
    • Enter the command in the Sub or Func box
    • Select immediate command.

    The command I'm running is a http get:
    Code:
    &hs.GetURL("xxx:xxx@192.168.99.45","/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1",TRUE,80)
    I did test that command under the tools -> enter script command and it runs fine. However running the same command with an event generates an error of

    Code:
    Running script(1) &hs.GetURL("xxx:xxx@192.168.99.45","/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1",TRUE,80)
    ("hs.GetURL("http://xxx:xxx@192.168.99.45/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1",TRUE,80)"),
    init error: Expected ')'
    I've tried a few permutations to fix the syntax error but can't seem to get it right? Any Ideas?



    #2
    Try removing the leading & in the script.

    Comment


      #3
      HS will add it back in for you when you save the event

      Comment


        #4
        Try removing the leading & in the script, not the immediate command.

        Comment


          #5
          I'm sorry, what script? I was simply entering the command in the "sub or func" box?

          Comment


            #6
            Sorry. The error message said "running script" so I thought you were running a script.

            Comment


              #7
              I've seen this somewhere before but don't recall where...

              Are you running on Windows or Linux?

              Comment


                #8
                Its running under windows ... When I searched I did find a beta issue about running a script command from an event did not see a resolution so I think its maybe an ongoing bug.

                Comment


                  #9
                  I fired up HS 4.1.2.0 on my Raspberry Pi and am unable to replicate your error. My immediate script is

                  Code:
                  &hs.GetURL("xxx:xxx@192.168.1.118","/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1",TRUE,8000)
                  and the request makes it to the server.

                  Note though that the leading "xxx:xxx@" is ignored by hs.getURL. To make that work you'll need instead to use hs.URLAction and build the Authorization: Basic header. Here is an example script I posted at some point.

                  Code:
                  Sub Main(param As String)
                      Const Debug As Boolean = False
                      Const logName As String = "relay"
                  
                      '=== adjust as required ====
                      Const addr As String = "192.168.1.118:8000"
                      Const user As String = "admin"
                      Const pass As String = "12345678"
                      '====
                  
                      ' default action is "on" - enter value in 'Parameters' field to override this
                      Dim action As String = "on"
                      If param <> "" Then action = param
                  
                      Dim auth As String = user & ":" & pass
                      Dim autha As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(auth)
                      Dim headers As String = "Authorization: Basic " & System.Convert.ToBase64String(autha)
                      Dim url As String = "http://" & addr & "/relay_en.cgi?saida1" & action & "=" & action
                  
                      Dim s = hs.URLAction(url, "GET", "", headers)
                      If Debug Then hs.WriteLog(logName, s)
                  
                  End Sub

                  Comment


                    #10
                    Originally posted by zwolfpack View Post
                    Note though that the leading "xxx:xxx@" is ignored by hs.getURL. To make that work you'll need instead to use hs.URLAction and build the Authorization: Basic header. Here is an example script I posted at some point.
                    That's not my experience. hs.geturl definitely honors the
                    Code:
                    "user:password@"
                    notation.

                    Comment


                      #11
                      Thanks ... Strange it worked for you as running on *nix via the Sub/Func command of an Event. As indicated in my OP the command runs fine from the "tools" run script command so I know the syntax was correct. Just when used in the event as a simple command its tosses the extra ) error.

                      I gave up on using the simple Func call and created a .vb script to run instead and that appears to be running fine. I did not pull out the auth to a separate header and it ran but if it gives me any problems I'll use your Auth header solution. Really appreciate you taking the time to post that.

                      Comment


                        #12
                        Originally posted by baudi View Post

                        That's not my experience. hs.geturl definitely honors the
                        Code:
                        "user:password@"
                        notation.
                        Good to know, thanks. In my test setup, the "bare bonz" web server doesn't require authentication. I guess if the server were to return the 401 auth required response code, hs.getURL will provide the auth header then.

                        Comment

                        Working...
                        X