Announcement

Collapse
No announcement yet.

How can I send a hhtp post command with body from a script ?

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

    How can I send a hhtp post command with body from a script ?

    I have found a api for my LinkTap. I can send commands via post http to control it. For the moment it would be enough for me to be able to send a on/off command, and from there can probably work out how to send the other commands.

    This is the descrition of the command.


    Activate Instant Mode for Watering ON and OFF

    POST https://www.link-tap.com/api/activateInstantMode


    Please note: Rate limiting is applied for this API. The minimum interval of calling this API is 15 seconds.


    Body object:username: Required. String type. Your LinkTap account's username
    apiKey: Required. String type. Your API key
    gatewayId: Required. String type. Your LinkTap Gateway's first 16-digits/letters ID, case insensitive, no dash symbol, e,g, 3F7A23FE004B1200
    taplinkerId: Required. String type. Your LinkTap Taplinker's first 16-digits/letters ID, case insensitive, no dash symbol, e,g, 67ABCDEF004B1200
    action: Required. String or Boolean type. "true" for Watering ON, "false" for Watering OFF.
    duration: Required. Number type. The watering duration (unit is minute). For Watering OFF, this field is 0. For Watring ON, the range is from 1 minute to 1439 minutes for the G1 and G2 models, and from 0 to 1439 minutes for the G1S and G2S models.
    durationSec: Optional. Number type. The second portion of the watering duration (unit is second). It is used for the G1S and G2S models only. Its value is between 0 and 59. An example: if you want to water for 10 minutes 30 seconds, then the duration field will be 10, and the durationSec field will be 30.
    eco: Optional. String or Boolean type. "true" for ECO enabled, "false" for ECO disabled.
    ecoOn: Required when eco equals "true". Number type. The valve ON duration (unit is minute). This value needs to be less than duration.
    ecoOnSec: Optional. Number type. The second portion of the valve ON duration (unit is second). It is valid for the G1S and G2S models only. Its value is between 0 and 59.
    ecoOff: Required when eco equals "true". Number type. The valve OFF duration (unit is minute).
    ecoOffSec: Optional. Number type. The second portion of the valve OFF duration (unit is second). It is valid for the G1S and G2S models only. Its value is between 0 and 59.
    autoBack: Optional. String or Boolean type. "true" for automatically re-activating the previous watering plan after watering in Instant Mode is completed.




    Response (success):result: "ok"
    message: "success"




    Response (failure):result: "error"
    message: various error messages




    Example of Request Body for Watering ON:{
    username: linktapuser,
    apiKey: "a6f1223d1fe191f8ec55662d1eb45720",
    gatewayId: "3C7A23FE004B1200",
    taplinkerId: "68ABCDEF004B1200",
    action: true,
    duration: 20
    eco: true,
    ecoOn: 1
    ecoOff: 2

    }




    Example of Request Body for Watering OFF:{
    username: linktapuser,
    apiKey: "a6f1223d1fe191f8ec55662d1eb45720",
    gatewayId: "3C7A23FE004B1200",
    taplinkerId: "68ABCDEF004B1200",
    action: false,
    duration: 0





    #2
    Probably the easiest path to accomplish this is to use the vb .net WebRequest object. The following is what I use to sent a JSON put command to the Hue Bridge:

    Code:
    Imports System.Net
    Imports System.IO
    ...
      Dim request As WebRequest, response As WebResponse, ds As Stream, reader As StreamReader, b() As Byte, sUrlResponse As String
      Dim body As String
      Dim url As String = "http://..."
    
      Try
        request = WebRequest.Create(url)
        request.Method = "PUT"
        request.ContentType = "application/json"
        If body <> "" Then
          request.ContentLength = Len(body)
          ds = request.GetRequestStream()
          b = System.Text.Encoding.UTF8.GetBytes(body)
          ds.Write(b, 0, b.Length)
          ds.Close()
        End If
        response = request.GetResponse()
        ds = response.GetResponseStream()
        reader = New StreamReader(ds)
        sUrlResponse = reader.ReadToEnd()
        reader.Close()
        response.Close()
      Catch ex As Exception
        hs.writelog("Hue Err", ex.ToString)
      End Try
    ...
    Google ".net webrequest" for more information on performing a webrequest in .net. (Actually you should be using HttpWebRequest instead, I just never bothered to convert to the newer method.)

    Comment

    Working...
    X