more G-Labs products

Author Topic: Initiate action from module button  (Read 1762 times)

May 06, 2014, 10:52:51 PM
Read 1762 times

bradvoy

  • ***
  • Information
  • Full Member
  • Posts: 50
I have created a custom module that includes a couple of buttons for performing actions, similar to the homegenie/generic/switch module.  I see that when the user clicks the buttons in the switch module, it makes a call to HG.Control.Modules.ServiceCall.  I tried to do the same thing in my module, but I don't know how to intercept these calls in my corresponding automation program.  My program has a When.WebServiceCallReceived clause, but that doesn't appear to be called by HG.Control.Modules.ServiceCall.  Do I need to implement a different handler in my program to receive these calls?

May 06, 2014, 11:31:15 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Use the browser "developer tools" to see what Url is actually being called when you press the buttons.

Could you also provide code of WebServiceCallReceived?

g.

May 07, 2014, 12:07:24 AM
Reply #2

bradvoy

  • ***
  • Information
  • Full Member
  • Posts: 50
Using the browser tools to see what is being called was a good idea.

It's calling URLs like http://192.168.1.4:8080/api/HomeAutomation.HomeGenie.Automation/1002/1/Door.Toggle//1399413698749?_=1399413611403.  My WebServiceCallReceived handler is handling calls to http://192.168.1.4:8080/api/Garage.Doors/1/Door.Toggle. 

Maybe I'm passing the wrong parameters to HG.Control.Modules.ServiceCall?  Here is what my call looks like:

HG.Control.Modules.ServiceCall('1/Door.Toggle', HG.WebApp.Data._CurrentModule.Domain, HG.WebApp.Data._CurrentModule.Address, '', function (data) { })

May 07, 2014, 10:58:06 AM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
If the widget references the automation program module itself, the domain and the address for HG.WebApp.Data._CurrentModule will be HomeAutomation.HomeGenie.Automation (default programs domain) and 1002 (program ID).
An automation program domain/address cannot be changed.

If you want to use custom domain/address, then your program has to register a virtual module using the Program.AddVirtualModule  or Program.AddVirtualModules function.

See http://www.homegenie.it/docs_api/advanced.html for further informations about Virtual Modules.

When you register a virtual module, this will be added in the modules list under the domain of your choice (eg. Garage.Doors).

So, for your specific case, add these lines in the trigger code:

Code: [Select]
Program.Setup(()=>
{             
      Program.AddVirtualModule("Garage.Doors", "1", "Sensor", "homegenie/generic/doorwindow");
});

After that, remember to pick the module "Garage.Doors.1" instead of the automation program.
This will make HG.WebApp.Data._CurrentModule reference the virtual module domain/address that will thus match the one you registered in the WebServiceCallReceived.

Cheers,
g.