Ping Me At Home Extended

This program stops quite regularly do to this error “CR: Network is unreachable”. If I use v1.1-beta.526.bounz I can set it to restart but at the moment I’m using 526 from Gene.

Here is the C# program code. I don’t think there is any error trapping. Could a C# programmer please suggest an edit for error trapping?

var module = Modules.InDomain("Security.Pingmeathome").WithAddress("1").Get();
string param1 = "Sensor." + Program.Option("PingMe.Name1").Value;
string param2 = "Sensor." + Program.Option("PingMe.Name2").Value;
string param3 = "Sensor." + Program.Option("PingMe.Name3").Value;  
string param4 = "Sensor." + Program.Option("PingMe.Name4").Value;  
if (Program.Option("PingMe.Name1").Value != "")
{
  module.Parameter(param1).Value = "0";
}
if (Program.Option("PingMe.Name2").Value != "")
{
  module.Parameter(param2).Value  = "0";
}
if (Program.Option("PingMe.Name3").Value != "")
{
  module.Parameter(param3).Value  = "0";
}
if (Program.Option("PingMe.Name4").Value != "")
{
  module.Parameter(param4).Value  = "0";
}
//
while (Program.IsEnabled)
{
  
  	Pause(8);

    int pinging_buddiesall = 0;
    int pinging_buddies1 = 0;
    int pinging_buddies2 = 0;
    int pinging_buddies3 = 0;
    int pinging_buddies4 = 0;
    for (int i=0;i<5;i++)
    {
    if (Program.Option("PingMe.Address1").Value != "" && Net.Ping(Program.Option("PingMe.Address1").Value))
    {
          pinging_buddies1++;
    }
    if (Program.Option("PingMe.Address2").Value != "" && Net.Ping(Program.Option("PingMe.Address2").Value))
    {
          pinging_buddies2++;
    }
    if (Program.Option("PingMe.Address3").Value != "" && Net.Ping(Program.Option("PingMe.Address3").Value))
    {
          pinging_buddies3++;
    }
    if (Program.Option("PingMe.Address4").Value != "" && Net.Ping(Program.Option("PingMe.Address4").Value))
    {
          pinging_buddies4++;
    }
      Pause(2);
    }
    //
    pinging_buddiesall = pinging_buddies1+pinging_buddies2+pinging_buddies3+pinging_buddies4;
    if (pinging_buddiesall > 0 && Program.Parameter("PingMe.AtHome").Value != "1")
    {
        Program.RaiseEvent("PingMe.AtHome", "1", "Ping Me At Home");     
    }
    else if (pinging_buddiesall == 0 && Program.Parameter("PingMe.AtHome").Value != "0")
    {
        Program.RaiseEvent("PingMe.AtHome", "0", "Ping Me At Home");
    }
    //
    if (Program.Option("PingMe.Address1").Value != "" && Program.Option("PingMe.Name1").Value != "" && pinging_buddies1 > 0 && module.Parameter(param1).Value != "1")
    {
      Program.RaiseEvent(module,param1, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address1").Value != "" && Program.Option("PingMe.Name1").Value != "" && pinging_buddies1 == 0 &&  module.Parameter(param1).Value != "0")
    {
	   Program.RaiseEvent(module,param1, "0", "Status update");
    }
    //
    if (Program.Option("PingMe.Address2").Value != "" && Program.Option("PingMe.Name2").Value != "" && pinging_buddies2 > 0 && module.Parameter(param2).Value != "1")
    {
      Program.RaiseEvent(module,param2, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address2").Value != "" && Program.Option("PingMe.Name2").Value != "" && pinging_buddies2 == 0 &&  module.Parameter(param2).Value != "0")
    {
	   Program.RaiseEvent(module,param2, "0", "Status update");
    }
    //
    if (Program.Option("PingMe.Address3").Value != "" && Program.Option("PingMe.Name3").Value != "" && pinging_buddies3 > 0 && module.Parameter(param3).Value != "1")
    {
      Program.RaiseEvent(module,param3, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address3").Value != "" && Program.Option("PingMe.Name3").Value != "" && pinging_buddies3 == 0 &&  module.Parameter(param3).Value != "0")
    {
	   Program.RaiseEvent(module,param3, "0", "Status update");
    }  
    //
    if (Program.Option("PingMe.Address4").Value != "" && Program.Option("PingMe.Name4").Value != "" && pinging_buddies4 > 0 && module.Parameter(param4).Value != "1")
    {
      Program.RaiseEvent(module,param4, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address4").Value != "" && Program.Option("PingMe.Name4").Value != "" && pinging_buddies4 == 0 &&  module.Parameter(param4).Value != "0")
    {
	   Program.RaiseEvent(module,param4, "0", "Status update");
    }    
    //
 
}
Program.GoBackground();

Hi, Claton.
You can wrap the whole code block inside while into try…catch block.
So you will have something like

while (Program.IsEnabled)
{
    try
    {
        Pause(8);
        ...
        //
    }
    catch (Exception ex)
    {
        // do something with exception
    }
}

Thanks for the reply but I don’t quite understand how to do this. If you could put that in the code and post I can try it. What I’d like it to do is restart the program. Although better would be to figure out what’s broken.

this is the current error I get.

Runtime.Error = “CR: Could not resolve non-loopback IP address for localhost”

Hi Claton,
It seems that there are problems with the network subsystem that lead to exceptions in Net class methods’ calls.
Try to add try...catch block at the very beginning of your endless loop as I suggested earlier. Just cut and paste all your program logic from the while block into the try block. You can do nothing with exception inside the catch block (leave it empty).

I’m not clear on how to do this. I see the try but not the catch. Could you please copy the program code I posted into an editor and insert the try catch and then upload it back here? Then I can copy and paste the whole thing and give it a try.

var module = Modules.InDomain("Security.Pingmeathome").WithAddress("1").Get();
string param1 = "Sensor." + Program.Option("PingMe.Name1").Value;
string param2 = "Sensor." + Program.Option("PingMe.Name2").Value;
string param3 = "Sensor." + Program.Option("PingMe.Name3").Value;  
string param4 = "Sensor." + Program.Option("PingMe.Name4").Value;  
if (Program.Option("PingMe.Name1").Value != "")
{
  module.Parameter(param1).Value = "0";
}
if (Program.Option("PingMe.Name2").Value != "")
{
  module.Parameter(param2).Value  = "0";
}
if (Program.Option("PingMe.Name3").Value != "")
{
  module.Parameter(param3).Value  = "0";
}
if (Program.Option("PingMe.Name4").Value != "")
{
  module.Parameter(param4).Value  = "0";
}
//
while (Program.IsEnabled)
{
  try
  {
    Pause(8);

    int pinging_buddiesall = 0;
    int pinging_buddies1 = 0;
    int pinging_buddies2 = 0;
    int pinging_buddies3 = 0;
    int pinging_buddies4 = 0;
    for (int i=0;i<5;i++)
    {
    if (Program.Option("PingMe.Address1").Value != "" && Net.Ping(Program.Option("PingMe.Address1").Value))
    {
          pinging_buddies1++;
    }
    if (Program.Option("PingMe.Address2").Value != "" && Net.Ping(Program.Option("PingMe.Address2").Value))
    {
          pinging_buddies2++;
    }
    if (Program.Option("PingMe.Address3").Value != "" && Net.Ping(Program.Option("PingMe.Address3").Value))
    {
          pinging_buddies3++;
    }
    if (Program.Option("PingMe.Address4").Value != "" && Net.Ping(Program.Option("PingMe.Address4").Value))
    {
          pinging_buddies4++;
    }
      Pause(2);
    }
    
    pinging_buddiesall = pinging_buddies1+pinging_buddies2+pinging_buddies3+pinging_buddies4;
    if (pinging_buddiesall > 0 && Program.Parameter("PingMe.AtHome").Value != "1")
    {
        Program.RaiseEvent("PingMe.AtHome", "1", "Ping Me At Home");     
    }
    else if (pinging_buddiesall == 0 && Program.Parameter("PingMe.AtHome").Value != "0")
    {
        Program.RaiseEvent("PingMe.AtHome", "0", "Ping Me At Home");
    }
    
    if (Program.Option("PingMe.Address1").Value != "" && Program.Option("PingMe.Name1").Value != "" && pinging_buddies1 > 0 && module.Parameter(param1).Value != "1")
    {
      Program.RaiseEvent(module,param1, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address1").Value != "" && Program.Option("PingMe.Name1").Value != "" && pinging_buddies1 == 0 &&  module.Parameter(param1).Value != "0")
    {
	   Program.RaiseEvent(module,param1, "0", "Status update");
    }
    
    if (Program.Option("PingMe.Address2").Value != "" && Program.Option("PingMe.Name2").Value != "" && pinging_buddies2 > 0 && module.Parameter(param2).Value != "1")
    {
      Program.RaiseEvent(module,param2, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address2").Value != "" && Program.Option("PingMe.Name2").Value != "" && pinging_buddies2 == 0 &&  module.Parameter(param2).Value != "0")
    {
	   Program.RaiseEvent(module,param2, "0", "Status update");
    }
    
    if (Program.Option("PingMe.Address3").Value != "" && Program.Option("PingMe.Name3").Value != "" && pinging_buddies3 > 0 && module.Parameter(param3).Value != "1")
    {
      Program.RaiseEvent(module,param3, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address3").Value != "" && Program.Option("PingMe.Name3").Value != "" && pinging_buddies3 == 0 &&  module.Parameter(param3).Value != "0")
    {
	   Program.RaiseEvent(module,param3, "0", "Status update");
    }  
    
    if (Program.Option("PingMe.Address4").Value != "" && Program.Option("PingMe.Name4").Value != "" && pinging_buddies4 > 0 && module.Parameter(param4).Value != "1")
    {
      Program.RaiseEvent(module,param4, "1", "Status update");
    }
    else if (Program.Option("PingMe.Address4").Value != "" && Program.Option("PingMe.Name4").Value != "" && pinging_buddies4 == 0 &&  module.Parameter(param4).Value != "0")
    {
	   Program.RaiseEvent(module,param4, "0", "Status update");
    }    
    
  }
  catch (System.Exception)
  {} 
}
Program.GoBackground();

This seems to have worked! Thanks much Bounz

perhaps this change should be made to the download archive?