more G-Labs products

Author Topic: help creating bi-directional widget and program  (Read 1086 times)

October 26, 2015, 01:02:54 AM
Read 1086 times

michaeltschmidt

  • *
  • Information
  • Newbie
  • Posts: 2
I am new to Homegenie, and must say, hands down the best, an I have tried many others. I am not a programmer, but can do some Web and script coding. I am stuck trying to figure out how to create a widget with both a display field and a switch that can activate a program and return results to the display of the widget. Can anyone post a simple widget and c# program to demontrate. It can be as simple as an on off switch that call a function to return a 1 for on and 0 for off. I am just struggling on how to pass the commands and data between the widget and program.

Thanks so much. I have looked at dozens of examples here in the forum, and have tried to cobble together some various pieces, but I am missing something somewhere.

October 26, 2015, 01:45:39 AM
Reply #1

Gene

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

October 30, 2015, 04:26:46 PM
Reply #2

michaeltschmidt

  • *
  • Information
  • Newbie
  • Posts: 2
Gene,

Thanks for the links, this is very helpful. I think i am starting to understand, i thought there was more to the connection between the widget and the program, but i see now that it is really just a web call that can also be done via the browser. I am still trying to map out what i am trying to do, but i think i am on the right track.

I do have one additional question, so i am wanting to create a program that i can execute with the scheduler at regular intervals. the program will basically send MQTT messages for a variety of items i am going to query. What i would like to do is store some dynamic data in a database or virtual memory, and query the data from my program. Can i use the program.store feature in one program to store dynamic data, and then consume the data by using reading that data from a different program? I am basically trying to do what i would normally do in a SQL TempDB.

Thanks,

Mike

October 30, 2015, 04:46:58 PM
Reply #3

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
You can get a reference to some other program by calling:

Code: [Select]
var program = Program.WithName("My Other Program");
var data = program.Store(...)...

if you prefer, you can reference a program using its address as well:

http://genielabs.github.io/HomeGenie/api/ape/a00009.html#a9a631da437211f32174acd888c2d0e81

Consider that a program store, can only have string values, so you'll have eventually to serialize data to JSON:

http://www.newtonsoft.com/json/help/html/serializingjson.htm

since in a HG program you cannot declare class, you'll have to use dynamic:

Code: [Select]
dynamic dataObject = new ExpandoObject();
dataObject.SomeField = "some value";
dataObject.SomeOtherField = 3;
var serializedObject = JsonConvert.SerializeObject(dataObject);
....

Another way of query some other program data, is to provide the other program of a own Web Service API:

http://genielabs.github.io/HomeGenie/api/ape/a00001.html#a58515455945c35783cde47d21f844663

hope this helps.
g.