more G-Labs products

Author Topic: Capturing and Logging Events, Basic HG Runtime Debugging with MonoDevelop  (Read 1074 times)

January 10, 2016, 08:37:36 PM
Read 1074 times

m0davis64

  • *
  • Information
  • Newbie
  • Posts: 1
HG v1.1 r508, Aeon z-stick r2

I am a newbie to homegenie and C# but have programmed for many, many years. Unfortunately, in C, C++, Java and in Smalltalk, LISP, and NeXTStep/OPENStep/Cocoa - As it turns out, none of those are very useful here until I get my hands around the environment and the basics of C# in MonoDevelop with HomeGenie's model. My .Net experience is limited to two 3-4 month long Excel-VBA programs.

I have experience supporting newbies who don't read the docs, use google extensively, and attempt to exhaust such options before posting, and after using HomeGenie for about a month, and spending a lot of time (just short reading all the forum posts in order), Google'ing my HomeGenie challenges, I need to ask a few questions. As I said, for the last week, I have been hunting the forums, reading nearly every entry in order, but I find the newer posts don't address my questions, and the older posts, which are relevant, are wrong (out of date) as HomeGenie appears to have a fastly moving development lifecycle. I have resorted to posting what *I* consider really stupid newbie questions. I appreciate your patience.

BTW, even though I wrote a long post here, I am generally looking for the 1 line answers with a screen shot. Don't feel required to give a long answer. :-) Given a few simple tips I expect I can figure it out.

(1) I have read and studied the logs (both console and log file) and read lots of the zwave standard, so I figured out the discovery, messaging, ack/nak, etc  between modules/widgets, some by reading the hex digits in the console debugging stream output. This was trying to figure out why my aeon labs minimote was not detected. I can add and remove the minimote to and from from the zwave network, and HomeGenie knows it is there (it has a node number), but events do not appear in any log (or console). I can watch HomeGenie try to discover it, but it times out. (I do know about waking it up by pressing a button for 3 seconds.) FYI, I did find the posts about the minimote in the forums, and elsewhere, and tried many of the ideas there (all the ones where people said the solution solved their problem).  And I know the codes and true button names for each of the buttons (since the documentation varies by packaging and US/EU). Any advice on this - where the event should be - its syntax - etc - is appreciated.

(2) The wizard programming is very nice, especially given my less than stellar experience with any of the supported languages. Question: How to 'print or debug to stdout or the log?' I tried a one line program (hello world equivalent) but basically cannot figure out the with/include/using syntax to get the library I need - or the path syntax of the library in the Mono/HomeGenie universe. Example (you can see some attempts in the commented-out code, since lots of zwave stuff does not make it to the console or logs):
trigger code:
hg.Program.Run();
program code:
//{
  // using HomeGenie.Service.Logging;
  // using SystemLogger;
  HomeAutomation.HomeGenie.SystemLogger.WriteToLog("test");
  // System.IO.File.AppendAllText("~/HomeGenieActivity.log", DateTime.Now.ToString("yyyyMMdd HH:mm:ss") + " : " + aString + "\n");
//}
Now I can just use this from any 'program code' segment of a wizard program I write.

(3) So I gave up on the minimote and moved to my true goal - To get my yard uplighting to turn on at dusk and off at a set time. I know cron for many, many years, but again the syntax for using it (that is the StatusField Equals the cron string is all trial and error (just a few days waiting for the dusk event to see if it matched) to sort that out. Better examples would help - like what field to use to compare to the cron string and how to compare it - would help. Yes, the doc says @Event; cron-string, but without the actual event path, this is still trial and error (nothing to log for events not matched, no event to log with jkUtils fires - some can be found from the UI widget updating, but the event that caused the update is not listed, just the name of the png file, which is reused for sunrise and sunset). Figured out I didn't want 'Earth Tools' or 'Weather Underground'. Figured out I could disable them without screwing up jkUtils. Recall I have no debugging (no scaffolding ability and no .Net environment). Speaking of scaffolding and or .Net environment, see (2 above).

(4) Related to (2), for jkUtils (nice work Jan, and bkenobi later), I discovered (by reloading HomeGenie to completely reset it) that the Lat/Long field in jkUtils does not understand compass points, that is, NSEW. It only gave me an error at line 259, 'not a number', and then filled the widget with NaNs. Two comments, a test for not a number there and print *what* it thinks is not a number, would be wonderful, and (b) the error at this line drove me to install MonoDevelop and to download and install all the sources. I have lots of experience with debuggers, so no issues there, and I thought this a good way to learn a little more about HomeGenie anyway. Unfortunately, putting a break point on line 259 (I could see the code) did not stop the debugger at the breakpoint, even though the error at the line still showed in the UI. Some tips on the MonoDevelop debugger would be good - hopefully this is not a MonoDevelop question, but a question on how files and threads behave in HomeGenie so the debugger is used correctly. BTW, I did figure out all the Mono directories, the source and build directories, how to archive and restore, and edited a few XML files to restore lost programs (programs in my group that no longer showed in *any* group, even though they were still in the XML file (that is, unreachable via the UI), etc. This is certainly a bug, but I cannot repeat it, so will not report it. So I think I was looking in the right places. I suspect I was attached to the main thread and the jkUtils:259 was in a thread that was not monitored by the debugger. A tip here would help a lot. I'm a beast once I have my debugging environment setup. :-)
BTW, the file with line 259 is: HomeGenie-master/BaseFiles/Common/html/pages/control/widgets/jkUtils/SolarAltitude/SolarAltitude.js
The code block is:
    ParseTime: function (timestring) {
        var d = new Date();
259:    var time = timestring.match(/(\d+)(?::(\d\d))?\s*(p?)/);
        d.setHours(parseInt(time[1]) + (time[3] ? 12 : 0));
        d.setMinutes(parseInt(time[2]) || 0);

        return d;

    },
Obviously, whatever is calling parseTime() is handing a bad parameter - I assume the NSEW at the end of Lat/Long, but I can't actually see the value because the debugger won't stop and thus no stack trace.
Other likely possibilities is the UI does not check the value entered in the UI for the Lat/Long, or the validation pattern doesn't match what timestring/match() will take, etc.

Thanks for you help with this list of questions.

January 12, 2016, 03:21:32 PM
Reply #1

[email protected]

  • *****
  • Information
  • Hero Member
  • Posts: 271
2) Console.WriteLine("Blah: something");

you can then stop home genie (assuming linux based here )

/etc/init.d/homegenie stop
cd /usr/local/bin/homegenie/
mono ./HomeGenie.exe

this will then run it in a point where you can see the logs in realtime :)

you could also do

mono ./HomeGenie.exe |grep -i "Blah:"

or whatever criteria you want (-i case insensitive)

I believe there is also a method that you can call to use NLOG iirc, but at work at the moment with limited access to check

January 12, 2016, 05:33:43 PM
Reply #2

Gene

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