diff --git a/connectcore-demo-example/index.html b/connectcore-demo-example/index.html index d60571f..052fb89 100644 --- a/connectcore-demo-example/index.html +++ b/connectcore-demo-example/index.html @@ -810,7 +810,7 @@ Digi Demo - Dashboard // Callback executed when the page loads. document.addEventListener("DOMContentLoaded", function(event) { // Start the timer that updates device status. - var statsTimer = setInterval(readDeviceStatus, 5000); + var statsTimer = setInterval(refreshDevice, 5000); }); diff --git a/connectcore-demo-example/static/js/dashboard.js b/connectcore-demo-example/static/js/dashboard.js index 30a957e..9cf6987 100644 --- a/connectcore-demo-example/static/js/dashboard.js +++ b/connectcore-demo-example/static/js/dashboard.js @@ -235,10 +235,51 @@ function processDeviceInfoResponse(response) { readDeviceStatus(); } +function refreshDevice() { + // Execute only in the dashboard page. + if (!isDashboardShowing() || device == null) + return; + + if (!deviceInitialized) { + // Hide the info popup. + showInfoPopup(false); + // Show the loading popup. + showLoadingPopup(true, MESSAGE_READING_DEVICE_INFO); + // Send request to retrieve device information. + $.post( + "http://" + getServerAddress() + "/ajax/get_device_info", + function(data) { + // Process only in the dashboard page. + if (!isDashboardShowing()) { + initializingDevice = false; + return; + } + // Check if there was any error in the request. + if (checkErrorResponse(data, true)) { + // Do not continue with device status. + initializingDevice = false; + return; + } + device.refreshIPs(data[ID_ETHERNET_IP], data[ID_WIFI_IP]); + updateInfoValues(); + } + ).fail(function(response) { + // Stop device initialization. + initializingDevice = false; + // Process only in the dashboard page. + if (!isDashboardShowing()) + return; + // Process error. + processAjaxErrorResponse(response); + }); + } + readDeviceStatus(); +} + // Reads the device status. function readDeviceStatus() { // Execute only in the dashboard page. - if (!isDashboardShowing()) + if (!isDashboardShowing() || device == null) return; // Hide the info popup. showInfoPopup(false); @@ -279,6 +320,13 @@ function processDeviceStatusResponse(response) { initializingDevice = false; return; } + + // Check if IP values are initialized. + if ((response[STREAM_ETHERNET_STATE] == 1 && device.getEthernetIP() == "0.0.0.0") + || (response[STREAM_WIFI_STATE] == 1 && device.getWifiIP() == "0.0.0.0")) { + deviceInitialized = false; + } + // Update the device status values. updateDataPointsValues(response); // Show the help popup if needed. diff --git a/connectcore-demo-example/static/js/devices.js b/connectcore-demo-example/static/js/devices.js index 47d7c0c..534b832 100644 --- a/connectcore-demo-example/static/js/devices.js +++ b/connectcore-demo-example/static/js/devices.js @@ -221,6 +221,11 @@ class ConnectCoreDevice { this.#numSamplesUpload = deviceData[ID_NUM_SAMPLES_UPLOAD]; } + refreshIPs(eth_ip, wifi_ip) { + this.#ethernetIP = eth_ip; + this.#wifiIP = wifi_ip; + } + // Returns the device type. getDeviceType() { return this.#deviceType;