Announcement

Collapse
No announcement yet.

NEW Script Connector Plugin V1.10.2.2

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NEW Script Connector Plugin V1.10.2.2

    Welcome to the Script Connector Plugin.

    This plugin lets you run any HomeSeer .Net script on remote computers, and advanced HomeSeer scripts on your main HomeSeer server.

    Remote scripts really run on the remote computers, and have access to all remote computer resources (file system, com ports, screen, keyboard, mouse...). The remote scripts also have access to all HomeSeer API. For example, you can easily set a HomeSeer device string with the content of a file on a remote computer, or print any message on the remote computer screen.


    Requirements:

    - The Speaker Client must be installed on the remote computers, but it doesn't have to be running. Alternatively, you can also run the Script Client on your main HomeSeer Server.
    - TCP port 8737 has to be open on your firewall, if you want to run HomeSeer scripts on remote computers over the Internet.
    - A Script Connector Client must be installed on the remote computer.


    To install the Script Client on each Speaker client computer:

    Once the plugin is installed, you can find a SetupHsScriptClient.msi Windows installer file in your HomeSeer 2 directory.
    From each remote computer, you need to run this file to install the Script Client.
    There are two ways to do this:
    - You may connect to the main HomeSeer computer from the client computer, then browse to the HomeSeer 2 directory and double-click the SetupHsScriptClient.msi
    - You may copy SetupHsScriptClient.msi to the remote computer using any other way, then run it.


    To run remote scripts from HomeSeer:

    - From any HomeSeer event, choose the Exec Remote Script action, enter the name of the Script Client, filename of the remote script, and optional parameter for the script Main() subroutine. If you use the standard "Run Script" HomeSeer event action, the Script Connector plugin is not invoked.

    - From any HomeSeer script, use the plugin ExecRemoteSub() API

    Example from HS Immediate Command Window:
    &hs.plugin("Script Connector").ExecRemoteSub "remote_client_name", "remote_messagebox.vb", "hello from HomeSeer"

    - From any HomeSeer script, use the plugin ExecRemoteFunc() API to return a result from the script Main Function

    Example from a HomeSeer VB script:
    hs.WriteLog( "Result", hs.Plugin("Script Connector").ExecRemoteFunc( "remote_client", "remote_test_func.vb", Nothing ) )


    To run remote scripts from the Remote Computer

    The HsScript program supports command line arguments.

    Syntax: HSSCRIPT remote_script_name.vb optional parameters
    Example from the Windows command prompt on a remote computer:
    HSSCRIPT remote_writelog.vb Hello From a Remote Computer !
    This prints "Hello From a Remote Computer !" to the HomeSeer event log.

    You can also create a Windows Shortcut easily on any remote computer to run remote scripts:
    Example with the Remote Mini Control script:
    - Right click on your desktop, choose New - Shortcut
    - Type the following as the shortcut target (including quotes) and apply:
    "c:\Program Files\HomeSeer 2\HsScript.exe" remote_mini_control.vb


    Sample scripts installed with the plugin:

    - remote_writelog.vb <-- Writes a message to the HomeSeer log
    - remote_writelog.cs <-- Writes a message to the HomeSeer log (Test C-Sharp Script)
    - remote_devicestring.vb <-- Changes a HomeSeer device string from a remote computer
    - remote_messagebox.vb <-- Shows a message box on the remote computer
    - remote_deviceaction.vb <-- Shows a dialog box on the remote computer, to switch HomeSeer devices ON/OFF
    - remote_mini_control.vb <-- Shows a dialog box with device status. You can click the status icons to switch devices ON/OFF
    - remote_marquee.cs <-- Shows a large scrolling message on the remote computer. Click on the message to close it.
    - remote_postit.cs <-- Shows a yellow post-it on a remote computer. Enter message as script parameter
    - remote_thermostat.cs <-- Shows a HomeSeer Thermostat control dialog box
    - remote_light.cs <-- Shows a small slider to control one light. Enter one device code as script parameter
    - remote_lights.cs <-- Shows a dynamic dialog box to control several lights. Enter several device codes as script parameter
    - remote_test_func.cs <-- Example CSharp Function Script
    - remote_test_func.vb <-- Example VB Function Script
    - remote_set_context.cs <-- Example script to save a value
    - remote_get_context.cs <-- Example script to get a value saved with remote_set_context.cs
    - media/*.cs <-- Scripts for the distributed HomeSeer Media Player

    The remote_messagebox.vb sample script shows how you have to declare any external assembly/dll you want to use from the remote script. You can add several #IMPORT lines to your scripts to reference as many assemblies as you need.


    Remote scripts advanced API

    Remote scripts have access to the hs object methods and properties. Furthermore remote scripts have access to the sh object (ScriptHost) methods and properties, to take advantage of remote features.

    sh.SetContext( keyString, paramObject ) <-- Save an object within the script client
    object = sh.GetContext( keyString) <-- Get an object previously saved. This allows to pass values between several scripts.
    boolean = sh.ExecLocalSub( scriptPath, paramObject )
    object = sh.ExecLocalFunc( scriptPath, paramObject )
    boolean = sh.ExecRemoteSub( scriptClient, scriptPath, paramObject )
    object = sh.ExecRemoteFunc( scriptClient, scriptPath, paramObject )
    string [] = sh.ClientList <-- List of registered Script clients as a string array
    string = sh.ClientName <-- Name of the running Script Client


    Remote Scripts special keywords:

    #IMPORT NameSpace,NameSpace.dll <-- adds NameSpace.dll as a reference to the script, and allows shortcuts.
    #USING NameSpace <-- Allows shortcuts to the named NameSpace
    #MTA <-- Use the Multithreaded COM Apartment model (this is used to host COM objects within scripts)
    #STA <-- Use the Single Threaded COM Apartment model


    [Edit] Attachement removed as the plugin is now available from the HomeSeer updater.
    Last edited by stipus; March 8, 2008, 01:29 PM.
    --
    stipus

    #2
    Here is a very simple script that can run on the Remote Script Client:

    Code:
    Sub Main( param as Object )
        hs.SetDeviceString( "A1", "Hello from a remote computer" )
    End Sub

    The same script, using the parameter object as the device string:

    Code:
    Sub Main( param as Object )
        hs.SetDeviceString( "A1", param )
    End Sub
    If you run from the Windows Command Line (CMD.EXE) the following command on a remote computer, A1 device string will be set to Hello ! on your HomeSeer server:
    HSSCRIPT name_of_script.vb Hello !


    Another more complex script :

    When you run this script, it displays a dialogbox on the remote computer (By the way, don't forget that if you don't have a remote computer, you can also run the HsScript.exe client on your main HomeSeer server...)

    On this dialog box, you can choose an HomeSeer device, type a device string, and click the Set Device String button...



    This shows you that you can build a new kind of HomeSeer applications with this plugin.

    Code:
    #IMPORT System.Windows.Forms,System.Windows.Forms.dll
    #IMPORT System.Drawing,System.Drawing.dll
     
    Sub Main( param as Object )
        Dim MainForm as new Form1()
        Application.Run(MainForm)
    End Sub
    
    Public Class Form1
        Inherits System.Windows.Forms.Form
     
        Public Sub New()
     
            Me.Label1 = New System.Windows.Forms.Label
            Me.Button1 = New System.Windows.Forms.Button
            Me.TextBox1 = New System.Windows.Forms.TextBox
            Me.ComboBox1 = New System.Windows.Forms.ComboBox
            Me.Label2 = New System.Windows.Forms.Label
            Me.SuspendLayout()
            '
            'Label1
            '
            Me.Label1.AutoSize = True
            Me.Label1.Location = New System.Drawing.Point(31, 18)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(142, 13)
            Me.Label1.TabIndex = 0
            Me.Label1.Text = "Choose HomeSeer Device : "
            '
            'Button1
            '
            Me.Button1.Location = New System.Drawing.Point(80, 103)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(167, 23)
            Me.Button1.TabIndex = 1
            Me.Button1.Text = "Change device string"
            Me.Button1.UseVisualStyleBackColor = True
            '
            'TextBox1
            '
            Me.TextBox1.Location = New System.Drawing.Point(191, 56)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(121, 20)
            Me.TextBox1.TabIndex = 2
            '
            'ComboBox1
            '
            Me.ComboBox1.FormattingEnabled = True
            Me.ComboBox1.Items.AddRange(New Object() {"A1", "A2", "A3", "A4", "A5"})
            Me.ComboBox1.Location = New System.Drawing.Point(191, 13)
            Me.ComboBox1.Name = "ComboBox1"
            Me.ComboBox1.Size = New System.Drawing.Size(121, 21)
            Me.ComboBox1.TabIndex = 3
            '
            'Label2
            '
            Me.Label2.AutoSize = True
            Me.Label2.Location = New System.Drawing.Point(31, 59)
            Me.Label2.Name = "Label2"
            Me.Label2.Size = New System.Drawing.Size(136, 13)
            Me.Label2.TabIndex = 4
            Me.Label2.Text = "Type a new Device String :"
            '
            'Form1
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(338, 157)
            Me.Controls.Add(Me.Label2)
            Me.Controls.Add(Me.ComboBox1)
            Me.Controls.Add(Me.TextBox1)
            Me.Controls.Add(Me.Button1)
            Me.Controls.Add(Me.Label1)
            Me.MaximizeBox = False
            Me.Name = "Form1"
            Me.Text = "HomeSeer Device Strings"
            Me.ResumeLayout(False)
            Me.PerformLayout()
        End Sub
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
        Friend WithEvents Label2 As System.Windows.Forms.Label
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            hs.SetDeviceString( ComboBox1.Text, TextBox1.Text )
        End Sub
     
    End Class
    You can also run this script from the remote computer, using the HsScript.exe command line:
    --> HsScript remote_devicestring.vb


    Tell me what you think !
    Last edited by stipus; September 9, 2007, 11:27 AM.
    --
    stipus

    Comment


      #3
      Attachement updated to V0.2.2.2

      Change log:

      - Fixed a small bug that could prevent a new Script Client with the same name from reconnecting if the first Script Client was not properly closed.
      - The sample script in post #2 has been included in the Scripts directory as remote_devicestring.vb
      --
      stipus

      Comment


        #4
        Here is a another script that shows a dialog box on the remote host: easy remote device action...



        Code:
        #IMPORT System.Windows.Forms,System.Windows.Forms.dll
        #IMPORT System.Drawing,System.Drawing.dll
         
        Sub Main( param as Object )
            Dim MainForm as new Form1()
            Application.Run(MainForm)
        End Sub
        
        Public Class Form1
        
            Inherits System.Windows.Forms.Form
         
            Public Sub New()
                Me.Label1 = New System.Windows.Forms.Label
                Me.DeviceTextBox = New System.Windows.Forms.TextBox
                Me.OnButton = New System.Windows.Forms.Button
                Me.OffButton = New System.Windows.Forms.Button
                Me.SuspendLayout()
                '
                'Label1
                '
                Me.Label1.AutoSize = True
                Me.Label1.Location = New System.Drawing.Point(20, 17)
                Me.Label1.Name = "Label1"
                Me.Label1.Size = New System.Drawing.Size(47, 13)
                Me.Label1.TabIndex = 0
                Me.Label1.Text = "Device :"
                '
                'DeviceTextBox
                '
                Me.DeviceTextBox.Location = New System.Drawing.Point(81, 14)
                Me.DeviceTextBox.Name = "DeviceTextBox"
                Me.DeviceTextBox.Size = New System.Drawing.Size(52, 20)
                Me.DeviceTextBox.TabIndex = 1
                Me.DeviceTextBox.Text = "A1"
                '
                'OnButton
                '
                Me.OnButton.Location = New System.Drawing.Point(12, 50)
                Me.OnButton.Name = "OnButton"
                Me.OnButton.Size = New System.Drawing.Size(55, 23)
                Me.OnButton.TabIndex = 2
                Me.OnButton.Text = "ON"
                Me.OnButton.UseVisualStyleBackColor = True
                '
                'OffButton
                '
                Me.OffButton.Location = New System.Drawing.Point(87, 50)
                Me.OffButton.Name = "OffButton"
                Me.OffButton.Size = New System.Drawing.Size(55, 23)
                Me.OffButton.TabIndex = 2
                Me.OffButton.Text = "OFF"
                Me.OffButton.UseVisualStyleBackColor = True
                '
                'Form1
                '
                Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
                Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
                Me.ClientSize = New System.Drawing.Size(156, 87)
                Me.Controls.Add(Me.OffButton)
                Me.Controls.Add(Me.OnButton)
                Me.Controls.Add(Me.DeviceTextBox)
                Me.Controls.Add(Me.Label1)
                Me.MaximizeBox = False
                Me.Name = "Form1"
                Me.Text = "Device Action"
                Me.ResumeLayout(False)
                Me.PerformLayout()
            End Sub
            Friend WithEvents Label1 As System.Windows.Forms.Label
            Friend WithEvents DeviceTextBox As System.Windows.Forms.TextBox
            Friend WithEvents OnButton As System.Windows.Forms.Button
            Friend WithEvents OffButton As System.Windows.Forms.Button
         
            Private Sub OnButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OnButton.Click
              If hs.DeviceExists( DeviceTextBox.Text ) <> -1 Then
                hs.ExecX10( DeviceTextBox.Text, "On" )
              End If
            End Sub
         
            Private Sub OffButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OffButton.Click
              If hs.DeviceExists( DeviceTextBox.Text ) <> -1 Then
                hs.ExecX10( DeviceTextBox.Text, "Off" )
              End If
            End Sub
        
        End Class
        Last edited by stipus; September 9, 2007, 11:28 AM.
        --
        stipus

        Comment


          #5
          Remote device control script error

          Hi Stipus,

          Installed ok. The script example to pop up a message works fine to my notebook from HS server (both win xp sp2).

          The device control script works up to the point I press the off button and then I get the attached:

          cheers,

          Phil

          See the end of this message for details on invoking
          just-in-time (JIT) debugging instead of this dialog box.

          ************** Exception Text **************
          System.IO.FileNotFoundException: Could not load file or assembly 'ICSharpCode.SharpZipLib, Version=0.80.0.1373, Culture=neutral, PublicKeyToken=1b03e6acf1164f73' or one of its dependencies. The system cannot find the file specified.
          File name: 'ICSharpCode.SharpZipLib, Version=0.80.0.1373, Culture=neutral, PublicKeyToken=1b03e6acf1164f73'

          Server stack trace:
          at Belikov.GenuineChannels.Messaging.MessageCoder.Serialize(Gen uineChunkedStream stream, Message message, Boolean compress)
          at Belikov.GenuineChannels.Connection.ConnectionManager.Send(Me ssage message)
          at Belikov.GenuineChannels.DotNetRemotingLayer.GenuineTcpClient TransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream)
          at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.S yncProcessMessage(IMessage msg)

          Exception rethrown at [0]:
          at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessag e(IMessage reqMsg, IMessage retMsg)
          at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(Mess ageData& msgData, Int32 type)
          at Scheduler.hsapplication.DeviceExists(String device)
          at Stipus.HsScript.Script.Form1.OffButton_Click(Object sender, EventArgs e)
          at System.Windows.Forms.Control.OnClick(EventArgs e)
          at System.Windows.Forms.Button.OnClick(EventArgs e)
          at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
          at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
          at System.Windows.Forms.Control.WndProc(Message& m)
          at System.Windows.Forms.ButtonBase.WndProc(Message& m)
          at System.Windows.Forms.Button.WndProc(Message& m)
          at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(M essage& m)
          at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Mes sage& m)
          at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

          WRN: Assembly binding logging is turned OFF.
          To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
          Note: There is some performance penalty associated with assembly bind failure logging.
          To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].



          ************** Loaded Assemblies **************
          mscorlib
          Assembly Version: 2.0.0.0
          Win32 Version: 2.0.50727.832 (QFE.050727-8300)
          CodeBase: file:///C:/WINDOWS/Microsoft.NET/Framework/v2.0.50727/mscorlib.dll
          ----------------------------------------
          Stipus.ScriptConnector.Interface
          Assembly Version: 0.2.2.2
          Win32 Version: 0.2.2.2
          CodeBase: file:///C:/Program%20Files/HomeSeer%202/Stipus.ScriptConnector.Interface.DLL
          ----------------------------------------
          GenuineChannels
          Assembly Version: 2.5.9.1
          Win32 Version: 2.5.9.1
          CodeBase: file:///C:/Program%20Files/HomeSeer%202/GenuineChannels.DLL
          ----------------------------------------
          System
          Assembly Version: 2.0.0.0
          Win32 Version: 2.0.50727.832 (QFE.050727-8300)
          CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
          ----------------------------------------
          System.Runtime.Remoting
          Assembly Version: 2.0.0.0
          Win32 Version: 2.0.50727.832 (QFE.050727-8300)
          CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Runtime.Remoting/2.0.0.0__b77a5c561934e089/System.Runtime.Remoting.dll
          ----------------------------------------
          remote_devicecontrol.vb
          Assembly Version: 0.0.0.0
          Win32 Version: 0.0.0.0
          CodeBase: file:///C:/Program%20Files/HomeSeer%202/Scripts/remote_devicecontrol.vb.dll
          ----------------------------------------
          Scheduler
          Assembly Version: 2.1.0.0
          Win32 Version: 2.1.0.0
          CodeBase: file:///C:/Program%20Files/HomeSeer%202/Scheduler.DLL
          ----------------------------------------
          System.Windows.Forms
          Assembly Version: 2.0.0.0
          Win32 Version: 2.0.50727.832 (QFE.050727-8300)
          CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
          ----------------------------------------
          System.Drawing
          Assembly Version: 2.0.0.0
          Win32 Version: 2.0.50727.832 (QFE.050727-8300)
          CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
          ----------------------------------------
          Accessibility
          Assembly Version: 2.0.0.0
          Win32 Version: 2.0.50727.42 (RTM.050727-4200)
          CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Accessibility/2.0.0.0__b03f5f7f11d50a3a/Accessibility.dll
          ----------------------------------------
          Microsoft.VisualBasic
          Assembly Version: 8.0.0.0
          Win32 Version: 8.0.50727.42 (RTM.050727-4200)
          CodeBase: file:///C:/WINDOWS/assembly/GAC_MSIL/Microsoft.VisualBasic/8.0.0.0__b03f5f7f11d50a3a/Microsoft.VisualBasic.dll
          ----------------------------------------

          ************** JIT Debugging **************
          To enable just-in-time (JIT) debugging, the .config file for this
          application or computer (machine.config) must have the
          jitDebugging value set in the system.windows.forms section.
          The application must also be compiled with debugging
          enabled.

          For example:

          <configuration>
          <system.windows.forms jitDebugging="true" />
          </configuration>

          When JIT debugging is enabled, any unhandled exception
          will be sent to the JIT debugger registered on the computer
          rather than be handled by this dialog box.

          Comment


            #6
            Check that the assembly 'ICSharpCode.SharpZipLib.dll' is the same on both computers (in the HomeSeer 2 directory).

            The assembly I found on my computers is attached.

            [Edit] Attachement removed as ii's included in the latest zip.
            Last edited by stipus; September 1, 2007, 07:25 AM.
            --
            stipus

            Comment


              #7
              New version V0.3.2.2 is out:

              Check the attachement on the first post.

              Change log since V0.2.2.2:

              - Added 'ICSharpCode.SharpZipLib.dll' to the ZIP file.
              - Added remote_deviceaction.vb script to the Scripts directory
              - HsScript.exe now supports command line arguments. This means you can now run HomeSeer scripts from the remote computers.

              HSSCRIPT.EXE script_name.vb optional parameters

              Example:

              HSSCRIPT.EXE remote_writelog.vb Hello From a Remote Computer !

              This will print "Hello From a Remote Computer !" to the HS event log.
              --
              stipus

              Comment


                #8
                Hi Stipus,

                you beat me to it. I was about to post that ICsharp* file was not included in teh speaker client install or updates. I de-installed speaker client and re-installed and it was not there.

                thanks for including it now.

                cheers

                Comment


                  #9
                  Originally posted by psampson View Post
                  Hi Stipus,

                  you beat me to it. I was about to post that ICsharp* file was not included in teh speaker client install or updates. I de-installed speaker client and re-installed and it was not there.

                  thanks for including it now.

                  cheers
                  I dont see ICsharp in 3-2-2-2 zip update above, am I missing something?

                  cheers

                  Comment


                    #10
                    Just included the file to the ZIP. You can redownload....
                    --
                    stipus

                    Comment


                      #11
                      Originally posted by stipus View Post
                      Just included the file to the ZIP. You can redownload....
                      Thanks for the new zip. Now I have copied 0.3.2.2 to server and client and rebooted both and get this message when I trigger an even t to run a remote script. Any idea what I have broken?

                      1/09/2007 10:45:20 PM - Remote Script - Compile Error : Scripts\remote_deviceaction.vb : Could not load file or assembly 'GenuineChannels, Version=2.5.7.5, Culture=neutral, PublicKeyToken=65fda4a3fde44959' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)


                      thanks!

                      Comment


                        #12
                        I hate this dll hell .... I have removed the attachement.

                        Will check everything again, and post here when it's ready.
                        --
                        stipus

                        Comment


                          #13
                          OK. This time all dlls have been checked.

                          You can redownload V0.3.2.2. Thanks for your patience
                          --
                          stipus

                          Comment


                            #14
                            Good to know: With the next version of the plugin, these 2 dlls won't be needed anymore.

                            The less dll, the better it is
                            --
                            stipus

                            Comment


                              #15
                              Great thanks. I'll re-install on server and client machine from scratch and let you know. I'm glad to help.

                              cheers

                              Comment

                              Working...
                              X