add all files

This commit is contained in:
Rucus
2026-02-17 09:29:34 -06:00
parent b8c8d67c67
commit 782d203799
21925 changed files with 2433086 additions and 0 deletions

View File

@@ -0,0 +1,699 @@
//DISCLAIMER HERE//
//Script for the engine
//Not releated for v6 API. These are just the client engines to power the logic and data in the front end
//Back End Functions that loops non-stop
function defaultViewState() {
//Sets up the default configurator views
$("#textJsonEditor").show();
$("#jsonEditorContainer").hide();
$("#tagListContainer").hide();
$("#channelPanel").show();
$("#devicePanel").hide();
$("#tagPanel").hide();
$("#deleteChannel").hide();
$("#deleteDevice").hide();
$("#readProjObj").hide();
$("#useCase1Panel").hide();
$("#iotGatewayPanel").hide();
}
function Loop() {
//Checks if debug is enabled
if ($("#debugState").is(':checked')) {
debugState = true;
$("#readProjObj").show();
$('body').css('background-color', 'yellow');
} else {
debugState = false;
$("#readProjObj").hide();
$('body').css('background-color', '#4CAF50');
}
//Check if State should be connected. If debug is true, we stop the loop and dont do anything.
if (connectState && !debugState) {
if (!disconnected) {
$("#connectedTo").css("color", "green");
$(".hideAfterConnect").hide();
$("#updateConfig").hide();
var htmlString = "<li><Strong>You are now connected as : </Strong>" + userName + "</li>";
$("#connectedUserTxt").html(htmlString);
updateStatsBarServer(inputServer);
updateStatsBarChannelCount();
updateStatsDeviceCount();
readEventLog();
var tempblank = [];
if (eventArrayChanged && (eventArray.toString() != tempblank.toString())) {
var tempindex = 0;
for (var i = 0; i < eventArray.length; i++) {
if (eventArray[i].timestamp == lastKnownTime) {
tempindex = i + 1;
}
}
for (var j = tempindex; j < eventArray.length; j++) {
updateEventLog(eventArray[j].timestamp, eventArray[j].event, eventArray[j].message);
}
lastKnownTime = eventArray[eventArray.length - 1].timestamp;
}
updateProj(inputServer); //For maintaining the latest value
if (treeChanged) {
updateStatsBarServer(inputServer);
updateStatsBarChannelCount();
updateStatsDeviceCount();
treeChanged = false;
drawTree(channelList);
$('#deviceTree').on('select_node.jstree', function(e, data) {
var loMainSelected = data;
getNodeAndParent(loMainSelected);
});
}
$('#deviceTree').on('ready.jstree', function() {
$("#deviceTree").jstree("open_all");
});
//deviceTreeListener();
} else {
$("#connectedTo").css("color", "red");
$(".hideAfterConnect").show();
$("#updateConfig").show();
}
} else {
//When disconnected or in debug mode
$("#connectedTo").css("color", "red");
$(".hideAfterConnect").show();
$("#updateConfig").show();
}
}
//General Functions
function getUserInputs() {
inputServer = document.getElementById('server').value;
inputChannel = document.getElementById('channel').value;
inputChannelType = document.getElementById('channelType').value;
inputDevice = document.getElementById('device').value;
inputDevID = document.getElementById('deviceId').value;
inputTag = document.getElementById('tag').value;
inputTagAddr = document.getElementById('tagAddr').value;
inputTagType = document.getElementById("tagType").value;
inputDriver = document.getElementById('channelType').value;
userName = document.getElementById('userName').value;
userPass = document.getElementById('userPass').value;
var authString = userName + ":" + userPass;
encodeAuth = btoa(authString);
}
function getNodeAndParent(loSelectedNode) {
//Gets the Node clicked
try {
var lnLevel = loSelectedNode.node.parents.length;
var lsSelectedID = loSelectedNode.node.id;
var loParent = $("#" + lsSelectedID);
var selected = loSelectedNode.node.text;
var tempList = [];
var channel;
var device;
var driver;
for (var ln = 0; ln <= lnLevel - 1; ln++) {
loParent = loParent.parent().parent();
if (loParent.children()[1] !== undefined) {
tempList.push(loParent.children()[1].text);
}
}
if (tempList.length === 0) {
//This is a channel
channel = selected;
cselected = selected;
console.log("cselected is" + cselected);
for (var i = 0; i < channelList.length; i++) {
if (channel == channelList[i].text) {
driver = channelList[i].driver;
console.log(driver);
}
}
//console.log("channel is " + channel + ", driver is " + driver);
channelSelected(channel, driver);
} else {
//This is a device
channel = tempList[0];
cselected = channel;
document.getElementById("channel").value = cselected;
driver = tempList[0].driver;
document.getElementById("channelType").value = driver;
device = selected;
dselected = selected;
document.getElementById("device").value = dselected;
console.log("cselected is" + cselected);
console.log("dselected is" + dselected);
deviceSelected(device, channel);
console.log("Getting Tags for " + device + " under " + channel);
getTags(device, channel);
}
} catch (err) {
updateLog('Error in fetching selection in tree');
}
}
//Dropdown display functions
/* When the user clicks on the button, toggle between hiding and showing the dropdown content */
function dropdown() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown menu if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.inputButton')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (var i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
//Device List Functions
function drawTree(treeObj) {
//console.log("Drawing Tree");
//console.log("Input is " + treeObj);
//Draws the Device list based on the jSON object parsed into it
//Has to destroy the tree and create a new one. There are no update function
$('#deviceTree').jstree("destroy").empty();
$('#deviceTree').jstree({
'core': {
'check_callback': true,
'data': channelList
}
});
}
function deviceTreeListener() {
}
//jSON Configurator Panel
function updateText(content) {
$("#textJsonInput").val(content);
}
//Custom Event Logger Functions
function updateLog(content, status) {
//Gets the Timestamp and inserts the content passed into the function
if (status == null) {
status = "";
}
var d = new Date(),
h = (d.getHours() < 10 ? '0' : '') + d.getHours(),
m = (d.getMinutes() < 10 ? '0' : '') + d.getMinutes();
s = (d.getSeconds() < 10 ? '0' : '') + d.getSeconds();
i = h + ':' + m + ':' + s;
//This function updates the log in the Event Log insert a row at the top of the table
var table = document.getElementById("resultsRow");
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = i;
cell2.innerHTML = content;
cell3.innerHTML = status;
}
//KSE Logger Functions
function updateEventLog(timestamp, eventType, message) {
var table = document.getElementById("eventsRow");
var row = table.insertRow(1);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
cell1.innerHTML = timestamp;
cell2.innerHTML = eventType;
cell3.innerHTML = message;
}
//Stats Bar functions
function updateStatsBarServer(inputServer) {
//Updates the Server IP
$("#connectedTo").html("<strong>Connected to &#58</strong>" + "<a href = \"http://" + inputServer + "/config\" target=\"_blank\"</a>" + inputServer + "</li>");
}
function updateStatsBarChannelCount() {
//Updates the No. of channels. The Global Variable channelCount is written into by the updateProj Function
var count = 0;
for (var i = 0; i < channelList.length; i++) {
count++;
}
$("#channelCount").html("<strong>No. of Channels &#58</strong>" + count + "</li>");
}
function updateStatsDeviceCount() {
var count = 0;
if (channelList === undefined) {
count = 0;
} else {
for (var i = 0; i < channelList.length; i++) {
count = count + channelList[i].children.length;
}
}
$("#deviceCount").html("<strong>No. of Devices &#58</strong>" + count + "</li>");
}
function readProj() {
//This function is a single read to the projObj
//Upon the sucessful callback, we update the global variables to make them universally accessible
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function() {
connectState = true;
updateLog("Server is now connected to " + inputServer, status);
},
error: function() {
connectState = false;
updateLog("Please check your connection and configuration", status);
}
});
}
function updateProj(inputServer) {
////This function is used in the Loop function to update the Global Variable projObj
//The following global variables are updated here: projObj
//Upon the sucessful callback, we update the global variables to make them universally accessible
if (connectState) {
//make sure the user wants to stay connected and avoid a situation we continue to update even when the user wants to disconnect
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function(JSON) {
//success(result,status,xhr)
projObj = JSON;
var tempList = [];
var tempObj = {};
channelCount = JSON.length;
for (var i = 0; i < channelCount; i++) {
tempObj = {};
tempObj.text = projObj[i]["common.ALLTYPES_NAME"];
tempObj.driver = projObj[i]["servermain.MULTIPLE_TYPES_DEVICE_DRIVER"];
getDevicesList(projObj[i]["common.ALLTYPES_NAME"]);
tempList[i] = tempObj;
}
var tempStr = "";
var tempStr2 = "";
for (var i = 0; i < tempList.length; i++) {
tempStr += tempList[i].text;
}
for (var i = 0; i < channelList.length; i++) {
tempStr2 += channelList[i].text;
}
if (tempStr == tempStr2) {
//we compare the list before writing again to avoid corruption of the data
//console.log("List unchanged");
} else {
channelList = tempList;
//console.log("List Updated");
treeChanged = true;
}
},
error: function(JSON, status, xhr) {
updateLog("Server is Disconnected..", xhr.statusText);
disconnected = true;
}
});
}
}
function channelSelected(channelName, driverType) {
//This function takes a server ip and returns the jSON response
//Upon the sucessful callback, we update the global variables to make them universally accessible
//Shows up the Channel Panel under Asset Creation
$(cselected).toggleClass("expanded");
$("#displayChannelPanel").addClass("active");
$("#displayDevicePanel").removeClass("active");
$("#displayTagPanel").removeClass("active");
$("#channelPanel").show();
$("#devicePanel").hide();
$("#tagPanel").hide();
$("#channel").val(channelName);
$("#channelType").val(driverType);
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function(data) {
//Updates the json Text Input and the Json Tree View
editor.set(data);
updateText(JSON.stringify(data));
console.log(data);
document.getElementById("deviceId").value = data[0]["servermain.DEVICE_ID_STRING"];
document.getElementById("device").value = data[0]["common.ALLTYPES_NAME"];
},
error: function() {}
});
}
function deviceSelected(deviceName, channelName) {
$("#displayChannelPanel").removeClass("active");
$("#displayDevicePanel").addClass("active");
$("#displayTagPanel").removeClass("active");
$("#channelPanel").hide();
$("#devicePanel").show();
$("#tagPanel").hide();
$("#deviceName").val(deviceName);
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices/' + deviceName,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function(data) {
//Updates the json Text Input and the Json Tree View
updateText(JSON.stringify(data));
editor.set(data);
$("#deviceId").val(data["servermain.DEVICE_ID_STRING"]);
$("#channelType").val(data["servermain.MULTIPLE_TYPES_DEVICE_DRIVER"]);
inputDevIDOld = data["servermain.DEVICE_ID_STRING"];
console.log(inputDevIDOld);
},
error: function() {
}
});
}
//OPERATIONS THAT GET INPUTS
function loadMdbsFile() {
//var url = string(document.getElementById("importMdbsJSON").value); //future improvement?
$("#displayText").addClass("active");
$("#displayTree").removeClass("active");
$("#displayTagList").removeClass("active");
$("#textJsonEditor").show();
$("#jsonEditorContainer").hide();
$("#tagListContainer").hide();
var url = "Modbus.txt";
var result = "";
var stringJson = "";
$.ajax({
type: 'GET',
url: url,
dataType: 'text',
success: function(data) {
result = data;
//Update text field wiht JSON from file
updateText(result);
//Parse JSON into the fields for object creation/update
inputJSON = document.getElementById('textJsonInput');
parsedJSON = JSON.parse(inputJSON.value);
//alert(parsedJSON['common.ALLTYPES_NAME']); //debug alert
inputChannel = parsedJSON['common.ALLTYPES_NAME'];
inputChannelType = parsedJSON['servermain.MULTIPLE_TYPES_DEVICE_DRIVER'];
inputDevice = parsedJSON['common.ALLTYPES_DEVNAME'];
inputDevID = parsedJSON['servermain.DEVICE_ID_STRING'];
inputTag = parsedJSON['common.ALLTYPES_TAGNAME'];
inputTagAddr = parsedJSON['servermain.TAG_ADDRESS'];
inputTagType = parsedJSON['servermain.TAG_DATA_TYPE'];
document.getElementById("channel").value = inputChannel;
document.getElementById("channelType").value = inputChannelType;
document.getElementById("device").value = inputDevice;
document.getElementById("deviceId").value = inputDevID;
document.getElementById("tag").value = inputTag;
document.getElementById("tagAddr").value = inputTagAddr;
document.getElementById("tagType").value = inputTagType;
},
});
}
function loadABFile() {
//var url = string(document.getElementById("importMdbsJSON").value); //future improvement?
$("#displayText").addClass("active");
$("#displayTree").removeClass("active");
$("#displayTagList").removeClass("active");
$("#textJsonEditor").show();
$("#jsonEditorContainer").hide();
$("#tagListContainer").hide();
var url = "AB.txt";
var result = "";
var stringJson = "";
$.ajax({
type: 'GET',
url: url,
dataType: 'text',
success: function(data) {
result = data;
//Update text field wiht JSON from file
updateText(result);
//Parse JSON into the fields for object creation/update
inputJSON = document.getElementById('textJsonInput');
parsedJSON = JSON.parse(inputJSON.value);
//alert(parsedJSON['common.ALLTYPES_NAME']); //debug alert
inputChannel = parsedJSON['common.ALLTYPES_NAME'];
inputChannelType = parsedJSON['servermain.MULTIPLE_TYPES_DEVICE_DRIVER'];
inputDevice = parsedJSON['common.ALLTYPES_DEVNAME'];
inputDevID = parsedJSON['servermain.DEVICE_ID_STRING'];
inputTag = parsedJSON['common.ALLTYPES_TAGNAME'];
inputTagAddr = parsedJSON['servermain.TAG_ADDRESS'];
inputTagType = parsedJSON['servermain.TAG_DATA_TYPE'];
document.getElementById("channel").value = inputChannel;
document.getElementById("channelType").value = inputChannelType;
document.getElementById("device").value = inputDevice;
document.getElementById("deviceId").value = inputDevID;
document.getElementById("tag").value = inputTag;
document.getElementById("tagAddr").value = inputTagAddr;
document.getElementById("tagType").value = inputTagType;
},
});
}
function getDevicesList(channelName) {
//This function takes in a Channel Name and addes the list of devices into the global object Channel List
//e.g. getDevicesList(Modbus TCP/IP);
$.ajax({
//An ajax call to the end point for the "Modbus TCP/IP"
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function(data) {
var tempList = [];
var tempDeviceModelList = [];
//Loops through the returned JSON and writes into an array of devices
for (var i = 0; i < data.length; i++) {
tempList[i] = data[i]["common.ALLTYPES_NAME"];
tempDeviceModelList[i] = data[i]["servermain.DEVICE_MODEL"];
}
// The temp list is created. E.g.{16 Bit Device,8 Bit Device}
for (var j = 0; j < channelCount; j++) {
//We now look for the obj that belongs to the channel name in channelList
if (channelList[j].text == channelName) {
//console.log(channelList[j].text + " Found");
//Trying to recreate the same format and do the comparison
var tempArray = [];
var tempObj = {};
tempObj.text = channelName;
tempObj.children = tempList;
tempObj.deviceModel = tempDeviceModelList;
tempArray[1] = tempObj;
var string1 = JSON.stringify(channelList[j].children);
var string2 = JSON.stringify(tempArray[1].children);
//Finally we can compare
if (string1 == string2) {
//Device unchanged. No need to do anything
//console.log("Device List for " + channelName + " is same");
} else {
//Device List is different. Add in the new list
//console.log("Device List for " + channelName + " is different");
channelList[j].children = tempList;
channelList[j].deviceModel = tempDeviceModelList;
//console.log("Added Children List for " + channelName);
treeChanged = true;
}
}
}
},
error: function() {
updateLog("Error getting device for " + channelName + "in getDeviceList");
}
});
}
function getChannelProperties(channelName) {
// retrieves the Channel Properies based on input
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/drivers/channels/' + channelName,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data, status, xhr) {
//console.log(xhr.responseText);
},
error: function(data, status, xhr) {
//console.log(data);
}
});
}
function getTags(deviceName, channelName) {
$("#displayTagList").addClass("active");
$("#displayText").removeClass("active");
$("#displayTree").removeClass("active");
$("#textJsonEditor").hide();
$("#jsonEditorContainer").hide();
$("#tagListContainer").show();
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices/' + deviceName + '/tags',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function(data) {
var readresultsview = "<tr align=" + 'left' + "><th>Tag Name</th><th>Address</th></tr>";
for (var i = 0; i < data.length; i++) {
readresultsview += "<td>" + data[i]["common.ALLTYPES_NAME"] + "</td><td>" + data[i]["servermain.TAG_ADDRESS"] + "</td></tr>";
}
document.getElementById("tagReadResults").innerHTML = readresultsview;
},
error: function() {}
});
}
function updateTags(deviceName, channelName) {
console.log("Refreshing Tag List");
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices/' + deviceName + '/tags',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
dataType: "json",
success: function(data) {
var readresultsview = "<tr align=" + 'left' + "><th>Tag Name</th><th>Address</th></tr>";
for (var i = 0; i < data.length; i++) {
readresultsview += "<td>" + data[i]["common.ALLTYPES_NAME"] + "</td><td>" + data[i]["servermain.TAG_ADDRESS"] + "</td></tr>";
}
document.getElementById("tagReadResults").innerHTML = readresultsview;
},
error: function() {}
});
}
//Unfortunately, we do not provide a list of drivers via the API yet. We therefore hardcoded the enumerated data. Please refer to the documentation for more information
function retreiveDeviceModel(driver, model) {
if (driver == "Modbus TCP/IP Ethernet") {
switch (model) {
case 0:
return "Modbus";
case 1:
return "Mailbox";
case 2:
return "Instromet";
case 3:
return "Roxar RFM";
case 4:
return "Fluenta FGM";
case 5:
return "Applicom";
case 6:
return "CEG";
default:
return "";
}
}
if (driver == "Simulator") {
switch (model) {
case 0:
return "16 Bit Device";
case 1:
return "8 Bit Device ";
default:
return "";
}
}
}

