How to check sensor is live ?

9 years 4 months ago #2035 by DaTT
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.

I'm sorry for my poor english. I speak Czech.
The following user(s) said Thank You: osalval

Please Log in or Create an account to join the conversation.

9 years 4 months ago #2037 by bit
Replied by bit on topic How to check sensor is live ?
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.

I'm sorry for my poor english.

Please Log in or Create an account to join the conversation.

9 years 4 months ago #2039 by DaTT
Replied by DaTT on topic How to check sensor is live ?

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'm sorry for my poor english. I speak Czech.

Please Log in or Create an account to join the conversation.

9 years 4 months ago #2050 by bit
Replied by bit on topic How to check sensor is live ?
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 ;)

I'm sorry for my poor english.
The following user(s) said Thank You: osalval

Please Log in or Create an account to join the conversation.

9 years 4 months ago #2063 by osalval
That is my problem also.

You can add "Status.Connection" in ESP8266 driver but I think MySensor don't have this posibility. :angry:

Please Log in or Create an account to join the conversation.

9 years 4 months ago - 9 years 4 months ago #2067 by bit
Replied by bit on topic How to check sensor is live ?
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.

I'm sorry for my poor english.
The following user(s) said Thank You: osalval, DaTT

Please Log in or Create an account to join the conversation.

Time to create page: 0.402 seconds

Forum latest

  • No posts to display.