|
@@ -66,15 +66,9 @@
|
|
|
<a class="selectable item" onClick="scanDevices();hideSideMenu();">
|
|
|
<i class="search icon"></i> Scan Devices
|
|
|
</a>
|
|
|
- <a class="selectable item" onClick="manualDriverConfig();">
|
|
|
- <i class="edit icon"></i> Manual Device Config
|
|
|
- </a>
|
|
|
-
|
|
|
- <a class="selectable item">
|
|
|
- <i class="object group icon"></i> Create Action Group
|
|
|
- </a>
|
|
|
+
|
|
|
<div class="bottom item">
|
|
|
- CopyRight ArOZ Online Project 2021
|
|
|
+ CopyRight ArozOS Project 2021
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
@@ -183,41 +177,18 @@ var currentlyViewingDevices = "";
|
|
|
var uselocal = false; //Use Local as command sender or use Host as command sender
|
|
|
var username = $("#data_session_username").text().trim();
|
|
|
//ao_module Float Window functions
|
|
|
-ao_module_setWindowIcon("home");
|
|
|
-ao_module_setWindowTitle("Home Dynamic Panel");
|
|
|
-ao_module_setGlassEffectMode();
|
|
|
+ao_module_setWindowTitle("IoT Hub");
|
|
|
ao_module_setWindowSize(465,730,true);
|
|
|
if (!ao_module_virtualDesktop){
|
|
|
$("body").css("background-color","white");
|
|
|
}
|
|
|
|
|
|
-var localSetting = ao_module_getStorage("hds","local");
|
|
|
-if ( localSetting !== undefined && localSetting !== null && localSetting != ""){
|
|
|
- uselocal = (localSetting == "true");
|
|
|
-}
|
|
|
-
|
|
|
-if (uselocal){
|
|
|
- $('#outdoor').prop('checked', false);
|
|
|
-}else{
|
|
|
- $('#outdoor').prop('checked', true);
|
|
|
-}
|
|
|
-
|
|
|
//Initiate the page content
|
|
|
loadDevList();
|
|
|
|
|
|
-$('#outdoor').change(function() {
|
|
|
- if(this.checked){
|
|
|
- ao_module_saveStorage("hds","local","false");
|
|
|
- uselocal = false;
|
|
|
- }else{
|
|
|
- ao_module_saveStorage("hds","local","true");
|
|
|
- uselocal = true;
|
|
|
- }
|
|
|
-});
|
|
|
|
|
|
function inputbox(message, placeholder = ""){
|
|
|
var input = prompt(message, placeholder);
|
|
|
-
|
|
|
if (input != null) {
|
|
|
return input;
|
|
|
}else{
|
|
@@ -225,71 +196,11 @@ function inputbox(message, placeholder = ""){
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function addDevViaIP(){
|
|
|
- var ipaddr = inputbox("Please enter the IP Address of your device.");
|
|
|
- if (ipaddr != false){
|
|
|
- var classType = inputbox("Select the custom driver for this device. Leave empty for default.");
|
|
|
- if (classType == false){
|
|
|
- alert("Driver Type cannot be empty!");
|
|
|
- return;
|
|
|
- }
|
|
|
- $.get("manualDriverConfig.php?ipaddr=" + ipaddr + "&classType=" + classType,function(data){
|
|
|
- //Finished the adding process. Realod the list of custom devices.
|
|
|
- loadCustomDeviceList();
|
|
|
- });
|
|
|
- }else{
|
|
|
- //User cancelled the opr
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function openFolderForDev(){
|
|
|
- if (ao_module_virtualDesktop){
|
|
|
- ao_module_openPath("SystemAOB/system/iotpipe/devices/fixed");
|
|
|
- }else{
|
|
|
- window.open('../SystemAOB/functions/file_system/index.php?controlLv=2&subdir=SystemAOB/system/iotpipe/devices/fixed');
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-function loadCustomDeviceList(){
|
|
|
- $("#customDevList").html("");
|
|
|
- $.ajax("manualDriverConfig.php").done(function(data){
|
|
|
- if (data.length == 0){
|
|
|
- $("#customDevList").append('<div class="item">N/A</div>');
|
|
|
- }else{
|
|
|
- for (var i =0; i < data.length; i++){
|
|
|
- $("#customDevList").append('<div class="item">' + data[i][1] + " <br>( Config UID: " + data[i][0] + " / Driver Loader: " + data[i][2] + ")" + '</div>');
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function manualDriverConfig(){
|
|
|
- //Open manual driver configuration interface
|
|
|
- loadCustomDeviceList();
|
|
|
- $("#manualDevConfig").show();
|
|
|
- hideSideMenu();
|
|
|
-}
|
|
|
|
|
|
function scanDevices(){
|
|
|
- $("#loadingMask").show();
|
|
|
- $.ajax("../SystemAOB/system/iotpipe/scandev.php").done(function(data){
|
|
|
- if (data.includes("ERROR")){
|
|
|
- alert("Scan Error! See console.log for more information.");
|
|
|
- console.log(data);
|
|
|
- }else{
|
|
|
- loadDevList();
|
|
|
- }
|
|
|
- $("#loadingMask").hide();
|
|
|
- });
|
|
|
|
|
|
}
|
|
|
|
|
|
-function setSelectNickname(object){
|
|
|
- currentlyViewingDevices = $(object).attr("uuid");
|
|
|
- setNickname();
|
|
|
-}
|
|
|
-
|
|
|
|
|
|
function hideSideMenu(){
|
|
|
ts('.right.sidebar').sidebar('hide');
|
|
@@ -321,282 +232,35 @@ function showMore(object){
|
|
|
}
|
|
|
|
|
|
|
|
|
-function action(object){
|
|
|
- var classType = $(object).parent().parent().attr("classtype");
|
|
|
- var driverFound = ($(object).parent().parent().attr("driverfound") == "true");
|
|
|
- var ip = $(object).parent().parent().attr("devip");
|
|
|
- if (driverFound){
|
|
|
- $("#actionInterface").fadeIn('fast');
|
|
|
- updateIframeSize();
|
|
|
- if ($(object).parent().parent().attr("location") == "remote"){
|
|
|
- $("#controlUI").attr("src","../SystemAOB/system/iotpipe/drivers/" + classType + "/" + classType + ".php?ip=" + ip + "&location=remote");
|
|
|
- }else{
|
|
|
- $("#controlUI").attr("src","../SystemAOB/system/iotpipe/drivers/" + classType + "/" + classType + ".php?ip=" + ip);
|
|
|
- }
|
|
|
-
|
|
|
- }else{
|
|
|
- alert("Driver not found!");
|
|
|
- }
|
|
|
-}
|
|
|
|
|
|
function loadDevList(){
|
|
|
$("#devList").html("");
|
|
|
- var template = '<div class="ts segment HDSDev" devIp="{deviceIP}" location="local">\
|
|
|
- <div class="ts grid">\
|
|
|
- <div class="four wide column"><img class="ts tiny devIcon image" src="img/system/loading.gif"></div>\
|
|
|
- <div class="twelve wide column">\
|
|
|
- <div class="ts container">\
|
|
|
- <div class="ts header">\
|
|
|
- <span class="devHeader">{deviceIP}</span>\
|
|
|
- <div class="sub devProperty header"><i class="spinner loading icon"></i> Loading</div>\
|
|
|
- </div>\
|
|
|
- </div>\
|
|
|
- </div>\
|
|
|
- </div>\
|
|
|
- <div class="controlBtn infoMount">\
|
|
|
- <button class="ts icon button" onClick="showMore(this);"><i class="notice icon"></i></button>\
|
|
|
- <button class="ts primary icon button" onClick="action(this);"><i class="external icon"></i></button>\
|
|
|
- </div>\
|
|
|
- </div>';
|
|
|
- $.ajax("loadDevList.php").done(function(data){
|
|
|
- if (data.length == 0){
|
|
|
- var nodevFound = '<div class="ts segment">\
|
|
|
- <h5 class="ts center aligned icon header">\
|
|
|
- <i class="remove icon"></i>No Device Found\
|
|
|
- <div class="sub header">No HDS based device is found in your network.<br>\
|
|
|
- Click <a href="readmore.html">here</a> to know more on how to build one yourself.</div>\
|
|
|
- </h5>\
|
|
|
- </div>';
|
|
|
- $("#devList").append(nodevFound);
|
|
|
- }else{
|
|
|
- for (var i =0; i < data.length; i++){
|
|
|
- var ip = data[i];
|
|
|
- var box = template;
|
|
|
- box = box.split("{deviceIP}").join(ip);
|
|
|
- $("#devList").append(box);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //All devices loaded. Get information about the devices.
|
|
|
- $(".HDSDev").each(function(){
|
|
|
- let ip = $(this).attr("devIp");
|
|
|
- requestInfo(ip,"info",this,uselocal);
|
|
|
- requestUUID(ip,"uuid",this,uselocal);
|
|
|
- });
|
|
|
- });
|
|
|
- $.ajax("manualDriverConfig.php").done(function(data){
|
|
|
- for(var i =0; i < data.length; i++){
|
|
|
- var uuid = data[i][0];
|
|
|
- var ipaddr = data[i][1];
|
|
|
- var classType = data[i][2];
|
|
|
- var box = template;
|
|
|
- box = box.split("{deviceIP}").join(ipaddr);
|
|
|
- box = $(box).attr("uuid",uuid);
|
|
|
- box = $(box).attr("classtype",classType);
|
|
|
- box = $(box).attr("classname",classType.split(".").join(" "));
|
|
|
- box = $(box).removeClass("HDSDev").addClass("CustomDev");
|
|
|
- box = $(box).attr("location","fixed");
|
|
|
- $("#devList").append(box);
|
|
|
- }
|
|
|
- initCustomDevUI();
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function initCustomDevUI(){
|
|
|
- $(".CustomDev").each(function(){
|
|
|
- var classType = $(this).attr("classtype");
|
|
|
- loadDevImage(classType,this);
|
|
|
- loadDevDefaultDescription(this);
|
|
|
- getNickName(this);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function loadDevDefaultDescription(object){
|
|
|
- var classType = $(object).attr("classtype");
|
|
|
- $.ajax("loadDriverProperties.php?classType=" + classType).done(function(data){
|
|
|
- $(object).find(".devProperty").text(data);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-function requestUUID(ip,subpath, object,local){
|
|
|
- if (local){
|
|
|
- //use local device as controller
|
|
|
- $.ajax({
|
|
|
- url: "http://" + ip + "/" + subpath,
|
|
|
- error: function(){
|
|
|
- //Declare offline
|
|
|
-
|
|
|
- },
|
|
|
- success: function(data){
|
|
|
- //UUID found.
|
|
|
- var uuid = data;
|
|
|
- $(object).attr("uuid",uuid);
|
|
|
- $(object).find(".devHeader").text(uuid);
|
|
|
- $(object).attr('location',"local");
|
|
|
- getNickName(object);
|
|
|
- },
|
|
|
- timeout: 5000 // sets timeout to 3 seconds
|
|
|
- });
|
|
|
- }else{
|
|
|
- //use host server as controller
|
|
|
- $.ajax({
|
|
|
- url:"../SystemAOB/system/iotpipe/extreq.php?ipa=" + ip + "&subpath=" + subpath,
|
|
|
- error: function(){
|
|
|
- //This devices might be not on the server side. Try again with client side request
|
|
|
- requestUUID(ip,subpath, object,false);
|
|
|
- },
|
|
|
- success: function(data){
|
|
|
- let filename = data;
|
|
|
- let thisObject = object;
|
|
|
- setTimeout(function(){
|
|
|
- tryGetUUID(filename,ip,subpath,thisObject,local);
|
|
|
- },1300);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function tryGetUUID(filename,ip,subpath, object,local,retryCount=0){
|
|
|
- if (retryCount > 10){
|
|
|
- //Assume offline
|
|
|
- return;
|
|
|
- }
|
|
|
- $.get("../SystemAOB/system/iotpipe/extreq.php?getreq=" + filename,function(data){
|
|
|
- if (data.includes("ERROR")){
|
|
|
- retryCount++;
|
|
|
- setTimeout(function(){
|
|
|
- tryGetUUID(filename,ip,subpath, object,local,retryCount);
|
|
|
- },1300);
|
|
|
- }else{
|
|
|
- var uuid = data;
|
|
|
- $(object).attr("uuid",uuid);
|
|
|
- $(object).attr('location',"remote");
|
|
|
- $(object).find(".devHeader").text(uuid);
|
|
|
- getNickName(object);
|
|
|
- }
|
|
|
-
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function getNickName(object){
|
|
|
- $.ajax({
|
|
|
- url: "nicknameman.php?uuid=" + $(object).attr("uuid"),
|
|
|
- success: function(data){
|
|
|
- //UUID found.
|
|
|
- if (data != false){
|
|
|
- //Replace the uuid with nickname
|
|
|
- $(object).find(".devHeader").text(data);
|
|
|
- $(object).attr("nickname",data);
|
|
|
- }
|
|
|
- },
|
|
|
- timeout: 5000 // sets timeout to 3 seconds
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function requestInfo(ip,subpath,object,local=true){
|
|
|
- //This function should work if both devices are in the same subnet. If not, something else will be done.
|
|
|
- if (local){
|
|
|
- $.ajax({
|
|
|
- url: "http://" + ip + "/" + subpath,
|
|
|
- error: function(){
|
|
|
- //Declare offline
|
|
|
- $(object).attr("className","offline");
|
|
|
- $(object).attr("classType","offline");
|
|
|
- $(object).find(".devHeader").html("<i class='remove icon'></i> Unable to Connect");
|
|
|
- $(object).find(".devProperty").html("This device is offline or its address has been changed.");
|
|
|
- $(object).find(".devIcon").attr('src',"img/system/unable2connect.png");
|
|
|
- },
|
|
|
- success: function(data){
|
|
|
- //Device in the same subnet. Try to load driver.
|
|
|
- if (data.includes("_")){
|
|
|
- var className = data.split("_")[0];
|
|
|
- var classType = data.split("_")[1];
|
|
|
- $(object).attr("className",className);
|
|
|
- $(object).attr("classType",classType);
|
|
|
- $(object).find(".devProperty").html(className);
|
|
|
- loadDevImage(classType,object);
|
|
|
- }else{
|
|
|
- console.log("[Homdynm] Error. Unknown devices class for ip address: " + $(object).attr("devIP"));
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- timeout: 5000 // sets timeout to 3 seconds
|
|
|
- });
|
|
|
- }else{
|
|
|
- //use server to get the required information.
|
|
|
- $.ajax({
|
|
|
- url:"../SystemAOB/system/iotpipe/extreq.php?ipa=" + ip + "&subpath=" + subpath,
|
|
|
- error: function(){
|
|
|
- //This devices might be not on the server side. Try again with client side request
|
|
|
- requestInfo(ip,subpath,object,true);
|
|
|
- },
|
|
|
- success: function(data){
|
|
|
- //The data should be a filename for getreq. Get it after 2 sec
|
|
|
- let filename = data;
|
|
|
- let thisip = ip;
|
|
|
- let thisObject = object;
|
|
|
- setTimeout(function(){
|
|
|
- tryGetReqInfo(filename,ip,subpath,thisObject,false);
|
|
|
- },1000);
|
|
|
-
|
|
|
- },
|
|
|
- timeout: 5000 // sets timeout to 3 seconds
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-function tryGetReqInfo(filename,ip,subpath,thisObject,local,retryCount = 0){
|
|
|
- if (retryCount > 10){
|
|
|
- //Assume offline
|
|
|
- $(thisObject).attr("className","offline");
|
|
|
- $(thisObject).attr("classType","offline");
|
|
|
- $(thisObject).find(".devHeader").html("<i class='remove icon'></i> Unable to Connect");
|
|
|
- $(thisObject).find(".devProperty").html("This device is offline or its address has been changed.");
|
|
|
- $(thisObject).find(".devIcon").attr('src',"img/system/unable2connect.png");
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- $.get("../SystemAOB/system/iotpipe/extreq.php?getreq=" + filename,function(data){
|
|
|
- console.log("[Home Dynamic] Remote returned value: " + ip + " " + data);
|
|
|
- if (data.includes("ERROR")){
|
|
|
- retryCount++;
|
|
|
- setTimeout(function(){
|
|
|
- tryGetReqInfo(filename,ip,subpath,thisObject,local,retryCount)
|
|
|
- },1000);
|
|
|
-
|
|
|
- }else{
|
|
|
- //Device found on server side. Get the information.
|
|
|
- if (data.includes(".") && data.includes("_")){
|
|
|
- //Found! Do something here
|
|
|
- var className = data.split("_")[0];
|
|
|
- var classType = data.split("_")[1];
|
|
|
- $(thisObject).attr("className",className);
|
|
|
- $(thisObject).attr("classType",classType);
|
|
|
- $(thisObject).find(".devProperty").html(className);
|
|
|
- loadDevImage(classType,thisObject);
|
|
|
- }else{
|
|
|
- //Might be trash from a random web server. Just ignore them.
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-function loadDevImage(classType,object){
|
|
|
- $.ajax("loadDevImage.php?driverClass=" + classType).done(function(data){
|
|
|
- $(object).find(".devIcon").attr('src',data[0]);
|
|
|
- $(object).attr("driverFound",data[1]);
|
|
|
- if (data[1] == false){
|
|
|
- //Driver not found. Update the icon
|
|
|
- $(object).find(".devIcon").attr('src',"img/system/driverNotFound.png");
|
|
|
+ $.get("../../../system/iot/list", function(data){
|
|
|
+ if (data.error !== undefined){
|
|
|
+ alert(data.error);
|
|
|
+ }else{
|
|
|
+ data.forEach(device => {
|
|
|
+ deviceData = encodeURIComponent(JSON.stringify(device));
|
|
|
+ $("#devList").append(`<div class="ts segment HDSDev" devicedata="${deviceData}" uuid="${device.DeviceUUID}" devIp="${device.IPAddr}" port="${device.Port}" location="local">
|
|
|
+ <div class="ts grid">
|
|
|
+ <div class="four wide column"><img class="ts tiny devIcon image" src="img/system/loading.gif"></div>
|
|
|
+ <div class="twelve wide column">
|
|
|
+ <div class="ts container">
|
|
|
+ <div class="ts header">
|
|
|
+ <span class="devHeader">${device.Name}</span>
|
|
|
+ <div class="sub devProperty header">${device.Model}</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="controlBtn infoMount">
|
|
|
+ <button class="ts icon button" onClick="showMore(this);"><i class="notice icon"></i></button>
|
|
|
+ <button class="ts primary icon button" onClick="action(this);"><i class="external icon"></i></button>
|
|
|
+ </div>
|
|
|
+ </div>`);
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
|