View File

@@ -0,0 +1,63 @@
//For storing user inputs
var inputServer; //Server IP
var inputChannel; //Channel to create
var inputChannelOld; //Channel to modify
var inputChannelType; //Channel Type or driver type
var inputDevice; //Device name
var inputDeviceOld; //Device to modify
var inputDriver; //Device Driver
var inputDevID; //Device ID (IP address)
var inputDevIDOld; //Device ID to modfiy
var inputTag; //Tag name
var inputTagAddr; //Tag address
var inputTagType; //Tag data type
var inputTagOld; //Tag name to modfiy
var inputTagAddrOld; //Tag address to modfiy
var inputTagTypeOld; //Tag data type to modfiy
var userName;
var userPass;
var encodeAuth;
//Server Information
var connectState = false;
var debugState = false;
var channelCount = 0;
var deviceCount = 0;
var tagCount = 0;
var sampleRate = 1000;
var supportedDrivers;
var disconnected = false;
//Objects for storing Project Information
var projObj;
var channelList = [];
var tagList = [];
var currentSelected = [];
var eventArray = [];
var eventArrayChanged = false;
var lastKnownTime;
//channelList contains a list of json Obj
//{ text: (Channel name)
//children: (Device array List)
//deviceModel: (Enumerations of the device driver)
//driver: (The driver the device is using)
//}
var deviceList = {};
var treeChanged = false;
var func1 = 0;
var func2 = 0;
var func3 = 0;
//DeviceList variables
var dselected;
var cselected;
var tselected;
var taddrselected;
//jsConfig Objects
var container = document.getElementById('jsoneditor');
var options = {};
var editor = new JSONEditor(container, options);

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,307 @@
//DISCLAIMER HERE//
//Main Execution
$(document).ready(function() {
console.log("initial state is " + connectState);
defaultViewState();
updateLog("v6 Webclient is loaded.");
//Non Stop Events
setInterval("Loop();", sampleRate);
//Listeners
$("#updateConfig").click(function() {
getUserInputs();
updateLog("Connecting as " + userName + "...");
readProj();
$("#deleteChannel").show();
$("#deleteDevice").show();
});
//Main Nav
$("#v6Configurator").click(function() {
$("#v6Configurator").addClass("active");
$("#useCase1").removeClass("active");
$("#iotGateway").removeClass("active");
$("#configurator").show();
$("#deviceList").show();
$("#jsonObject").show();
$("#useCase1Panel").hide();
$("#iotGatewayPanel").hide();
});
$("#useCase1").click(function() {
$("#v6Configurator").removeClass("active");
$("#useCase1").addClass("active");
$("#iotGateway").removeClass("active");
$("#configurator").hide();
$("#deviceList").show();
$("#jsonObject").show();
$("#useCase1Panel").show();
$("#iotGatewayPanel").hide();
});
$("#iotGateway").click(function() {
$("#v6Configurator").removeClass("active");
$("#useCase1").removeClass("active");
$("#iotGateway").addClass("active");
$("#configurator").hide();
$("#deviceList").show();
$("#jsonObject").show();
$("#useCase1Panel").hide();
$("#iotGatewayPanel").show();
});
//ZE BUTTONS
$("#createCh").click(function() {
if (connectState) {
getUserInputs();
updateLog("Creating a " + inputChannelType + " named " + inputChannel);
createChannel(inputServer, inputChannelType, inputChannel);
} else {
updateLog("Please connect the server first");
}
});
$("#createDevice").click(function() {
if (connectState) {
getUserInputs();
updateLog("Creating " + inputDevice + " with ID " + inputDevID + "for driver" + inputDriver);
createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver);
} else {
updateLog("Please connect the server first");
}
});
$("#createTag").click(function() {
if (connectState) {
getUserInputs();
updateLog("Creating " + inputTag + " with address " + inputTagAddr);
createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr);
getTags(inputDevice, inputChannel);
} else {
updateLog("Please connect the server first");
}
});
$("#readProjObj").click(function() {
updateLog("Reading ProjObj...");
if (projObj === null) {
updateLog("ProjObj is not Loaded. Please connect to Server first");
// your code here.
} else {
editor.set(projObj);
var stringJson = JSON.stringify(projObj, null, 2);
//Stringify it and update into the text area
updateText(stringJson);
updateLog("Please view in in the editor panel");
}
});
$("#getJSON").click(function() {
updateLog("Getting the Obj");
var textInput = document.getElementById("textJsonInput").value;
var jsonInput = JSON.parse(textInput);
console.log(jsonInput);
setJson(jsonInput);
});
//Nav Menus
$("#displayText").click(function() {
//Text for the Json Object Viewer
$("#displayText").addClass("active");
$("#displayTree").removeClass("active");
$("#displayTagList").removeClass("active");
$("#textJsonEditor").show();
$("#jsonEditorContainer").hide();
$("#tagListContainer").hide();
});
$("#displayTree").click(function() {
//jsTree for the Json object view
$("#displayTree").addClass("active");
$("#displayText").removeClass("active");
$("#displayTagList").removeClass("active");
$("#textJsonEditor").hide();
$("#jsonEditorContainer").show();
$("#tagListContainer").hide();
});
$("#displayTagList").click(function() {
$("#displayTagList").addClass("active");
$("#displayText").removeClass("active");
$("#displayTree").removeClass("active");
$("#textJsonEditor").hide();
$("#jsonEditorContainer").hide();
$("#tagListContainer").show();
});
$("#displayChannelPanel").click(function() {
$("#displayChannelPanel").addClass("active");
$("#displayDevicePanel").removeClass("active");
$("#displayTagPanel").removeClass("active");
$("#channelPanel").show();
$("#devicePanel").hide();
$("#tagPanel").hide();
});
$("#displayDevicePanel").click(function() {
$("#displayChannelPanel").removeClass("active");
$("#displayDevicePanel").addClass("active");
$("#displayTagPanel").removeClass("active");
$("#channelPanel").hide();
$("#devicePanel").show();
$("#tagPanel").hide();
});
$("#displayTagPanel").click(function() {
$("#displayChannelPanel").removeClass("active");
$("#displayDevicePanel").removeClass("active");
$("#displayTagPanel").addClass("active");
$("#channelPanel").hide();
$("#devicePanel").hide();
$("#tagPanel").show();
});
$("#drawTree").click(function() {
console.log(channelList);
drawTree(channelList);
});
$("#createDeviceTree").click(function() {
addChild();
});
$("#deleteChannel").click(function() {
delChannel(cselected);
});
$("#deleteDevice").click(function() {
delDevice(dselected, cselected);
});
$('#deleteTag').click(function() {
delTag(dselected, cselected, tselected);
updateTags(dselected, cselected);
});
$("#importMdbsJSON").click(function() {
updateLog("Loading file...");
$('input[type=file]').trigger('click');
loadMdbsFile();
updateLog("File loaded successfully, click the Create button.");
});
$("#importABJSON").click(function() {
updateLog("Loading file...");
$('input[type=file]').trigger('click');
loadABFile();
updateLog("File loaded successfully, click the Create button.");
});
$("#modCh").click(function() {
updateLog("Attempting to modify object for " + cselected);
modChannel(cselected);
});
$("#modDev").click(function() {
updateLog("Attempting to modify object for " + dselected);
modDevice(dselected);
});
$("#modTag").click(function() {
updateLog("Attempting to modify object for " + tselected);
modTag(tselected, taddrselected);
});
$("#createAll").click(function() {
updateLog("Attempting to create all objects in template");
if (connectState) {
getUserInputs();
//createChannel(inputServer, inputChannelType, inputChannel);
//getUserInputs();
func1 = createChannel(inputServer, inputChannelType, inputChannel);
func2 = createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver);
func3 = createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr);
$when(func1).done($when(func2).done(func3));
getTags(inputDevice, inputChannel);
} else {
updateLog("Please connect the server first");
}
});
$('#tagReadResults').on('click', 'tr', function() {
$("#displayChannelPanel").removeClass("active");
$("#displayDevicePanel").removeClass("active");
$("#displayTagPanel").addClass("active");
$("#channelPanel").hide();
$("#devicePanel").hide();
$("#tagPanel").show();
var td = this.cells[0]; // the first <td>
var td2 = this.cells[1];
var td3 = this.cells[2];
tselected = $(td).text();
taddrselected = $(td2).text();
//ttypeselected = $(td3).text();
//updateLog(taddrselected + ttypeselected);
$("#tag").val(tselected);
$("#tagAddr").val(taddrselected);
if (tselected != "Tag Name") {
updateLog("Tag " + tselected + " is selected from " + dselected + " under " + cselected);
var selected = $(this).hasClass("highlight");
$("#tagReadResults tr").removeClass("highlight");
if (!selected)
$(this).addClass("highlight");
}
getUserInputs();
inputTagTypeOld = inputTagType; //Tag data type to modfiy
});
//IoT Gateway
$("#createRESTServer").click(function() {
var restnameInput = document.getElementById("restServerName");
var restport = document.getElementById("restServerPort");
console.log(restnameInput.value, restport.value);
createRestServer(restnameInput.value, restport.value);
});
$("#addtoIoTGateway").click(function() {
var tagAddrString = cselected + '.' + dselected + '.' + tselected;
var restnameInput = document.getElementById("restServerName");
console.log("Adding " + tagAddrString + ' to ' + restnameInput.value);
addRestTag(restnameInput.value, tagAddrString);
});
$("#readTag").click(function() {
var tagAddrString = cselected + '.' + dselected + '.' + tselected;
var readNonStop = document.getElementById("readNonStop").checked;
var restport = document.getElementById("restServerPort");
var readInterval = setInterval(readLoop, 1000);
function readLoop() {
console.log(readNonStop);
readNonStop = document.getElementById("readNonStop").checked;
if (readNonStop) {
readTag(tagAddrString, restport.value);
} else {
readTag(tagAddrString, restport.value);
clearInterval(readInterval);
}
}
});
$("#deleteRESTServer").click(function() {
var restnameInput = document.getElementById("restServerName");
deleteRestServer(restnameInput.value);
});
}); /* End of Ready*/

