Announcement

Collapse
No announcement yet.

Communicating with HomeSeer and my plugin with ASPX & c#

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

  • Communicating with HomeSeer and my plugin with ASPX & c#

    I have an aspx file in HomeSeer's html directory containing c# script (shown below). I access it via http://127.0.0.1/somefile.aspx (copy of HomeSeer running on my dev machine).

    Code:
    <%@Page Language="C#" %>
    
    <script runat="server">
    
        Scheduler.hsapplication hs;
        HomeSeerAPI.PluginAccess plugin;
    
        void Page_Load(object Sender, EventArgs E)
        {
            try
            {
                // for use with the HS web server
                hs = (Scheduler.hsapplication)Context.Items["Content"];
                if (hs == null)
                {
                    throw new Exception("Error getting access to HS application.");
                }
    
                // get a reference to the TaskerFence plugin
    
                HomeSeerAPI.IHSApplication ihs = (HomeSeerAPI.IHSApplication)hs;
                plugin = new HomeSeerAPI.PluginAccess(ref ihs, "TaskerFence", "");
                if (plugin == null)
                {
                    throw new Exception("Could not load plugin");
                }
                if ((bool)plugin.Connected)
                {
                    Response.Write("Connected to TaskerFence plugin, name=" + plugin.Name + "<br>");
                    string strName;
                    string[] something = { };
                    strName = (string)hs.PluginPropertyGet("Tasker", "", "Name", something);
                    Response.Write("Name property = " + strName + "<br>");
                }
                else
                {
                    Response.Write("TaskerFence plugin not connected.<br>");
                    return;
                }
    
                Response.Write("HomeSeer Ver: " + hs.Version() + "<br>");
    
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message + ex.StackTrace);
            }
    
        }
    </script>
    Output from the web page when accessed is next:

    Connected to TaskerFence plugin, name=
    Name property =
    HomeSeer Ver: 3.0.0.435


    It seems to connect with HomeSeer OK as it returns the correct version number (or maybe it's getting that from the DLL. It's returning non-null for the plugin reference, and the plugin.Connected value is true.

    Any attempt to communicate with the plugin returns nothing. In the example above I tried getting the plugin name. I've also tried calling PluginPropertyGet on the name with the same non-result. Have also tried calling PostBackProc (directly) and a generic TestFunc function that I added to my plugin.

    It doesn't help that I'm writing everything in c# when all of the docs (such as they are) are written assuming you will be using VB.

    Any ideas from all you smart and experience plugin writers out there? If it will help I can post the plugin code.

    Thanks.

  • #2
    Did you actually implement PluginPropertyGet in your plugin? it is NOT provided by HS, you need to provide it... LMK if you need an example...

    Comment


    • #3
      Originally posted by bsobel View Post
      Did you actually implement PluginPropertyGet in your plugin? it is NOT provided by HS, you need to provide it... LMK if you need an example...
      I did not. Silly me for seeing it in the SDK and thinking it was built in. I will give that a try.

      Comment


      • #4
        Originally posted by jayph View Post

        I did not. Silly me for seeing it in the SDK and thinking it was built in. I will give that a try.
        Don't feel silly, I did the exact same thing the first time, took me a bit to realize my plugin was being called, but there was no implementation. Makes sense, you can control what functions you want exposed. You can use reflection and expose everything, or more manually use a switch or other flow control and only expose names you want...

        Comment


        • #5
          Still struggling with PluginPropertyGet, but implemented PluginFunction and that is working so I'm moving forward again.

          Comment

          Working...
          X