more G-Labs products

Author Topic: Program with virtual modules not responding to widget  (Read 1626 times)

September 11, 2015, 02:31:16 PM
Read 1626 times

domotica_user

  • *
  • Information
  • Newbie
  • Posts: 14
Dear all,
I have a program running with a When.WebServiceCallReceived(MODULES_DOMAIN, ( args ) and a When.ModuleParameterChanged( (module, property) section. Both contain very little (basically just a: Program.Notify("Widget test", "Test"); ). I have created two widgets and bound them to the appropriate virtual module. So i have a program -> 5 virtual modules -> 2 widgets for virt. mod.1 and 2

Unfortunately, when i click on the switch on my dashboard, nothing happens (i expect a message "Test" popping up). When opening my FF java console i see the following message: "no element found"

What have i forgotten to do?
Thank you very much for your help.
Regards!

September 11, 2015, 02:52:01 PM
Reply #1

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
You can look at that item for guide you on pogramming a new virtual module :

http://www.homegenie.it/forum/index.php?topic=975.msg5938#msg5938

Cheers
Dani

September 11, 2015, 03:16:32 PM
Reply #2

domotica_user

  • *
  • Information
  • Newbie
  • Posts: 14
Hi Dani,
Thank you for your reply. I did see this post yesterday, but as far as i can see i have done exactly that, but the widget is not connected to the program (or virtual module). I have in my program:
-  Trigger code: "Program.AddVirtualModules(MODULES_DOMAIN, "Switch", "homegenie/generic/switch", 1, 5)"
- Program code: var myModules = Modules.InDomain(MODULES_DOMAIN); When.WebServiceCallReceived(MODULES_DOMAIN, ( args ) => {
- Inside the WebServiceCallReceived routine i only have a Program.Notify() (to test).

I don't see what i am doing wrong (after reading your suggested post a few times. I hope you can point me in a specific direction. The domains match btw. I checked that a few times.
Thanks again!

September 11, 2015, 03:29:08 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Perhaps you're modifying the module parameter directly. Indeed, the magic is done by using the Program.RaiseEvent function to update the module parameter.  When changing a module parameter directly will just change it silently, will not fire any event, so will not notify to UI and the whole subsystem that the parameter has changed.

http://www.homegenie.it/docs/doxy/a00007.html#a218728a3b9a672b32b46f1e2275cc20d

g.

September 11, 2015, 03:31:57 PM
Reply #4

domotica_user

  • *
  • Information
  • Newbie
  • Posts: 14
Hi Gene,
Thanks for your reply. What i am doing is clicking on the widget on my dashboard. I expect the program to fire the WebServiceCallReceived routine, or am i mistaken?
Thanks for your reply.

September 11, 2015, 03:34:18 PM
Reply #5

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
http://www.homegenie.it/forum/index.php?topic=1061.msg6408#msg6408

yes it should hit the WebServiceCallReceived routine.
Open the web browser debugger to see what url is called when you hit the buttons.
Paste it here along with the code you currently implemented.

g.

September 11, 2015, 03:43:06 PM
Reply #6

domotica_user

  • *
  • Information
  • Newbie
  • Posts: 14
The following url is called:
http://10.x.x.93/api/HomeAutomation.Homeduino/1/Control.On/null/1441978679182?_=1441836391792

I have attached the program and trigger code.
I hope you can help me with this. Thanks!

September 11, 2015, 03:53:13 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
You are missing the

Code: [Select]
Program.GoBackground();

instruction at the end of your program code.
Otherwise the program will exit. You will know that is running in the background because the led light will turn green.

g.

September 11, 2015, 04:05:21 PM
Reply #8

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
The way you're using ModuleParameterChanged is not correct. This is supposed to be used for listening to module events, for instance when you turn on a module the Status.Level parameter will change to 1.

Code: [Select]


When.ModuleParameterChanged( (module, property) => {
  Program.Notify("Homeduino switch", "Test2");
  if (module.Instance.Domain == MODULES_DOMAIN )
  {
    int lightnumber = Convert.ToInt32(module.Instance.Address);
    switch (property.Name) {
      case "Meter.Watts":
        Program.Notify("Homeduino switch", "Meter.Watts = " + property.Value);
        break;
      case "Status.Level":
        Program.Notify("Homeduino switch", "Status.Level = " + property.Value);
        break;
      default: 
        break;
    }
  }
  return true;
});


when you click the ON button the "Control.On" command will be called, and so the WebServiceCallReceived function will perform

Code: [Select]
Program.RaiseEvent(module, "Status.Level", 1, "My Light");

causing the module Status.Level change to 1.


g.

September 11, 2015, 04:10:28 PM
Reply #9

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
I now see you took the code from the MyLight program. Well this is a program contributed by a forum user, and I didn't notice of the errors in it till now.
A better working example would have been the Philiphs Hue program.

g.

September 11, 2015, 09:54:58 PM
Reply #10

domotica_user

  • *
  • Information
  • Newbie
  • Posts: 14
It is fixed now. Gene, because of your remark of the missing Program.GoBackground();  i started looking into that (i HAD a green light, so why not working?).

It turned out that i was using a while(1) { sleep(); } and that was BEFORE the ModuleParameterChanged, so it never reached this section of code. Very silly of course, but all is well now :)
Thank you for helping me, i can start coupling the widgets with my hardware interface now.

BTW: Dutch users: I am using the Homeduino interface to have a Klik Aan Klik Uit (KAKU) interface for Homegenie. When this is working properly i will contribute the program to this project, but if you have questions about my kaku research, please let me know. I will help you setting stuf up.