more G-Labs products

Author Topic: Help to understand HG better  (Read 2672 times)

May 20, 2015, 06:10:29 PM
Read 2672 times

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
1-When should we use or not use RunAsyncTask?

2-When should we use Program.GoBackground();?  Only when program code has no while loop?


3-Trigger Code
-runs only once at start from what I understand?  There is a pulldown to change this, what condition is being evaluated?
-have to have this Program.Setup( () => {?
-what is the return actually used for?  only return true if program code has a while enabled loop in it?

May 20, 2015, 08:00:04 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
1. Preferably avoid using RunAsyncTask unless you want the stuff inside executed asynchronously (it will not wait for those instructions to complete)
2. Yes, but only if you have some event listeners in your code (eg. When.WebServiceCallReceived, When.ModuleParameterChange...)
3. Trigger code:
-  is used by program engine to evaluate if the code to run is to be execute or not. So it will run only when the program code is not active.
- Program.Setup is not mandatory and it is to be used when you need to execute some code only once when the program is activated
- the return will tell the program engine if the code to run has to be executed or not

Trigger code was initially thought for Wizard scripts and then (not so wisely) applied to other type of programs as well.  In the near future, trigger code will be deprecated and there will be only the code to run. I hope there will be less confusion in users by then :)

Cheers,
g.

May 28, 2015, 04:44:19 PM
Reply #2

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Next question, trying to understand the interfaces between clicking on the widgets and the corresponding code.  For example I am trying to use the colorlight widget to adjust a RGB LED on my arduino.

I added the widget in trigger/setup:
Code: [Select]
Program.AddVirtualModules("HomeAutomation.ArduinoBsmtUtil", "Sensor", "homegenie/generic/sensor", 1, 4);
Program.AddVirtualModules("HomeAutomation.ArduinoBsmtUtil", "Light", "homegenie/generic/colorlight", 5, 5);

Then in my code I have a function to send the RGB values via my serial port to Arduino, this part is working :-) .

Looking at the Fibraro and MiLight RGB lights for examples, I see they have code in
Code: [Select]
When.ModuleParameterChanged( (module, property) => {for Control.On and Control.Off, but not for Control.Level or Control.ColorHsb

They do handle these in the  webservice call however:
Code: [Select]
When.WebServiceCallReceived("HomeAutomation.MiLight", ( args ) =>
...
        case "Control.ColorHsb":
        string[] values = parameter.Split(',');


So this brings the question, do widgets use the webservicecall or moduleparameterchange to execute the code? 

Do the LED's or HSV values need to be formal module parameters?

Thanks!!!

May 29, 2015, 08:20:21 AM
Reply #3

dani

  • *****
  • Information
  • Global Moderator
  • Posts: 535
ModuleParameterChanged is used from Module to UI ou for perform some action when a module parameter changes.

WebServiceCall is used from WebAPI or UI (by WebAPI) to perform some action in HG, for exemple to send command to module.

May 29, 2015, 01:13:50 PM
Reply #4

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
So WebServiceCallReceived is executed by the colorlight widget when color is changed or turned on with a mouse click?

May 29, 2015, 03:20:30 PM
Reply #5

Gene

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

June 12, 2015, 02:35:38 AM
Reply #6

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330

I'm having a difficult time getting my web service call to work.  The camera code works, I see result in browser:
Code: [Select]
http://192.168.1.100/api/Media.IpCamera/1/Camera.MotionDetected
{ 'ResponseValue' : 'OK' }


So I try to duplicate this code in my HomeAutomation.ArduinoGarage program and nothing happens.  Is there some trick or some key pieces I could be overlooking?

http://192.168.1.100/api/HomeAutomation.ArduinoGarage/1/Status
---nothing in browser, no notification pops up

Code: [Select]
When.WebServiceCallReceived("HomeAutomation.ArduinoGarage/", ( args ) =>
{
    string[] reqs = ((string)args).Split('/');
    Program.Notify("Arduino Garage", "TEST");

June 14, 2015, 05:57:53 AM
Reply #7

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Even though the security system is enabled and has the default add feature for sensors and door windows, my arduino based door sensor and motion sensor widgets do not show the use as security Feature.  Why, how to get these to show up?

June 14, 2015, 10:00:07 PM
Reply #8

nolio

  • *****
  • Information
  • Global Moderator
  • Posts: 544
In "90 Security Alarm System" and trigger code :
Code: [Select]
Program.AddFeature("Sensor,DoorWindow", "HomeGenie.SecuritySensor", "Use as Security Sensor");
Program.AddFeature("Siren,Light,Dimmer,Switch", "HomeGenie.SecurityAlarm", "Use as Security Alarm");

You could see that your trigger for alarm is "sensor" or "doorwindow", are you sure you have selected one of this type in the configuration of the module ?

June 15, 2015, 03:51:37 AM
Reply #9

kevin1

  • *****
  • Information
  • Hero Member
  • Posts: 330
Yes, I have the arduino virtuals set as DoorWindow but they don't show any security options in the Control view.