Announcement

Collapse
No announcement yet.

Really simple C# sample plugin available here!

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

    Really simple C# sample plugin available here!

    Hi All

    I'm probably not the only one here that has been struggling with how incomplete the HS3 plugin documentation is, and how convoluted the sample VB.Net plugins were. It took me months to get my head around what they were doing with multiple levels of indirection, multiple copies of core objects, and multiple static classes cross referencing each other.

    Anyway, I've had a breakthrough and managed to make a very simple, barebones C# plugin that can launch and connect to the Homeseer HS3 server. 99% of the code is now in a single non-static class (perfect for multiple instances), with the bare minimum of code in the console wrapper required to launch it and wait for shutdown. It took me ages to figure out how to successfully connect to the Homeseer TCP API, but now that it works I've made it as straightforward and sensible as I can, with lots of code comments to explain what is going on.

    The basic premise is:
    1) All of your functional code goes into the plugin (HSPI) class that implements the IPlugInAPI interface
    2) The console wrapper creates an instance of your plugin class, and calls a Connect method on your plugin
    3) The plugin makes it's own private connection to Homeseer and sets up the bi-directional remote call functionality
    4) The console wrapper sits in a sleep loop, periodically testing if the plugin has failed or needs to shut down.

    Note that I haven't implemented any devices, actions, triggers, conditions or web pages, this is an empty shell ready for you to populate with your own code.

    Current version (1.0.0.0) here: https://drive.google.com/open?id=0B3...Xl2OXhIb2ZxZVk
    Last edited by aXis; January 17, 2016, 10:10 PM.

    #2
    Thanks for sharing this! I've been planning to turn my aspx page into an actual plug in and have been wondering if something like this existed. Going through the docs to try to just figure out where to begin has been a somewhat frustrating experience so far.

    Comment


      #3
      Axis, thanks for sharing. There's no .csproj file included so opening the .sln file throws an error. Nothing major, but a little confusing for beginners?
      Author of Highpeak Plugins | SMS-Gateway Plugin | Blue Iris Plugin | Paradox (Beta) Plugin | Modbus Plugin | Yamaha Plugin

      Comment


        #4
        Good pick up. I didnt think it was necessary but you're right, it will help beginners. I've repackaged the csproj and app.config files now, original link has been updated.

        Comment


          #5
          Thanks for this, I'm currently building my first plugin and this has already been quite helpful!

          Comment


            #6
            You're very welcome

            I wrote a new hardware plugin using this template over the weekend and also upgraded/refactored and old one, both are working well. I didn't have to make any changes to the template so I'm happy that it's about as simple as I can get it.

            Comment


              #7
              Thanks

              Thank you very much, I too have tried to rake through the documentation and samples to find the basics.

              I have taken the liberty of creating a template from your project. The template was built using Visual Studio 2015 Community and is for C#
              Attached Files

              Comment


                #8
                Awesome, it's really good to see people are getting some use out of it.

                I've just started my sixth plugin using this template. The plain input/status only ones were easy, the last one I did had some outputs which made it harder but still worked out OK.

                Comment


                  #9
                  Sample

                  Hey Axis - if you feel so inclined, a Hello World sample may be good

                  Comment


                    #10
                    Thanks for this sample project, it has helped me a LOT !
                    If only I could get the actions to work now :-)

                    Comment


                      #11
                      aXis

                      Would you be interested in putting this up on github for others to contribute to? I have several ideas for improvements, but passing around a file in the forum doesn't seem optimal.

                      Comment


                        #12
                        I think there will be a good number of people who will feel GitHub is another hurdle to get started. So I would advocate a thread where the latest plugin sample is updated as a downlodable zip file in the very first post (and hopefully it will be made sticky).

                        Having said that, while this is a really great starting point, there is still room for improvement (there always is). For instance I have added a lot of the comments from the SDK documentation to the functions. I also wish the example shows how to add configuration pages, etc. If the original author is not responding anymore, then maybe we should consider starting something new based on that code...

                        Comment


                          #13
                          Originally posted by mulu View Post
                          I think there will be a good number of people who will feel GitHub is another hurdle to get started. So I would advocate a thread where the latest plugin sample is updated as a downlodable zip file in the very first post (and hopefully it will be made sticky).

                          Having said that, while this is a really great starting point, there is still room for improvement (there always is). For instance I have added a lot of the comments from the SDK documentation to the functions. I also wish the example shows how to add configuration pages, etc. If the original author is not responding anymore, then maybe we should consider starting something new based on that code...
                          You don't know to know how to use git. Github already provides a downloadable zip file of the source code.

                          Comment


                            #14
                            Originally posted by mulu View Post
                            Having said that, while this is a really great starting point, there is still room for improvement (there always is). For instance I have added a lot of the comments from the SDK documentation to the functions. I also wish the example shows how to add configuration pages, etc. If the original author is not responding anymore, then maybe we should consider starting something new based on that code...
                            Hi, can you share your updated example please?

                            Comment


                              #15
                              Originally posted by mulu View Post
                              I think there will be a good number of people who will feel GitHub is another hurdle to get started. So I would advocate a thread where the latest plugin sample is updated as a downlodable zip file in the very first post (and hopefully it will be made sticky).

                              Having said that, while this is a really great starting point, there is still room for improvement (there always is). For instance I have added a lot of the comments from the SDK documentation to the functions. I also wish the example shows how to add configuration pages, etc. If the original author is not responding anymore, then maybe we should consider starting something new based on that code...
                              and for those like me with quite a bit of dev experience on other platforms, not having Github is a hinderance as that help with he normal dev workflow immensely as well as allowing others to learn from the just the changes to versions

                              Comment

                              Working...
                              X