Java Sample Code
The following is an complete example of how to use all of the functionality of Zeus API in Java.
Java Sample Code
// Notes: You can obtain your authaccount and authpass,
// when you have made login on ZeusWeb, going to URL: api_credentials.html
// - IP should have this format "192.168.1.1"
// - If you want the client connect to a secure server (SSL), the SSL parameter must be True
ZeusAPI myAPI = new ZeusAPI();
ZeusAPI.Client client = null;
try
{
// Get your yourAuthAccount and yourAuthpass by logging into ZeusWeb and going to api_credentials.html
client = myAPI.new Client("IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass");
}catch (Exception ex) {
System.out.println(ex.toString());
}
// Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now
List channels = new ArrayList( Arrays.asList(0,1));
Calendar startDate = Calendar.getInstance();
startDate.setTime(new Date());
startDate.add(Calendar.DATE, -1);
List myHistorical = client.GetHistorical("MyStation", startDate.getTime(), new Date(), channels);
if (myHistorical == null)
System.out.println(client.GetZeusApiLastError());
else{
for(ZeusAPI.Historical element : myHistorical){
System.out.println("DATE: " + element.DateOfRecord.toString() + " REASON: " + element.Reason + " CHANNEL_ID: " + element.ChannelID + " VALUE: " + element.Value);
}
}
// Gets the real time values / last known values of the station "MyStation"
ZeusAPI.LastKnownValues mylastknownvalues = myAPI.new LastKnownValues();
mylastknownvalues = client.GetLastKnownValues("MyStation");
if (mylastknownvalues == null)
System.out.println(client.GetZeusApiLastError());
else{
mylastknownvalues.values.replace("0", 52.5f); // Set last known value for channel Analog 0 = 52.5
mylastknownvalues.values.replace("1", 40.3f); // Set last known value for channel Analog 1 = 40.3
// Uploads the changed values to the Server
if (client.SetLastKnownValues("MyStation", mylastknownvalues) == false)
System.out.println(client.GetZeusApiLastError());
}
// Gets alarms of all stations that user can see, since yesterday until now
List myAlarms = client.GetAlarm(startDate.getTime(), new Date(), null);
if (myAlarms == null)
System.out.println(client.GetZeusApiLastError());
else
{
for (ZeusAPI.Alarms element : myAlarms)
{
System.out.println("DATE: " + element.DateOfRecord.toString() + " STATION: " + element.StationID + " REASON: " + element.Reason + " CHANNEL_ID: " + element.ChannelID + " TEXT: " + element.AlarmText);
}
}
// Upload historians for station "MyStation"
List myListHistorical = new ArrayList();
myListHistorical.add(myAPI.new Historical(new Date(), 0, "0", 10.2f));
myListHistorical.add(myAPI.new Historical(new Date(), 1, "0", 15.5f));
if (client.SetHistorical("MyStation", myListHistorical) == false)
System.out.println(client.GetZeusApiLastError());
// Upload alarms for station "MyStation"
List myListAlarms = new ArrayList();
myListAlarms.add(myAPI.new Alarms("MyStation", new Date(), 1, 21, "This is my high level alarm", ""));
myListAlarms.add(myAPI.new Alarms("MyStation", new Date(), 3, 22, "This is my restored alarm", ""));
if (client.SetAlarms(myListAlarms) == false)
System.out.println(client.GetZeusApiLastError());
// Send a message to the station "Microcom"
if (client.SendMessage("Microcom", "my message", false) == false)
System.out.println(client.GetZeusApiLastError());
// Gets enqueued messages pending of execution on server
List myMessages = client.PendingMessages();
if (myMessages == null)
System.out.println(client.GetZeusApiLastError());
else{
for (ZeusAPI.KeyValue element : myMessages)
{
System.out.println("KEY: " + element.Key + " VALUE: " + element.Value);
}
}
// Gets ProgrammableRelayPeriod of selected output (0) of station "MyStation"
List myConfigurationRelay = client.GetConfigurationRelay("MyStation", 0);
if (myConfigurationRelay == null)
System.out.println(client.GetZeusApiLastError());
else{
for (ZeusAPI.ProgrammableRelayPeriod element : myConfigurationRelay)
System.out.println("WEEKDAYS: " + element.Weekdays.toString() + " ACTIVATIONTIME: " + element.ActivationTime + " DURATION: " + element.Duration.toString());
}
// Send a Relay Configuration to the station "Microcom" to output 0
List myFrameTime = new ArrayList();
myFrameTime.add(myAPI.new ProgrammableRelayPeriod(new ArrayList( Arrays.asList("L", "M", "X")),new Date(), 5));
myFrameTime.add(myAPI.new ProgrammableRelayPeriod(new ArrayList( Arrays.asList("L", "J", "V")),new Date(), 20));
myFrameTime.add(myAPI.new ProgrammableRelayPeriod(new ArrayList( Arrays.asList("L", "M", "X", "J", "V", "S", "D")),new Date(), 120));
if (client.SetConfigurationRelay("Microcom", 0, myFrameTime) == false)
System.out.println(client.GetZeusApiLastError());
// Notes: You can obtain your authaccount and authpass,
// when you have made login on ZeusWeb, going to URL: api_credentials.html
// - IP should have this format "192.168.1.1"
// - If you want the client connect to a secure server (SSL), the SSL parameter must be True
ZeusAPI myAPI = new ZeusAPI();
ZeusAPI.Client client = null;
try
{
// Get your yourAuthAccount and yourAuthpass by logging into ZeusWeb and going to api_credentials.html
client = myAPI.new Client("IP of the Server", Port, False, "yourAuthAccount", "yourPassword", "yourAuthpass");
}catch (Exception ex) {
System.out.println(ex.toString());
}
// Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now
List channels = new ArrayList( Arrays.asList(0,1));
Calendar startDate = Calendar.getInstance();
startDate.setTime(new Date());
startDate.add(Calendar.DATE, -1);
List myHistorical = client.GetHistorical("MyStation", startDate.getTime(), new Date(), channels);
if (myHistorical == null)
System.out.println(client.GetZeusApiLastError());
else{
for(ZeusAPI.Historical element : myHistorical){
System.out.println("DATE: " + element.DateOfRecord.toString() + " REASON: " + element.Reason + " CHANNEL_ID: " + element.ChannelID + " VALUE: " + element.Value);
}
}
// Gets the real time values / last known values of the station "MyStation"
ZeusAPI.LastKnownValues mylastknownvalues = myAPI.new LastKnownValues();
mylastknownvalues = client.GetLastKnownValues("MyStation");
if (mylastknownvalues == null)
System.out.println(client.GetZeusApiLastError());
else{
mylastknownvalues.values.replace("0", 52.5f); // Set last known value for channel Analog 0 = 52.5
mylastknownvalues.values.replace("1", 40.3f); // Set last known value for channel Analog 1 = 40.3
// Uploads the changed values to the Server
if (client.SetLastKnownValues("MyStation", mylastknownvalues) == false)
System.out.println(client.GetZeusApiLastError());
}
// Gets alarms of all stations that user can see, since yesterday until now
List myAlarms = client.GetAlarm(startDate.getTime(), new Date(), null);
if (myAlarms == null)
System.out.println(client.GetZeusApiLastError());
else
{
for (ZeusAPI.Alarms element : myAlarms)
{
System.out.println("DATE: " + element.DateOfRecord.toString() + " STATION: " + element.StationID + " REASON: " + element.Reason + " CHANNEL_ID: " + element.ChannelID + " TEXT: " + element.AlarmText);
}
}
// Upload historians for station "MyStation"
List myListHistorical = new ArrayList();
myListHistorical.add(myAPI.new Historical(new Date(), 0, "0", 10.2f));
myListHistorical.add(myAPI.new Historical(new Date(), 1, "0", 15.5f));
if (client.SetHistorical("MyStation", myListHistorical) == false)
System.out.println(client.GetZeusApiLastError());
// Upload alarms for station "MyStation"
List myListAlarms = new ArrayList();
myListAlarms.add(myAPI.new Alarms("MyStation", new Date(), 1, 21, "This is my high level alarm", ""));
myListAlarms.add(myAPI.new Alarms("MyStation", new Date(), 3, 22, "This is my restored alarm", ""));
if (client.SetAlarms(myListAlarms) == false)
System.out.println(client.GetZeusApiLastError());
// Send a message to the station "Microcom"
if (client.SendMessage("Microcom", "my message", false) == false)
System.out.println(client.GetZeusApiLastError());
// Gets enqueued messages pending of execution on server
List myMessages = client.PendingMessages();
if (myMessages == null)
System.out.println(client.GetZeusApiLastError());
else{
for (ZeusAPI.KeyValue element : myMessages)
{
System.out.println("KEY: " + element.Key + " VALUE: " + element.Value);
}
}
// Gets ProgrammableRelayPeriod of selected output (0) of station "MyStation"
List myConfigurationRelay = client.GetConfigurationRelay("MyStation", 0);
if (myConfigurationRelay == null)
System.out.println(client.GetZeusApiLastError());
else{
for (ZeusAPI.ProgrammableRelayPeriod element : myConfigurationRelay)
System.out.println("WEEKDAYS: " + element.Weekdays.toString() + " ACTIVATIONTIME: " + element.ActivationTime + " DURATION: " + element.Duration.toString());
}
// Send a Relay Configuration to the station "Microcom" to output 0
List myFrameTime = new ArrayList();
myFrameTime.add(myAPI.new ProgrammableRelayPeriod(new ArrayList( Arrays.asList("L", "M", "X")),new Date(), 5));
myFrameTime.add(myAPI.new ProgrammableRelayPeriod(new ArrayList( Arrays.asList("L", "J", "V")),new Date(), 20));
myFrameTime.add(myAPI.new ProgrammableRelayPeriod(new ArrayList( Arrays.asList("L", "M", "X", "J", "V", "S", "D")),new Date(), 120));
if (client.SetConfigurationRelay("Microcom", 0, myFrameTime) == false)
System.out.println(client.GetZeusApiLastError());