59 lines
2.7 KiB
Plaintext
59 lines
2.7 KiB
Plaintext
def scada_web_socket_execute():
|
|
#We read a list of tags at the beginning of the script for efficiency.
|
|
tags_to_read = system.tag.readBlocking(["Configuration/FC", "Configuration/aws"])
|
|
whid = tags_to_read[0].value
|
|
aws_config = system.util.jsonDecode(tags_to_read[1].value)
|
|
region = aws_config.get("region")
|
|
logger = system.util.getLogger("%s-Web-Socket-Execute" % (whid))
|
|
provider = "[%s_SCADA_TAG_PROVIDER]" % (whid)
|
|
AWS.create_tags.create_web_socket_tags(whid)
|
|
Latency.CreateLatencyTags.create_latency_tags(whid) # attempt to create latency lags
|
|
check_socket_closed_in_loop = AWS.wbsckt_abort.check_web_socket()
|
|
#Check the heartbeat and restart if not recieved within the specified time
|
|
check_heartbeat = AWS.heartbeat.check_heartbeat(provider, 120)
|
|
if check_heartbeat:
|
|
AWS.wbsckt_abort.close_websckt()
|
|
AWS.heartbeat.get_heartbeat(provider)
|
|
if whid == "" or whid == None:
|
|
raise ValueError("FC not configured. A project on the gateway is missing Configuration/FC id")
|
|
|
|
elif not region:
|
|
raise ValueError("No aws region configured for project")
|
|
|
|
elif check_socket_closed_in_loop:
|
|
logger.warn("Socket is closed check System/close_socket tag")
|
|
|
|
else:
|
|
description = provider + "websocket api gateway"
|
|
set_global = system.util.getGlobals().setdefault(whid,{})
|
|
running = system.util.getGlobals()[whid].get("wbsckt_running", 0)
|
|
if not running:
|
|
try:
|
|
message_handler = AWS.message_types.A2C_MessageHandler(whid)
|
|
args = [whid, provider, region, message_handler, "scada/api/endpoint"]
|
|
description = "%s-web-socket-api"
|
|
system.util.invokeAsynchronous(AWS.web_socket.web_socket_main, args, description )
|
|
except:
|
|
AWS.errors.error_handler(whid, "Web-Socket-Execute")
|
|
|
|
def update_execute():
|
|
data = AWS.message_types.Update()
|
|
data.read_messages_from_queue()
|
|
data.write_tags()
|
|
|
|
def status_execute():
|
|
tags_to_read = system.tag.readBlocking(["Configuration/FC", "System/aws_data"])
|
|
whid = tags_to_read[0].value
|
|
alarms_data = system.util.jsonDecode(tags_to_read[1].value)
|
|
# Alarm script
|
|
try:
|
|
if AWS.message_types.global_first_connect == False:
|
|
Visualisation.status.reset_alarms(whid)
|
|
Visualisation.status.global_previous_state = {}
|
|
AWS.message_types.global_first_connect = True
|
|
status = Visualisation.status.GetStatus(whid, alarms_data)
|
|
status.build_status()
|
|
status.write_data()
|
|
alarms.alarm_count.get_count(whid, alarms_data)
|
|
except:
|
|
AWS.errors.error_handler(whid, "Status-Visualisation-Script") |