Custom Object Example: Recurring Alarm

In this example, when an alarm arrives, the Platform check if the alarm has occurred more than two times in the last five hours.

Name: Historical Alarm Object

Type: Alarm Rule

Description: When an alarm arrives, check if it has occurred more than 2 times in past 5 hours. To use this code for your own purposes, change the name of the alarm in finder.setAlarmName (be sure to enclose the name in double quotation marks). Then, change the number of hours from 5 to the desired number of hours (in Date dateBefore - (1000*60*60*5)) and the number of occurrences from 2 to the desired number of occurrences in if (historyAlarmList.size()>2). These changes are also highlighted in the source code listing below.

Source Code:


import com.axeda.drm.sdk.Context;

import com.axeda.drm.sdk.data.Alarm;

import com.axeda.drm.sdk.data.AlarmEntry;

import com.axeda.drm.sdk.data.HistoricalAlarmFinder;

import com.axeda.drm.sdk.device.Device;

import com.axeda.common.sdk.jdbc.DateQuery;

 

HistoricalAlarmFinder finder = new HistoricalAlarmFinder(Context.create());

Date dateBefore = new Date(new Date().getTime() - (1000*60*60*5));

finder.setAlarmName("TestAlarmObject");

finder.setDate(DateQuery.after(dateBefore));

List historyAlarmList = finder.findAll();

if (historyAlarmList.size()>2)

{

return true;

}

return false;

 

Parameters: None