Python Sample Code
The following is an complete example of how to use all of the functionality of Zeus API in Python.
# 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", or the domain name
# - If you want the client connect to a secure server (SSL), the SSL parameter must be True
from ZeusAPI import *
import datetime
from datetime import timedelta
# Get your yourAuthAccount and yourAuthpass by logging into ZeusWeb and going to api_credentials.html
client = Client("IP of the Server", "Port", False, "yourAuthAccount", "yourPassword", "yourAuthpass")
# We check that the object creation was correct.
if client.IsCreated() == False :
print(client.GetZeusApiLastError())
exit()
# Gets historian of selected channels (0, 1) of station "MyStation" since yesterday until now
myHistorical = client.GetHistorical("MyStation", datetime.datetime.now() - datetime.timedelta(days=1), datetime.datetime.now(), [0,1])
if myHistorical == None :
print(client.GetZeusApiLastError())
else :
for element in myHistorical :
print("DATE: " + element["DateOfRecord"].strftime('%d-%m-%Y %H:%M:%S') + " REASON: " + element["Reason"] + " CHANNEL_ID: " + str(element["ChannelID"]) + " VALUE: " + str(element["Value"]))
# Gets the real time values / last known values of the station "MyStation"
mylastknownvalues = client.GetLastKnownValues("MyStation")
if mylastknownvalues == None :
print(client.GetZeusApiLastError())
else :
mylastknownvalues["values"]["0"] = 52.5
mylastknownvalues["values"]["1"] = 40.3
# Uploads the changed values to the Server
if client.SetLastKnownValues("MyStation", LastKnownValues(mylastknownvalues["lastConnectionTime"], mylastknownvalues["RSSI"], mylastknownvalues["PowerSupply"], mylastknownvalues["values"])) :
print(client.GetZeusApiLastError())
# Gets alarms of all stations that user can see, since yesterday until now
myAlarm = client.GetAlarm(datetime.datetime.now() - datetime.timedelta(days=1), datetime.datetime.now())
if myAlarm == None :
print(client.GetZeusApiLastError())
else :
for element in myAlarm :
print("DATE: " + element["DateOfRecord"].strftime('%d-%m-%Y %H:%M:%S') + " STATION: " + element["StationID"] + " REASON: " + str(element["Reason"]) + " CHANNEL_ID: " + str(element["ChannelID"]) + " TEXT: " + element["AlarmText"])
# Upload historians for station "MyStation"
if client.SetHistorical("MyStation", [Historical(datetime.datetime.now(), 1, "0", 15.5), Historical(datetime.datetime.now(), 0, "0", 10.2)]) == False :
print(client.GetZeusApiLastError())
# Upload alarms for station "MyStation"
if client.SetAlarms([Alarms("MyStation", datetime.datetime.now(), 1, 21, "This is my high level alarm", ""), Alarms("MyStation", datetime.datetime.now(), 3, 22, "This is my restored alarm", "")]) == False :
print(client.GetZeusApiLastError())
# Send a message to the station "MyStation"
if client.SendMessage("MyStation", "my message") == False :
print(client.GetZeusApiLastError())
# Gets enqueued messages pending of execution on server
myMessages = client.PendingMessages()
if myMessages == None :
print(client.GetZeusApiLastError())
else :
for element in myMessages :
print("Key: " + element["Key"] + " VALUE: " + element["Value"])