README
IoT Platform
Lynxari Timer Application
Schedule events according to sun position or schedule
Install
Lynxari Server App for controling devices on a timed schedule
<script type="module">
import agilatechLynxariTimerApplication from 'https://cdn.skypack.dev/@agilatech/lynxari-timer-application';
</script>
IoT Platform
gt; npm install @agilatech/lynxari-timer-application
Install in the same directory in which lynxari is installed. Create a config.json file to suit.
The purpose of this application is to schedule actions and trigger events according to time or sun position. Through simple configuration, the app can initiate device transitions and launch shell programs at specific time periods, or at sunrise, sunset, noon, etc. No limits are placed onto the number of scheduled events, and the application may command devices on remotely linked servers as well as local ones.
This application runs on the Agilatech® Lynxari IoT platform. As such, it is not applicable for other environments.
To use it with Lynxari, simply insert its object definition as an element in the apps array in the applist.json file. On startup, the Lynxari server reads applist.json and starts all applications found there.
A config.json configuration file must be present in the module's main directory. For this module, that will be within the Lynxari home directory in node_modules/@agilatech/lynxari-timer-application/config.json
The config.json file defines an array of requests to be scheduled. Each request fully defines the event to be carried out and the schedule to be followed. The three main elements of a request are the class, the command, and the schedule.
class : Must be one of shell | transition The 'shell' class is used to trigger an operating system call, such as a program or a shell script. The 'transition' class is used to trigger a platform device transition.
command : The command is a JSON object which defines the actual instruction to be carried out. It may contain these fields:
schedule : The schedule is a JSON object which defines the time period or sun position at which to trigger the command. Time periods are specified in cron-like fashion and conform to crontab syntax, with the addition of seconds. Examples of sun position are sunrise, dusk, or noon, and take precedence over any time-of-day specification (hours/minutes/seconds).
"schedule": {
"second": "*",
"minute": "*",
"hour": "*",
"day_of_month": "*",
"month": "*",
"day_of_week": "*"
}
If all time period commands are wildcards, the command is triggered every second of every day.
Note that any time period not specified defaults to a wildcard. In fact, if the schedule object is completely omitted, that is equivalent to the above definition with all wildcards defined.
"schedule": {
"second": "0",
"minute": "15",
"day_of_month": "10,20",
"month": "2-3"
}
The command will be triggered after 14:59 minutes after the top of every hour on the 10th and 20th of March and April (note that only the day of month is not zero-based). If the second were not specified to be 0, then the command would be triggered every second during the 14 minute.
NOTE: If both day_of_month and day_of_week are defined and not wildcard, then precedence is given to day_of_week.
Here is an example of a valid sun position object definition:
"sun": {
"position": "nauticalDusk",
"latitude": 32.949009,
"longitude": -105.140349
}
Combining the schedule and sun definitions, the following will time an event to occur every Sunday evening at astronomical dusk:
"schedule": {
"day_of_week": "6",
"sun": {
"position": "astronomicalDusk",
"latitude": 35.78,
"longitude": -78.649999
}
}
Putting it all together then, a valid example config file looks like:
{
"requests": [
{
"class": "transition",
"command": {
"execute": "light-switch",
"arguments": ["high"],
"server": "bldg1",
"device_name": "south-flood",
},
"schedule": {
"sun": {
"position": "dusk",
"latitude": 35.78,
"longitude": -78.649999
}
}
},
{
"class": "transition",
"command": {
"execute": "light-switch",
"arguments": ["low"],
"server": "bldg1",
"device_name": "south-flood",
},
"schedule": {
"sun": {
"position": "dawn",
"latitude": 35.78,
"longitude": -78.649999
}
}
},
{
"class": "shell",
"command" : {
"execute": "mysqldump",
"arguments": ["--dump-date", "station", "> /home/systems/dbdumps"]
},
"schedule": {
"second": "0",
"minute": "0",
"hour": "2",
}
}
]
}
This timer configuration will switch on the south flood light on building 1 at dusk and then off at dawn. It will also save the mysql station database every night at 2AM.
Copyright © 2018 Agilatech®. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.