more G-Labs products

Author Topic: Plugins development  (Read 4134 times)

October 14, 2015, 01:17:41 PM
Read 4134 times

Bartek

  • *
  • Information
  • Newbie
  • Posts: 6
Hi, I'm new to HG. I have got an automation system built on CAN BUS with bridge module that gives access to the system via TCP. Now, I found HG and it looks very nice for me, with C# especially.

I want to develope a plugin, that makes easy access to my system, and my question is how to do this? I've read this forum and docs, but I feel a bit confused. Is there any good tutorial or hello world plugin, that can be installed via HG manager? I see there's x10 plugin on github, but its code spread over few other projects.

I know I can use TCP helper, but I want put ugly translating CAN code to plugin and then access its commands from HG scripts.

October 14, 2015, 05:01:29 PM
Reply #1

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
You can look at the code of Philips Hue Bridge In HG Programs - Devices and things
« Last Edit: October 14, 2015, 05:03:24 PM by dani »

October 15, 2015, 10:12:18 PM
Reply #2

Bartek

  • *
  • Information
  • Newbie
  • Posts: 6
But this is just a program script. I want make much more complicated plugin (interface), with use of external assemblies. Is it possible to write such code without compiling whole HG or MIG, just to make a plugin and install it by System > Install Addons button?

I also have some other plugins idea, which requires some external assemblies and the program scripts aren't a good enough for that. So my goal is to write external dll and plug it into the HG, then use it in programs. Am I think correctly?

October 16, 2015, 12:40:26 AM
Reply #3

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
In that case, you can refer to the src code of ZWaveLib.dotnet. it is now an external référence for MIG interface

October 16, 2015, 04:25:08 PM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
You can develop Add-Ons for HG, here some examples:

https://github.com/genielabs/HomeGenie/blob/master/BaseFiles/Common/ADDONS.md

An HG Add-On can then be packaged as a distributable zip file and so imported from the UI from Configure->Settings->Install Add-On option.


October 16, 2015, 06:33:45 PM
Reply #5

Bartek

  • *
  • Information
  • Newbie
  • Posts: 6
Thanks, I'll check that.

October 17, 2015, 12:29:33 AM
Reply #6

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi Bartek,

it turns out that there was a bug with the Add-On install functionality, so ensure to be using at least HG v1.1 r498 (currently only available as source code on github) where the bug is fixed.

Cheers,
g.

November 10, 2015, 10:50:06 PM
Reply #7

Bartek

  • *
  • Information
  • Newbie
  • Posts: 6
Hi again.
I've build r500, made setup file and install new version.

Then I add new project to mig solution with copy of x10 interface plugin, then remove all x10 code, leaving just empty class with MigInterface methods implemented.
Then modify zip files. When I try to install plugin a windows with button proceed is being shown, after that nothing happend.
In logs I've got something like this (some lines are in Polish language)

Code: [Select]
2015-11-10 22:38:45.3586 Info WebServiceGateway 169.254.80.80 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interface.Install [OPEN]
2015-11-10 22:38:45.3586 Debug Interface not found Onixarts.TestOA
2015-11-10 22:38:45.3586 Debug Interface not found Onixarts.TestOA
2015-11-10 22:38:45.3711 Error System.IO.FileNotFoundException: Nie moLLna zaL,adowaÄ? pliku lub zestawu 'file:///C:\Program Files\HomeGenie\Onixarts.MIG.Interfaces.Test' lub jednej z jego zaleLLnoL>ci. Nie moLLna odnaleLsÄ? okreL>lonego pliku.
Nazwa pliku: 'file:///C:\Program Files\HomeGenie\Onixarts.MIG.Interfaces.Test'
   w System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   w System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   w System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   w System.Reflection.Assembly.LoadFrom(String assemblyFile)
   w MIG.MigService.TypeLookup(String typeName, String assemblyName)
   w MIG.MigService.AddInterface(String domain, String assemblyName)

=== Informacje o stanie sprzed powiÄ.zania ===
DZIENNIK: Where-ref bind. Location = C:\Program Files\HomeGenie\Onixarts.MIG.Interfaces.Test
DZIENNIK: Appbase = file:///C:/Program Files/HomeGenie/
DZIENNIK: Initial PrivatePath = NULL
Zestaw wywoL,ujÄ.cy: (Unknown).
===
DZIENNIK: to powiÄ.zanie zaczyna siÄT w kontekL>cie L,adowania LoadFrom.
OSTRZEL»ENIE: Obraz macierzysty nie bÄTdzie sondowany w kontekL>cie LoadFrom. Obraz macierzysty bÄTdzie sondowany tylko w domyL>lnym kontekL>cie L,adowania, takim jak Assembly.Load().
DZIENNIK: uLLycie pliku konfiguracji aplikacji: C:\Program Files\HomeGenie\HomeGenie.exe.Config
DZIENNIK: uLLycie pliku konfiguracji hosta:
DZIENNIK: uLLycie pliku konfiguracji komputera z C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
DZIENNIK: to samo powiÄ.zanie byL,o widoczne wczeL>niej i nie powiodL,o siÄT z hr = 0x80070002.

2015-11-10 22:38:45.3711 Info WebServiceGateway 169.254.80.80 HTTP GET 200 /api/HomeAutomation.HomeGenie/Config/Interface.Install [CLOSED AFTER 0,014 seconds]
There info says, that it can't load assembly or its reference. But there is no additiona references in my project.

Have You any suggestions about that?

December 01, 2015, 10:05:39 PM
Reply #8

Bartek

  • *
  • Information
  • Newbie
  • Posts: 6
After some pdb battle I'm able to debug homegenie and found that:

Code: [Select]
public MigInterface AddInterface(string domain, string assemblyName = "")
        {
            MigInterface migInterface = GetInterface(domain);
            if (migInterface == null)
            {
                try
                {
                    var type = TypeLookup("MIG.Interfaces." + domain, assemblyName);
                     [...]

My plugin has another namespace prefix... You should mention that in documentation ;)

So one problem solved... who's next ;).

December 01, 2015, 11:47:49 PM
Reply #9

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
You're right Bartek,

miig plugin documentation is something I hope to do soon, in the meantime feel free to ask for support here in the forum.

Cheers,
g.

December 03, 2015, 12:06:56 PM
Reply #10

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
This has come at just the right time as I am about to start writing a plugin.. Once i can get system.net.http to work in mono.. but first time trying to write any exe to run in mono as well as .net

What are you using as the target framework?

December 18, 2015, 11:07:01 PM
Reply #11

maxflax

  • ***
  • Information
  • Full Member
  • Posts: 90
How do you call your plugin functions from your HG program script Bartek? Also coding on a plugin with functionality not fitted for the HG Script Programs.

December 20, 2015, 12:12:46 PM
Reply #12

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
you can make api calls.. have a look at Zwave - Once you enable the zwave plugin you will then see the scripts that interact..

When looking for the method name it will replace the . with an underscore _

So Get.Value will be get_value (without looking at code)

David

January 04, 2016, 02:25:00 AM
Reply #13

maxflax

  • ***
  • Information
  • Full Member
  • Posts: 90
This actually helped me when I found the z-wave MIG lib and got the pieces of the puzzle to fit.
Thanks David :)
« Last Edit: January 06, 2016, 01:32:58 AM by maxflax »