report communication problem

6 years 2 months ago #1975 by bit
hi there,
is there some function in automation scripting to handle "sensor is not responding"?
for example:
if a relay actuator (receiver) is off, in web UI i can't change it state, and that's ok, but i would like to detect this situation to send a warnig.
thanks

I'm sorry for my poor english.

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

6 years 2 weeks ago #2289 by esawyja
I would also like this feature, if there is no data from a sensor for a configurable time period, either print it to console or email

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

6 years 2 weeks ago #2291 by EasyIoT

esawyja wrote: I would also like this feature, if there is no data from a sensor for a configurable time period, either print it to console or email


Here is my script in automation to report sensor connection failure. Each sensor reports it's status at least once in 24h. If status is missing then email is sent. Cron job is set to 1h.
/*
  This code is running one time when program is enabled
*/
public void Setup()
{
}

/*
  This code is running periodicaly when program is enabled. 
  Cron job detirmine running period.
*/
public void Run()
{
  EmailHelper.SetupSmtp("xxxxx@gmail.com", "xxxxx", "smtp.gmail.com", 587, true);
  
  String outTxt = "";
  
  foreach (Module m in Modules.Instance.ModuleList)
  {
    // we do not check those modules
    if (
      	m.Domain == "RPiGPIO" ||
      	m.Domain == "Virtual" || 
      	m.Domain == "Esp8266" && m.Address == "N1S10" ||
        m.Domain == "Esp8266" && m.Address == "N1S11" ||
        m.Domain == "Esp8266" && m.Address == "N1S12" ||
        m.Domain == "Esp8266" && m.Address == "N1S13" ||
        m.Domain == "Esp8266" && m.Address == "N1S14" ||
        m.Domain == "Esp8266" && m.Address == "N1S15" ||
        m.Domain == "Esp8266" && m.Address == "N1S16" ||
        m.Domain == "Esp8266" && m.Address == "N1S6" ||
        m.Domain == "Esp8266" && m.Address == "N1S7" ||
        m.Domain == "Esp8266" && m.Address == "N1S8" ||
        m.Domain == "Esp8266" && m.Address == "N1S9" ||
        m.Domain == "Virtual" && m.Address == "N1S0"              
       )
      continue;
    
    
    bool connectionOk = false;

    foreach (ModuleParameter p in m.Properties)
    {
      // if not settings and Status.Connection
      if (p.Name.IndexOf("Settings.") == -1 && m.Domain != "Esp8266")
      {
        if ((DateTime.UtcNow - p.UpdateTime).TotalHours <= 27)
        {
          connectionOk = true;
          break;
        }
      }
      else if (p.Name == "Status.Connection" && p.Value == "1")
      {
          connectionOk = true;
          break;
      }
    }
    
    if (!connectionOk)
      outTxt += "Module not connected: "+ m.Domain + " "+ m.Address + ":"+m.Description + "\n\r";
      
  }
  
  if (outTxt != "")
    EmailHelper.SendEmail("xxxx@gmail.com", "xxxxxx@gmail.com", "[EasyIoT server] Module connection status alert", outTxt);
}

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

Time to create page: 0.225 seconds

Forum latest

  • No posts to display.