This tutorial will explain basics of EasyIoT server automation. Sometimes we want to automate functions in EasyIoT server. For example we want to get SMS alarm if water leak occurs or get Email notification if some event occurs, do more actions if we press one button or execute specific commands on predefined time schedule.
All settings can be done in configuration with admin username. In web interface go to Configure->Automation. Here you can add automation group. The purpose of automation group is to group similar automation programs together.
To test automation program we firs create one group and then add new automation program:
We name program and press button Add. We leave cron job empty for now.
As we can see, program is now disabled with no cron settings. To go to program editor press Edit program.
Automation engine creates template program. All programs are written in C# and use EasyIoT helper function to access EasyIoT server objects and events. We will write more about helper functions in next automation tutorial.
For now we will explain how automation module works. We see two functions Setup and Run. Setup function will execute only once at program start (when program is enabled or server started). Run function is executed on Cron schedule. We will explain cron schedule later.
For now we modify program to this:
This code is running one time when program is enabled
public void Setup()
Console.WriteLine("My test program Setup executed");
This code is running periodicaly when program is enabled.
Cron job detirmine running period.
public void Run()
Console.WriteLine("My test program Run executed");
Update program and go back. When you update program program is compiled and checked for errors. Now enable program and look in EasyIoT server console. You should see something like this:
You will see console output written in setup function. Setup function executes only once when you enable it. In this part ob program we usually put EasyIoT event helper functions to setup custom even handlers.
If we want to execute some functions in regular interval we setup Cron settings. Cron settings are in crontab format:
* * * * * - - - - - | | | | | | | | | +----- day of week (0 - 6) (Sunday=0) | | | +------- month (1 - 12) | | +--------- day of month (1 - 31) | +----------- hour (0 - 23) +------------- min (0 - 59)
For example if we write in crontab like this:
* * * * *
It will execute every minute. If we look in our console output we will see:
Setup is executed only once and Run is executed every minute.
For example if we want to execute our program on specific minute, hour, day, month or day of the week we change cron settings accordingly. Next is more complex example:
0 12 * */2 Mon
This Cron will execute at 12:00 PM on Monday of every other month, starting with January. For more cron examples use keyword "cron expressions" in web search engine.
All enabled programs started at EasyIoT server startup with 1 min delay.
This are basics of EasyIoT server automation. More will be explained in next tutorial.
See more tutorials at http://iot-playground.com/build
To support this site and EasyIoT framework development please buy in our store.
Raspberry Pi 512MB Model B +
Raspberry Pi Model B+, ARM1176JZF-S Running at 700MHz, 512MB RAM.