Very good idea..... I read your post yesterday and tried to get it to work with EasyIOT.... I am a total newbie at coding so please forgive the code
I have set up as a cron job to run every couple of minutes to ping my phone when my Alarm value is Off.... I suppose I can get it to run all the time and set the Alarm on and off whenever the phone is pingable but I want to to able to set the Alarm to ON at night and the phone will also be pingable so I dont want it to automatically turn the alarm off just beacuse the phone is pingable.
UPDATE: I noticed that sometimes I get false possitives when I am walking around the house cause I have a wifi extender and when my phone hopes to the extender and a ping happens at the same time then I get a false possitive... So I have added a loop to the ping so that it pings 3 times with a 3 second interval between pings to make the system more resilent to movement. I have also added an update where it also sends a notification to my phone that the alarm has been activated.
Here is the second try at the code:
public void Setup()
{
}
public void Run()
{
Console.WriteLine("Ping Test Program was Started");
ModuleParameter p = ModuleHelper.GetProperty(Domains.VIRTUAL, "N18S0", "Sensor.DigitalValue");
if (p.Value == "0")
{
int pingAttempts = 0;
int maxPingAttempts = 3;
System.Net.NetworkInformation.Ping PingSender = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingReply pingReply;
Console.WriteLine("Ping Test Program is Running");
// Loop until the first successful call or 3 failed attempts
do
{
pingAttempts++;
pingReply = PingSender.Send("192.168.1.187");
System.Threading.Thread.Sleep(3 * 1000);
Console.WriteLine("Ping Attempt Number: " + pingAttempts);
}
while ((pingReply.Status != System.Net.NetworkInformation.IPStatus.Success) && (pingAttempts < maxPingAttempts));
// pingReply is either the first successful one, or the last of
// the loop (all of which would have been false)
if (pingReply.Status != System.Net.NetworkInformation.IPStatus.Success)
{
DriverHelper.ProcessCommad(Domains.VIRTUAL, "N18S0", "ControlOn", "");
Console.WriteLine("The Alarm has been turned ON");
System.Collections.Specialized.NameValueCollection values = new System.Collections.Specialized.NameValueCollection();
System.Net.WebClient client = new System.Net.WebClient();
values["AuthorizationToken"] = "a super secret token that you need to get for yourself";
values["Body"] = "Automation has turned the Alarm ON";
client.UploadValues("
pushalot.com/api/sendmessage",values
);
}
}
}