Is there any way to determine if the sensor alive? I have NRF24L01 Arduino door / window sensor connected via NRF24L01 to the raspberry pi server. Alarms (open / closed) go right. But when I unplug the power Arduino sensor, the server does not know it. So the server indicates the last state of sensor and thinks that sensor lives. Can I keep using automation to check whether the sensor is live and connected, if so, how? Thank you.
hi,
door sensor can't receive ping from gateway, it only transmit and sleep.
but you could add routine on sensor's sketch to send periodically ping from sensor to gateway, so checking (server side) this with automation program.
bit wrote: hi,
door sensor can't receive ping from gateway, it only transmit and sleep.
but you could add routine on sensor's sketch to send periodically ping from sensor to gateway, so checking (server side) this with automation program.
Thank you for answer. Can you advise how to do it? The code samples would be best. Please. Thank you.
i know how to do it in sensor, but i still don't know how to do it in automation. i'm new in c#, so i need to get information about.
i need too this code and i'm working on it. i will post the code next days.
keep in touch
hello, i'm back with my code.
it seems to work properly, but i please you to test it.
almost nothing to do in door/wìndow sensor sketch, because it already have routine to send ping (for daily battery check ). we just need to set a shorter sleep time.
change:
#define SLEEP_IN_MS 86400000 // 1 day
to (for example):
#define SLEEP_IN_MS 60000 // 10 minutes
then add the automation program:
public void Setup()
{
EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine ("------>>>> saving receiving time");
long UnixNow = ConvertToUnixTime(DateTime.Now);
Console.WriteLine (UnixNow);
ModuleHelper.SetProperty( m.Domain, m.Address, "Last.Check", UnixNow.ToString() );
return true;
});
}
public void Run()
{
int CheckPeriod = 600; // <<<---- set interval here (in sec.): if sensor don't send ping within this time it's considered disconnected.
Console.WriteLine ( "---> Check sensor alive");
foreach (Module m in Modules.Instance.ModuleList)
{
ModuleParameter p = m.FindProperty("Last.Check");
if (p!= null)
{
Console.WriteLine (p.Value);
if ( ConvertToUnixTime( DateTime.Now ) - p.DecimalValue > CheckPeriod)
Console.WriteLine ( "Sensor "+ m.Domain + ":"+ m.Address + " - "+m.Description + " ---> DISCONNECTED! " );
else
Console.WriteLine ( "Sensor "+ m.Domain + " "+ m.Address + ": "+m.Description + " ---> IS ALIVE! " );
}
}
}
public static long ConvertToUnixTime(DateTime datetime)
{
DateTime sTime = new DateTime(1970, 1, 1,0,0,0,DateTimeKind.Utc);
return (long)(datetime - sTime).TotalSeconds;
}
this automation just print sensors status on console.
lastly add cron job every 10 minutes : */10 * * * *
that's all. hope can help.