View File

@@ -0,0 +1,115 @@
$("#delAll").click(function(){
deleteAllbutton();
});
function deleteAllbutton(){
var x;
if (confirm("Are you sure you want to delete all?") === true) {
delAllChannels();
} else {
alert("Aborted");
}
}
$("#demoProj").click(function(){
//Creates the Channels, Devices, Tags
deleteAllbutton();
//createChannel(inputServer, inputChannelType, inputChannel)
for(var i=1; i<3; i++){
var chName = "Channel"+i;
createChannel(inputServer, "Simulator", chName);
}
createChannel(inputServer, "Modbus TCP/IP Ethernet", "Modbus");
//createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver)
createDevice(inputServer, "Modbus", "127.0.0.1.1", "Slave 1", "Modbus TCP/IP Ethernet");
createDevice(inputServer, "Modbus", "127.0.0.1.2", "Slave 2", "Modbus TCP/IP Ethernet");
createDevice(inputServer, "Channel1", "1", "Device 1", "Simulator");
createDevice(inputServer, "Channel2", "2", "Device 2", "Simulator");
//createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr)
createTag(inputServer, "Modbus", "Slave 1", "RH", "400001");
createTag(inputServer, "Modbus", "Slave 1", "Temp", "400002");
createTag(inputServer, "Modbus", "Slave 2", "RH", "400001");
createTag(inputServer, "Modbus", "Slave 2", "Temp", "400002");
createTag(inputServer, "Channel1", "Device 1", "K", "USER(1000,K)");
createTag(inputServer, "Channel1", "Device 1", "S", "USER(1000,S)");
createTag(inputServer, "Channel1", "Device 1", "E", "USER(1000,E)");
createTag(inputServer, "Channel1", "Device 1", "6", "USER(1000,6)");
createTag(inputServer, "Channel2", "Device 2", "RAMP", "RAMP (120, 35, 100, 4)");
createTag(inputServer, "Channel2", "Device 2", "RANDOM", "RANDOM (30, -20, 75)");
createTag(inputServer, "Channel2", "Device 2", "SINE", "SINE (10, -40.000000, 40.000000, 0.050000, 0)");
});
$("#templateA").click(function(){
//BMS Suite
deleteAllbutton();
//createChannel(inputServer, inputChannelType, inputChannel)
createChannel(inputServer, "Simulator", "SNMP");
createChannel(inputServer, "Simulator", "Bacnet");
createChannel(inputServer, "Modbus TCP/IP Ethernet", "Modbus");
//createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver)
createDevice(inputServer, "Modbus", "127.0.0.1.1", "Slave 1", "Modbus TCP/IP Ethernet");
createDevice(inputServer, "Modbus", "127.0.0.1.2", "Slave 2", "Modbus TCP/IP Ethernet");
createDevice(inputServer, "SNMP", "1", "UPS", "Simulator");
createDevice(inputServer, "BACNET", "2", "AHU-1-1", "Simulator");
//createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr)
createTag(inputServer, "Modbus", "Slave 1", "RH", "400001");
createTag(inputServer, "Modbus", "Slave 1", "Temp", "400002");
createTag(inputServer, "Modbus", "Slave 2", "RH", "400001");
createTag(inputServer, "Modbus", "Slave 2", "Temp", "400002");
createTag(inputServer, "SNMP", "UPS", "V1", "RANDOM (30, -200, 200)");
createTag(inputServer, "SNMP", "UPS", "V2", "RANDOM (40, -200, 240)");
createTag(inputServer, "SNMP", "UPS", "V3", "RANDOM (50, -200, 200)");
createTag(inputServer, "Bacnet", "AHU-1-1", "AI", "SINE (10, -40.000000, 40.000000, 0.050000, 0)");
createTag(inputServer, "Bacnet", "AHU-1-1", "AO", "SINE (10, -40.000000, 40.000000, 0.050000, 0)");
createTag(inputServer, "Bacnet", "AHU-1-1", "TEMP1", "SINE (10, -40.000000, 40.000000, 0.050000, 0)");
});
$("#templateB").click(function(){
//Manufacturing Suite
deleteAllbutton();
//createChannel(inputServer, inputChannelType, inputChannel)
createChannel(inputServer, "Simulator", "Allen Bradley");
createChannel(inputServer, "Simulator", "Siemens");
createChannel(inputServer, "Simulator", "Omron");
createChannel(inputServer, "Simulator", "Mitsubishi");
createChannel(inputServer, "Modbus TCP/IP Ethernet", "Modbus");
//createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver)
createDevice(inputServer, "Modbus", "127.0.0.1.1", "Slave 1", "Modbus TCP/IP Ethernet");
createDevice(inputServer, "Modbus", "127.0.0.1.2", "Slave 2", "Modbus TCP/IP Ethernet");
createDevice(inputServer, "Allen Bradley", "1", "ControlLogix 5580", "Simulator");
createDevice(inputServer, "Siemens", "2", "S7-1500", "Simulator");
createDevice(inputServer, "Omron", "2", "NJ Series", "Simulator");
createDevice(inputServer, "Mitsubishi", "2", "Q Series", "Simulator");
//createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr)
createTag(inputServer, "Modbus", "Slave 1", "RH", "400001");
createTag(inputServer, "Modbus", "Slave 1", "Temp", "400002");
createTag(inputServer, "Modbus", "Slave 2", "RH", "400001");
createTag(inputServer, "Modbus", "Slave 2", "Temp", "400002");
createTag(inputServer, "Allen Bradley", "ControlLogix 5580", "T4:0", "RANDOM (30, -200, 200)");
createTag(inputServer, "Allen Bradley", "ControlLogix 5580", "CS1:1", "RANDOM (30, -200, 200)");
createTag(inputServer, "Allen Bradley", "ControlLogix 5580", "CS1:2", "RANDOM (30, -200, 200)");
createTag(inputServer, "Siemens", "S7-1500", "B0", "RANDOM (40, -200, 240)");
createTag(inputServer, "Siemens", "S7-1500", "B1", "RANDOM (40, -200, 240)");
createTag(inputServer, "Omron", "NJ Series", "MyArray[1,0]", "RANDOM (50, -200, 200)");
});

