Announcement

Collapse
No announcement yet.

PUT Command to Blynk Server

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

    PUT Command to Blynk Server

    Hello all, Im looking to send "PUT" commands as supported by the Blynk Arduino APP

    From some online searches the following command works for IFTTT however id like to execute this command directly from a HS Script if possible and avoid IFTTT.
    How can I format this to a Script that HS will recognized. Ive tried several examples i found but none work .

    URL : http://192.168.1.15:8080/your_token/pin/V4
    METHOD : PUT
    CONTENT TYPE : application/json
    BODY : ["1"]


    Thank you

    #2
    I would try something like this - http://board.homeseer.com/showthread...httpwebrequest

    Comment


      #3
      I've been struggling with this also.

      I can successfully update the value of V1 (to 876) using the script that gets generated at this website :

      https://blynkapi.docs.apiary.io/#ref...-value-via-put

      The code looks like this.

      Code:
      Dim request = TryCast(System.Net.WebRequest.Create("http://blynk-cloud.com/XXXSECURITYKEYXXX/update/V1"), System.Net.HttpWebRequest)
      
      request.Method = "PUT"
      
      request.ContentType = "application/json"
      Using writer = New
      System.IO.StreamWriter(request.GetRequestStream())
      Dim byteArray As Byte() =
      System.Text.Encoding.UTF8.GetBytes( 
       "[   \""876\"" ]") 
      request.ContentLength = byteArray.Length
      writer.Write(byteArray)
      writer.Close()
      End Using
      Dim responseContent As String
      Using response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)
      Using reader = New System.IO.StreamReader(response.GetResponseStream()) responseContent = reader.ReadToEnd()
      End Using
      End Using
      When I try to run this as a vb script in homeseer I get the following error

      Code:
      2:23:37 PM  - Error - Script compile error: Declaration expected.on line 19
      10/20/2019 12:23:37 PM  - SCR - Option Strict OffImports System.IOImports System.Netimports Schedulerimports SystemPublic Module scriptcode50#Region "Automatically generated code, do not modify"'Automatically generated code, do not modify'Event Sources Begin    <System.ContextStaticAttribute()> Public WithEvents hs As Scheduler.hsapplication    <System.ContextStaticAttribute()> Public WithEvents hsp As scheduler.hsp    <System.ContextStaticAttribute()> Public WithEvents hssystem As scheduler.phone0'Event Sources End'End of automatically generated code#End RegionDim request = TryCast(System.Net.WebRequest.Create("http://blynk-cloud.com/9-WEMru-5bpmNCz0hYW49R0fWpkimGLD/update/V1"), System.Net.HttpWebRequest)request.Method = "PUT"request.ContentType = "application/json"Using writer = New System.IO.StreamWriter(request.GetRequestStream())  Dim byteArray As Byte() = System.Text.Encoding.UTF8.GetBytes("[  \""87\""]")  request.ContentLength = byteArray.Length  writer.Write(byteArray)  writer.Close()End UsingDim responseContent As StringUsing response = TryCast(request.GetResponse(), System.Net.HttpWebResponse)  Using reader = New System.IO.StreamReader(response.GetResponseStream())    responseContent = reader.ReadToEnd()  End UsingEnd UsingEnd Module

      I got closer by trying to copy the script in the linked thread, ie

      Code:
      Imports System.IO
      Imports System.Net
      
          Sub Main(ByVal Parm As Object)
              Dim httpWebRequest = DirectCast(WebRequest.Create("http://blynk-cloud.com/XXXSECURITYKEYXXX/update/V1"), HttpWebRequest)
              httpWebRequest.ContentType = "application/json"
              httpWebRequest.Method = "PUT"
      
              Using streamWriter = New StreamWriter(httpWebRequest.GetRequestStream().ToString)
                  Dim json As String = "{""value"" : ""876""}"
                 streamWriter.Write(json)
              End Using
      
              Dim httpResponse = DirectCast(HttpWebRequest.GetResponse(), HttpWebResponse)
              Using streamReader = New StreamReader(httpResponse.GetResponseStream().ToString)
                  Dim responseText = StreamReader.ReadToEnd()
                  hs.WriteLog("Response", responseText)
              End Using
          End Sub
      This script runs in Homeseer 2 with no errors, but it doesn't update the value of V1

      (Stumped)

      Comment

      Working...
      X