more G-Labs products

Author Topic: Thermostat we request: Intermittent error  (Read 566 times)

February 08, 2017, 08:00:26 PM
Read 566 times

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
I have a WiFi thermostat that works fine with the request except around once a week I get this error (log file):
2017-02-07 15:02:54.7902 Error HomeAutomation.HomeGenie.Automation   NetHelper   Error: ConnectFailure (No route to host)   Exception.StackTrace     at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0

The code wraps an exception check, but does not seem to work:
Code: [Select]
var ReadThermostat = new Func<dynamic>( () => {
  try {
      var resultJson = Net.WebService("http://"+webID+"/tstat").GetData(); // json data
      return resultJson;
      } catch (Exception e) {
        Program.Notify("ReadThermostat:"+TTYPE+" result: ERROR", e.Message);
        //Console.WriteLine(e.Message + "\n" + e.StackTrace); // test this too
        return null;
      }
});

Possibly the Net.WebService call does not pass back the exception?
Note: When I restart the program, everything works fine...

PS: The error in the Details section of the program is:
Runtime.Error = "CR: Cannot perform member binding on `null' value"

« Last Edit: February 08, 2017, 08:03:53 PM by HGexperimenter »

February 08, 2017, 08:28:03 PM
Reply #1

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
Yes, it's definitely possible that exception is suppressed.
If you look in sources, you'll find a lot of try-catch'es with empty catch block.
I'll check the source code of Net.WebService tomorrow morning.

February 09, 2017, 06:37:44 AM
Reply #2

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
Well, yes, NetHelper.GetData() tries to deserialize response as XML or JSON data and in case of exception - returns response itself, not an object. Take a look here: https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/Scripting/NetHelper.cs#L428.
Also, the Call() method of NetHelper class handles an exception in WebClient call itself and logs an error (https://github.com/genielabs/HomeGenie/blob/master/HomeGenie/Automation/Scripting/NetHelper.cs#L401).
So the exceptions are not being rethrown.

You can check the data you have after calling Net.WebService().GetData() and if it's an empty string or not JSON object - handle this situation.
Also, I'm working now on auto restarting of failed programs, maybe this will help you too.

February 12, 2017, 02:22:45 PM
Reply #3

Bounz

  • ***
  • Information
  • Full Member
  • Posts: 94
Hi, HGexperimenter.

Try to check an auto-restart feature I've implemented in new testing build. Download link is here: http://www.homegenie.it/forum/index.php?topic=129.msg11843#msg11843

February 15, 2017, 10:45:32 PM
Reply #4

HGexperimenter

  • **
  • Information
  • Jr. Member
  • Posts: 42
Hi Bounz,

Thanks for the help.  I will first try to do the check on the returned string from Net.WebService().GetData() for empty or non-json.

It would be great to have the error catch passed or retry capability since this sort of web call to WiFi will potentially have a collision or other problems intermittently.

Thanks for your help!