View File

@@ -0,0 +1,401 @@
//DISCLAIMER HERE//
//This sample demonstrates the calls for each of the end point for Create, Delete, Modify Operations
//Note that this code is not recommended for production due to the security reasons. For production, please use HTTPS with the relevant CA certs as well as CORS setup accordingly. Do consider the use of our OPC UA Tunnel together with a DMZ PC for systems that are exposed to the internet. Consult your IT team for more information.
//CREATE OPERATIONS - v6
//The create channel function takes in the inputServer (IP address), Channel Type and Channel Name to create the channel
function createChannel(inputServer, inputChannelType, inputChannel) {
for (var i = 0; i < channelList.length; i++) {
if (inputChannel == channelList[i]) {
updateLog("Channel of the same name already exist.");
}
}
updateLog("Creating a " + inputChannelType + " named " + inputChannel);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/channels/',
data: '{"servermain.MULTIPLE_TYPES_DEVICE_DRIVER": "' + inputChannelType + '","common.ALLTYPES_NAME":"' + inputChannel + '"}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function() {
updateLog("Channel " + inputChannel + " created.", status);
funcdone = 1;
},
error: function() {
updateLog("Channel " + inputChannel + " failed.", status);
funcdone = 0;
}
});
}
//The create Device function allows you to take in the inputServer (IP address), inputChannel (Channel Name), input DevID (Device ID), inputDevice (Device Name), inputDriver (Driver Type) to create a tag
function createDevice(inputServer, inputChannel, inputDevID, inputDevice, inputDriver) {
updateLog("Creating " + inputDevice + " with ID " + inputDevID + " for driver " + inputDriver);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + '/devices',
data: '{"common.ALLTYPES_NAME":"' + inputDevice + '","servermain.DEVICE_MODEL":0,"servermain.DEVICE_ID_STRING": "' + inputDevID + '","servermain.DEVICE_CHANNEL_ASSIGNMENT":"' + inputChannel + '","servermain.MULTIPLE_TYPES_DEVICE_DRIVER":"' + inputDriver + '"}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, status) {
updateLog(inputDevice + " created under " + inputChannel, status);
funcdone = 2;
},
error: function(JSON, status) {
updateLog("Creation of " + inputDevice + " failed.", status);
funcdone = 0;
}
});
}
//The create Tag function allows you to take in the inputServer (IP address), inputChannel (Channel Name), input Device (Device Name), inputTag (Tag Name), inputTagAddr (Tag Adress) to create a device
function createTag(inputServer, inputChannel, inputDevice, inputTag, inputTagAddr) {
console.log(inputDevice);
console.log(inputTag + inputTagAddr);
updateLog("Creating " + inputTag + " with address " + inputTagAddr);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + '/devices/' + inputDevice + '/tags',
data: '{"common.ALLTYPES_NAME":"' + inputTag + '","servermain.TAG_ADDRESS":"' + inputTagAddr + '","servermain.TAG_DATA_TYPE":' + inputTagType + '}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, status, xhr) {
updateLog(inputTag + " created under " + inputDevice, status);
updateTags(dselected, cselected);
//console.log(d);
},
error: function(JSON, status, xhr) {
updateLog("Creation of " + inputTag + " failed.", status);
//console.log(d);
}
});
}
//DELETE OPERATIONS - v6
//Deletes all channel. We update he log and loop through the global variable to delete all the channels one by one
function delAllChannels() {
var oldList = [];
oldList = channelList;
console.log(oldList);
updateLog("Deleting everything...");
for (var i = 0; i < oldList.length; i++) {
$.ajax({
type: 'DELETE',
url: 'http://' + inputServer + '/config/v1/project/channels/' + oldList[i].text,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data, status) {},
error: function(data, status) {}
});
}
}
//Deletes a single channel
//Takes in the channel name and deletes it
function delChannel(channelName) {
updateLog("Deleting " + channelName);
$.ajax({
type: 'DELETE',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data, status) {
updateLog("Delete Channel Success", status);
},
error: function(data, status) {
updateLog("Delete Channel Fail", status);
}
});
}
//Delete an device. We take in the device Name and channel Name to delete it
function delDevice(deviceName, channelName) {
updateLog("Deleting " + device + "under Channel Name" + channelName);
$.ajax({
type: 'DELETE',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices/' + deviceName,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data, status) {
updateLog("Delete Device Success", status);
},
error: function(data, status) {
updateLog("Delete Device Fail", status);
}
});
}
//Deletes a tag. We take in the device Name, Channel Name, Tag Name to delete.
function delTag(deviceName, channelName, tagName) {
updateLog("Deleting Tag " + tagName + " from Device " + deviceName + " under " + channelName);
$.ajax({
type: 'DELETE',
url: 'http://' + inputServer + '/config/v1/project/channels/' + channelName + '/devices/' + deviceName + '/tags/' + tagName,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data, status) {
updateLog("Delete Tag Success", status);
updateTags(dselected, cselected);
},
error: function(data, status) {
updateLog("Delete Tag Fail", status);
}
});
}
//MODIFYING OPERATIONS - v6
//Detects changes made in the text field and updates the existing object defined in the Asset tab accordingly
//Stores existing object data
function modChannel(cselected) {
inputChannelOld = cselected;
inputChannel = document.getElementById("channel").value;
if (inputChannelOld != inputChannel) {
updateLog('Updating Channel name to ' + inputChannel); //debug alert
$.ajax({
type: 'PUT',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannelOld,
data: '{"common.ALLTYPES_NAME":"' + inputChannel + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, xhr, d) {
treeChanged = true;
console.log(d);
updateLog("Channel name changed to " + inputChannel);
},
error: function(JSON, xhr, d) {
console.log(d);
updateLog("Channel name update failed, check your settings.");
}
});
} else {
updateLog("Channel updates failed, remember to select the Channel you wish to modify from the tree panel on the left");
}
}
//Detects changes made in the text field and updates the existing object defined in the Asset tab accordingly
//Stores existing object data
function modDevice(dselected) {
inputDeviceOld = dselected;
inputDevice = document.getElementById("device").value;
inputDevID = document.getElementById("deviceId").value;
inputChannel = document.getElementById("channel").value;
if (inputDeviceOld != inputDevice && inputDevIDOld != inputDevID) {
updateLog('Error - please only update one property at a time.'); //debug alert
} else {
if (inputDeviceOld != inputDevice) {
updateLog('Updating Device name to ' + inputDevice); //debug alert
$.ajax({
type: 'PUT',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + "/devices/" + inputDeviceOld,
data: '{"common.ALLTYPES_NAME":"' + inputDevice + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, xhr, d) {
treeChanged = true;
console.log(d);
updateLog("Device name changed to " + inputDevice);
},
error: function(JSON, xhr, d) {
console.log(d);
updateLog("Device updates failed, remember to select the Device you wish to modify from the tree panel on the left");
}
});
}
if (inputDevIDOld != inputDevID) {
updateLog('Updating Device ID to ' + inputDevID); //debug alert
$.ajax({
type: 'PUT',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + "/devices/" + inputDeviceOld,
data: '{"servermain.DEVICE_ID_STRING":"' + inputDevID + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, xhr, d) {
treeChanged = true;
console.log(d);
updateLog("Device ID changed to " + inputDevID);
},
error: function(JSON, xhr, d) {
console.log(d);
updateLog("Device updates failed, remember to select the Device you wish to modify from the tree panel on the left");
}
});
}
}
}
//Detects changes made in the text field and updates the existing object defined in the Asset tab accordingly
//Stores existing object data
function modTag(tselected, taddrselected) {
inputTagOld = tselected; //Tag name to modfiy
inputTag = document.getElementById("tag").value; //Get new Tag
inputTagAddrOld = taddrselected;
inputTagAddr = document.getElementById("tagAddr").value; //Tag address to modfiy
inputTagType = document.getElementById("tagType").value; //Tag data type to modfiy
inputDevice = document.getElementById("device").value;
inputChannel = document.getElementById("channel").value;
if (inputTagOld != inputTag) {
updateLog('Updating Tag name to ' + inputTag); //debug alert
$.ajax({
type: 'PUT',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + "/devices/" + inputDevice + "/tags/" + inputTagOld,
data: '{"common.ALLTYPES_NAME":"' + inputTag + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, xhr, d) {
updateLog("Tag name changed to " + inputTag);
updateTags(dselected, cselected);
},
error: function(JSON, xhr, d) {
console.log(d);
//updateLog("Tag updates failed, remember to select the Tag you wish to modify from the tag panel on the right");
}
});
}
if (inputTagAddrOld != inputTagAddr) {
updateLog('Updating Tag Address to ' + inputTagAddr); //debug alert
$.ajax({
type: 'PUT',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + "/devices/" + inputDevice + "/tags/" + inputTagOld,
data: '{"servermain.TAG_ADDRESS":"' + inputTagAddr + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, xhr, d) {
updateLog("Tag Address changed to " + inputTagAddr);
updateTags(dselected, cselected);
},
error: function(JSON, xhr, d) {
console.log(d);
//updateLog("Tag updates failed, remember to select the Tag you wish to modify from the tag panel on the right");
}
});
}
if (inputTagTypeOld != inputTagType) {
updateLog('Updating Tag Data Type to ' + inputTagType); //debug alert
$.ajax({
type: 'PUT',
url: 'http://' + inputServer + '/config/v1/project/channels/' + inputChannel + "/devices/" + inputDevice + "/tags/" + inputTagOld,
data: '{"servermain.TAG_DATA_TYPE":"' + inputTagType + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(JSON, xhr, d) {
treeChanged = true;
console.log(d);
updateLog("Tag Data Type changed to " + inputTagType);
},
error: function(JSON, xhr, d) {
console.log(d);
updateLog("Check your tag settings, ensure this data type exists");
// updateLog("Tag updates failed, remember to select the Tag you wish to modify from the tag panel on the right");
}
});
} else {
updateLog("Tag updates failed, remember to select the Tag you wish to modify from the tag panel on the right");
}
}
//MISC FUNCITONS BUT RELEVANT TO V6
//Function updates and writes JSON object into Server to load the preconfigured JSON
function setJson(jsonObj) {
$.ajax({
type: 'PUT',
url: inputServer + '/config/v1/project/channels/' + inputChannel,
//Removed .value as we have a global varibale storing it
data: '{"common.ALLTYPES_NAME":"' + jsonObj['common.ALLTYPES_NAME'] + '","Force_Update": true}',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(d) {
console.log(d);
},
error: function() {
console.log(d);
}
});
}

