more G-Labs products

Author Topic: Virtual modules and custom hardware  (Read 860 times)

June 13, 2016, 08:17:26 PM
Read 860 times

Bartek

  • *
  • Information
  • Newbie
  • Posts: 6
Hi,

I'm trying to understand HG philosophy behind the virtual modules to integrate my hardware modules with HG, and I need some help.

My home automation has many hardware devices, lets say I've got N relay devices. Each of these devices has a 6 relays (channels) to control 6 lights. I can talk to my home automation using TCP Helper. To control a single relay (light) I need to know the device ID, and then the relay number (1-6).

So, I started to implement this in HG. I'm added a new program that can talk with my system, then add 6 virtual modules (because single device has 6 outputs) in Startup Code. I'm also added option called DeviceID.

Now there is a problem. How can I add more than one device with this 6 outputs. I can't change the virtual modules for this program to lets say 12 for 2 devices or 18 for 3 devices, because each of these device has a different ID which I want to setup from options parameter.

Is it possible to configure HG in that way?

And problem no 2. My system TCP connector supports only few connections in the same time. If I have many programs in HG that handles many devices then I want to have only a single connector code, that talks with my system and route events to the specific programs. What is the best way to achieve this? Do I need to write a MIG Interface that handles the communication? Is it the best solution?

September 06, 2016, 08:41:25 AM
Reply #1

reza

  • *
  • Information
  • Newbie
  • Posts: 10
put something like this in the startup code

Code: [Select]
  Program.AddVirtualModules("HomeAutomation.RCSwitch", "Switch", "homegenie/generic/switch", 1, 5)
  .Run();

will create 5 virtual devices (for example)

in your code, implement url handlers like this one

Code: [Select]
// - http://<hg_address>/api/HomeAutomation.RCSwitch/lightnumber/command
When.WebServiceCallReceived("HomeAutomation.RCSwitch", ( args ) => {
  string[] reqs = ((string)args).Split('/');
  //string domain = reqs[0];
  bool win = true;
  try  {
    string lightnumber = reqs[1];
    string command = reqs[2];
    ...

and then you can act on that module. you'll have to serialize them all so create like 36 devices and you can then do something like

Code: [Select]
module = (int)(number / 6);
light      = number%6;