In this tutorial we will show how to set up sensor low battery alarm in EasyIoT server automation function. We will be notified by email when one of sensors batteries is low.
Battery powered sensors can report it's battery level from 0 to 100%. Checking all battery statuses of all sensor nodes to determine flat battery in user interface is not practical. We will show how to automate this function in EasyIoT server automation module.
We want to be notified for low battery status once per week on Friday at 15:30 by email. Before configuring EasyIoT server automation function we recommend reading following tutorials:
EasyIoT server automation - part I
EasyIoT server automation - part II
EasyIoT server automation - part III
In EasyIoT server automation module we add new automation program. We will name program "Module battery check" and set CRON to 30 15 * * fri. CRON 30 15 * * fri means program execution every Friday at 15:30. Next we will write program - press button edit.
Because we will execute program periodically, we will keep Setup() function empty and add our program in Run(). In program we loop trough all modules and read property Status.Battery. If property exists we check its value. If value is less than 5 we send email notification. Change email addresses and password to suits your account. And don't forget to enable automation program.
It's also very easy to change program to send SMS message instead of email notification with SmSHelper function.
Automation program:
/* 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()
{
String outTxt = "";
EmailHelper.SetupSmtp("This email address is being protected from spambots. You need JavaScript enabled to view it.", "password", "smtp.gmail.com", 587, true);
foreach (Module m in Modules.Instance.ModuleList)
{
ModuleParameter p = m.FindProperty("Status.Battery");
if (p!= null)
{
if (p.DecimalValue <= 5)
{
outTxt += "Change battery in module: "+ m.Domain + " "+ m.Address + ": "+m.Description + ", battery: " + p.Value + "%\n\r";
continue;
}
}
}
if (outTxt != "")
EmailHelper.SendEmail("This email address is being protected from spambots. You need JavaScript enabled to view it.", "This email address is being protected from spambots. You need JavaScript enabled to view it.", "[EasyIoT server] Module battery status alarm", outTxt);
}
See more tutorials at http://iot-playground.com/build
Comments
RSS feed for comments to this post