No announcement yet.

simple script was working .. no changes .. now not working

  • Filter
  • Time
  • Show
Clear All
new posts

  • simple script was working .. no changes .. now not working

    I have the following script that makes a call to an external web server which turns my aircon zones on and off.
    Its been working fine for months, there have been no changes to the script.
    I have manually tested the remote server using curl in a command window from the HS server and it works fine.
    So its not the remote server, its not firewalling from HS server.

    It appears to be crashing on this line Dim dataStream As Stream = request.GetRequestStream()
    This is through trial and error by commenting out lots of rows.

    The error Im getting is :
    Error 3 Running script C:\Program Files (x86)\HomeSeer HS3\scripts\ActronControl.vb :Exception has been thrown by the target of an invocation.->Does entry point Main exist in script? at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Obj ect obj, Object[] parameters, Object[] arguments) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at Scheduler.clsRunVBNetScript.ExecuteScript()
    Any ideas ?

    Thanks in advance.

    System config :

    Current Date/Time: 15-May-19 10:54:56 PM
    HomeSeer Version: HS3 Pro Edition
    Operating System: Microsoft Windows 10 Pro - Work Station
    System Uptime: 0 Days 0 Hours 54 Minutes 7 Seconds
    IP Address:
    Number of Devices: 528
    Number of Events: 138
    Available Threads: 800
    HSTouch Enabled: True
    Event Threads: 0
    Event Trigger Eval Queue: 0
    Event Trigger Priority Eval Queue: 0
    Device Exec Queue: 0
    HSTouch Event Queue: 0
    Email Send Queue: 0
    Anti Virus Installed: Windows Defender
    In Virtual Machine: No MFG: gigabyte technology co., ltd.
    Enabled Plug-Ins EasyTrigger FritzTR064 Kodi MediaController Sonos Z-Wave

    Script :

    Imports System.IO
    Imports System.Net
    Imports System.Text

    public Sub Main(byVal parm as object)
    const debug = true
    dim MyParm() as string

    MyParm = parm.toString.split(":")

    dim postData = "{""DA"":{""" & MyParm(0) & """:" & MyParm(1) & "}}"

    if debug then hs.writelog("Actron",postdata) ' sample data looks like this {"DA":{"enabledZones":[1,1,1,1,0,0,0,0]}}

    ' Create a request using a URL that can receive a post.
    const server_url = ""

    Dim request As WebRequest = WebRequest.Create(server_url)
    ' Set the Method property of the request to POST.
    request.Method = "POST"

    ' Create POST data and convert it to a byte array.
    Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
    ' Set the ContentType property of the WebRequest.
    request.ContentType = "application/json"
    ' Set the ContentLength property of the WebRequest.
    request.ContentLength = byteArray.Length

    ' Get the request stream.
    Dim dataStream As Stream = request.GetRequestStream()

    ' Write the data to the request stream.
    dataStream.Write(byteArray, 0, byteArray.Length)

    ' Close the Stream object.

    ' Get the response.
    Dim response As WebResponse = request.GetResponse()

    ' Display the status.
    If debug Then hs.writelog("POST request", CType(response, HttpWebResponse).StatusDescription)

    ' Get the stream containing content returned by the server.
    dataStream = response.GetResponseStream()

    ' Open the stream using a StreamReader for easy access.
    Dim reader As New StreamReader(dataStream)

    ' Read the content.
    Dim responseFromServer As String = reader.ReadToEnd()

    ' Display the content.
    If debug Then hs.writelog("POST response", responseFromServer)

    ' Clean up the streams.

    End Sub
    Last edited by gdarby; May 19th, 2019, 11:38 PM. Reason: Solved

  • #2
    Quick update .. Ive solved it. Turns out the request.Method = "POST" is no longer being supported by the server. Ive changed this to "PUT" and it works fine.

    FYI the diagnosis was part structured (turned on some try/catch blocks with some debug out - which told me it was actually a 404 page not found error) and then a bunch of trial and error to try and see what part of the header was malformed to align with the server.