HomeGenie Forum
General Category => Troubleshooting and Support => Topic started by: HGexperimenter on February 08, 2017, 08:00:26 PM
-
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:
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"
-
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.
-
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.
-
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 (http://www.homegenie.it/forum/index.php?topic=129.msg11843#msg11843)
-
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!