Announcement

Collapse
No announcement yet.

Sending a post command?

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

    #16
    Originally posted by risquare View Post

    Big5 is made for non-programmers to use.

    You know your devices better but I find it weird that you must use POST to post nothing. POST is made to send out some content a.k.a. payload. If you have nothing to send out than why using POST. There are many cases out there where the command is the URL itself like in your case. However they all use GET. I still recommend for you to try GET. Won't hurt to try.
    Yup, it is weird. I did try GET and it didn't work. Then I found the docs for the Roku and they say it must be POST to send data and GET to inquire data.

    From their docs:
    keypress/<KEY> Equivalent to pressing down and releasing the remote control key identified after the slash. You can also use this command, and the keydown and keyup commands, to send keyboard alphanumeric characters when a keyboard screen is active, as described in Keypress Key Values. This command is sent using an HTTP POST with no body.
    Next step is to try and figure out how to put the static URL into a Virtual Device and pull it from there. Or, place it in a config file and read it from there instead of having to enter the URL in each event for each keypress I need to create.

    I greatly your help so far with this. Of all the community forums I participate in, the best folks, by far, are here.

    Update: I have the code to pull the URL and port from an .ini file. Just need to figure out how to construct the URL inside the keypress code without it needing to be def as a constant.
    Last edited by avpman; August 30, 2021, 02:50 PM. Reason: Updated.

    Comment


      #17
      Seems like a config file might be the easiest. I like to store API keys in config files rather than the script body. To read a config value,

      Code:
      Dim inifile As String = "xyz.ini"
      Dim Debug As Boolean = hs.GetINISetting("Settings", "Debug", "False", inifile)
      Dim apikey As String = hs.GetINISetting("Settings", "apikey", "", inifile)
      Then in [HS root]/Config/xyz.ini,
      Code:
      [Settings]
      Debug=False
      apikey=blahblahblah
      The second parameter of hs.GetINISetting() is the "key name" from the .ini file.

      Another way is to store the value in a device.

      To store a string,
      Code:
      hs.SetDeviceString(dvRef, "contents to be stored", True)
      To retrieve,
      Code:
      [COLOR=#000000][FONT=courier new]Dim dvStr As String = hs.DeviceString(dvRef)[/FONT][/COLOR]
      for both, dvRef is the device reference number (an integer).

      Comment


        #18
        Just saw your update. If you are still looking, here is a simple example from one of my scripts for building a URI.

        Code:
        Dim uri As String = String.Format("http://{0}/state={1}", target, CInt(state))
        If debug Then hs.WriteLog(logName, "uri: " & uri)
        In this case, 'target' is the hostname (IP address). In the String.Format() function, the first parameter is the format, the second is what gets inserted into {0}, the thrist is what gets inserted into {1}, etc.

        The resulting URI is something like "http://192.168.1.123/state=1".

        Comment


          #19
          Originally posted by zwolfpack View Post
          Seems like a config file might be the easiest. I like to store API keys in config files rather than the script body. To read a config value,

          Code:
          Dim inifile As String = "xyz.ini"
          Dim Debug As Boolean = hs.GetINISetting("Settings", "Debug", "False", inifile)
          Dim apikey As String = hs.GetINISetting("Settings", "apikey", "", inifile)
          Then in [HS root]/Config/xyz.ini,
          Code:
          [Settings]
          Debug=False
          apikey=blahblahblah
          The second parameter of hs.GetINISetting() is the "key name" from the .ini file.

          Another way is to store the value in a device.

          To store a string,
          Code:
          hs.SetDeviceString(dvRef, "contents to be stored", True)
          To retrieve,
          Code:
          [COLOR=#000000][FONT=courier new]Dim dvStr As String = hs.DeviceString(dvRef)[/FONT][/COLOR]
          for both, dvRef is the device reference number (an integer).
          Thanks zwolfpack . This is perfect for what I need.
          Be safe...

          Comment


            #20
            Originally posted by avpman View Post

            Thanks zwolfpack . This is perfect for what I need.
            Be safe...
            Thanks again zwolfpack got it:

            Sub Main (key as String)
            Dim inifile As String = "Roku2.ini"
            Dim Debug As Boolean = hs.GetINISetting("Settings", "Debug", "False", inifile)
            Dim URL As String = hs.GetINISetting("Settings", "URL", "", inifile)

            URL = URL & Key
            const data = ""
            const headers="Content-Type: application/x-www-form-urlencoded"
            dim s = hs.URLAction(URL, "POST", data, headers)

            If debug Then
            hs.WriteLog("Roku full cmd",URL & " " & Debug & " " & key)
            hs.writelog("POST response", s)
            end if

            End Sub

            Comment

            Working...
            X