View File

@@ -0,0 +1,145 @@
//In v6, we introduced the following key addition to the Common API.
//- Addition of Tags to IoT Gateway
// - Config API
// The following codes are usable only for 6.1 and above
//Function for event Log.
function readEventLog() {
$.ajax({
type: 'GET',
url: 'http://' + inputServer + '/config/v1/event_log?limit=1000',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data) {
//We send HTTP request at 1s rate. In one min, there will be 100 security only event
var tempArray = [];
for (var i = 0; i < data.length; i++) {
if (data[i].event != 'Security') {
tempArray.push(data[i]);
}
}
if (eventArray.toString() != tempArray.toString()) {
eventArray = tempArray;
console.log("EventArray Changed");
eventArrayChanged = true;
}
},
error: function(data) {
updateLog("Error retrieving KSE log");
}
});
}
function createRestServer(serverName, port) {
port = parseInt(port);
var tempdata = {
"common.ALLTYPES_NAME": serverName,
"iot_gateway.AGENTTYPES_TYPE": "REST Server",
"iot_gateway.REST_SERVER_ALLOW_ANONYMOUS_LOGIN": true,
"iot_gateway.REST_SERVER_CORS_ALLOWED_ORIGINS": "*",
"iot_gateway.REST_SERVER_ENABLE_WRITE_ENDPOINT": true,
"iot_gateway.REST_SERVER_NETWORK_ADAPTER": "Localhost only",
"iot_gateway.REST_SERVER_PORT_NUMBER": port,
"iot_gateway.REST_SERVER_USE_HTTPS": false
};
tempdata = JSON.stringify(tempdata);
console.log(tempdata);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/_iot_gateway/rest_servers',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
data: tempdata,
success: function() {
updateLog(serverName + " has been created");
},
error: function(data, status, xhr) {
console.log(data.responseJSON.message);
updateLog(data.responseJSON.message);
}
});
}
function deleteRestServer(serverName) {
$.ajax({
type: 'DELETE',
url: 'http://' + inputServer + '/config/v1/project/_iot_gateway/rest_servers/' + serverName,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function() {
updateLog(serverName + "deleted");
},
error: function(e) {
updateLog("Error adding item");
console.log(e);
}
});
}
function addRestTag(serverName, tagaddr) {
var tempdata = {
"iot_gateway.IOT_ITEM_SERVER_TAG": tagaddr,
};
tempdata = JSON.stringify(tempdata);
console.log(tempdata);
$.ajax({
type: 'POST',
url: 'http://' + inputServer + '/config/v1/project/_iot_gateway/rest_servers/' + serverName + '/iot_items',
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
data: tempdata,
success: function() {
updateLog(tag + " added");
},
error: function(e) {
updateLog("Error adding item");
console.log(e);
}
});
}
function readTag(tagaddr, port) {
$.ajax({
type: 'GET',
url: 'http://127.0.0.1:' + port + '/iotgateway/read?ids=' + tagaddr,
contentType: 'application/json',
xhrFields: {
withCredentials: false
},
headers: {
'Authorization': 'Basic ' + encodeAuth
},
success: function(data) {
console.log(data.readResults[0].v);
$("#tagValue").html("<p>" + data.readResults[0].v + "</p>");
},
error: function(data) {
updateLog(data.responseJSON.message);
}
});
}