Announcement

Collapse
No announcement yet.

HS4 plug-in development / debug on separate server

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

  • HS4 plug-in development / debug on separate server

    I recently installed HS4Pro on Windows 10 virtualized under ESXi. To date I had been running HS2Pro on a dedicated Windows 7 PC and for HS2 plug-in development I ran Visual Studio locally on the same machine. This time around I'd like to make an attempt to keep my HS4Pro production system / virtual machine as lean and clean as makes reasonable sense.

    Since I need to re-write a couple of my HS2 plug-ins for HS4 I'm wondering what are my options for a development environment? Can I have a separate development server with visual studio installed which connects and deploys to the production VM to support remote debugging? If not, would I need to replicate the the whole HS4Pro installation on the development machine? Or is it just advisable to just bite the bullet and do development locally on the production VM?

    Thanks for any advice!

    Don

  • #2
    How every HS plugin developer does it (for HS3 at least) - you don't even need remote debugging - just run (debug) your code in Visual Studio, you can pass the IP address and port via debug "Command line arguments" i.e. server=192.168.1.10 (or --server 192.168.1.10)I can't remember exactly

    Code:
    public class Options
    {
        [Option('p', "port", HelpText = "HomeSeer admin port")]
        public int Port { get; set; } = 10400;
    
        [Option('s', "server", HelpText = "HomeSeer IP address")]
        public string Server { get; set; } = "127.0.0.1";
    }
    
    Parser.Default.ParseArguments<Options>(args)
    .WithParsed(options => Connect(options.Server, options.Port));
    
    HsClient = ScsServiceClientBuilder.CreateClient<IHSApplication>(
    new ScsTcpEndPoint(serverAddress, serverPort), this);
    
    CallbackClient = ScsServiceClientBuilder.CreateClient<IAppCallbackAPI>(
    new ScsTcpEndPoint(serverAddress, serverPort), this);
    Full code here: https://forums.homeseer.com/forum/de...plugin-library

    Comment


    • #3
      As Alex indicated, HS is a remote server so connecting to it by passing the server parameter provides a level of debug. With this approach your plugin code is still running on the same computer as Visual Studio. What would have saved me much time in the past is a means to debug remotely with plugin running on the same computer as HS. Linux environments, especially mono, are different so the execution result running on Linux HS could be different than the same pluign running on Windows with a remote server connection to Linux HS.

      Comment


      • #4
        Simple enough. With VS2019 installed on a separate laptop, I just created a HS4 PI sample project (per https://docs.homeseer.com/display/HS...ating+a+Plugin) and then passed the address of my HS4 server as "server=X.X.X.X". Thanks guys!

        EDIT: Michael, to your point. Since the hardware with which a plug-in needs to communicate is often connected to the HS4 server, that's really where many plug-ins need to run. In the case of my plug-in, it will need to communicate with a lighting panel via RS232. Fortunately, all of my serial controlled devices terminate on a MOXA NPort serial/IP server so the plug-in should be able to run on the development laptop, provided I have the NPort virtual comm drivers installed.

        Comment


        • #5
          I took the next step and tried to build and run the HS4 C# Sample Plugin

          It builds successfully under VS2019 on the development laptop, and if I copy the the following files to my HS4 server,
          HSPI_HomeSeerSamplePlugin.exe.config --> ./HomeSeer HS4/
          HomeSeerSamplePlugin.exe --> ./HomeSeer HS4/
          add-sample-device.html --> ./HomeSeer HS4/html/HomeSeerSamplePlugin
          sample-blank.html --> ./HomeSeer HS4/html/HomeSeerSamplePlugin
          sample-guided-process.html --> ./HomeSeer HS4/html/HomeSeerSamplePlugin
          sample-trigger-feature.html --> ./HomeSeer HS4/html/HomeSeerSamplePlugin





          then I'm able to run it successfully on the server by (1) enabling it in HS4 Web Plug-in UI or (2) leaving it disabled and just launching HomeSeerSamplePlugin.exe from the ./HomeSeer HS4/ folder after starting HS4.

          However, if I try to run the plugin from Visual Studio on the development laptop, the plug-in only partially works. I can access some of the pages but others such as the "settings" page do not load. It seems there is a problem finding the Newtonsoft assembly in this case?

          Click image for larger version  Name:	HomeSeerSamplePlugin_settings_page_load_failure.JPG Views:	0 Size:	9.3 KB ID:	1407795
          Code:
          8/1/2020 3:14:21 PM HomeSeer Error Getting plugin GenPage: Could not load file or assembly 'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
          8/1/2020 3:13:08 PM HomeSeer Starting Plug-In Plugin Sample Plugin started successfully in 15147 milliseconds
          Edit: It's working now. The HSPI_HomeSeerSamplePlugin.exe.config file specified the privatePath="bin/homeseer. This is correct on the target HS4 server but not in the Visual Studio development environment which is running the app from .\bin\Debug. I resolved this by copying Newtonsoft.Json and Newtonsoft.Json.dll from .\HomeSeerSamplePlugin\packages\Newtonsoft.Json.12.0.3\lib\n et45\ to a new bin\homeseer folder that I created beneath the Debug directory: .\HomeSeerSamplePlugin\bin\Debug\bin\homeseer.

          Last edited by dschoppe; August 1st, 2020, 04:28 PM. Reason: Resolved

          Comment


          • #6
            dschoppe in case you have assembly loading issues - I suggest Assembly Binding Log Viewer - very useful.

            And regarding remote debug - Visual Studio supports by connecting to running exe remotely.

            Comment


            • #7
              alexbk66, Thanks for the tips. Much appreciated!

              Comment


              • #8
                https://docs.microsoft.com/en-us/vis...p?view=vs-2019

                Click image for larger version

Name:	2020-08-02.png
Views:	24
Size:	32.3 KB
ID:	1407863

                Comment

                Working...
                X