consolidate status info and prevent multiple ajax calls

This commit is contained in:
Christian Herzog
2019-09-28 10:41:53 +02:00
parent 092ccc8185
commit f36a41e892
3 changed files with 11 additions and 9 deletions

View File

@@ -17,6 +17,7 @@ var enableAPTimer = true;
var enableStatusTimer = true; var enableStatusTimer = true;
var commandHeader = 'squeezelite -b 500:2000 -d all=info '; var commandHeader = 'squeezelite -b 500:2000 -d all=info ';
var pname, ver, otapct; var pname, ver, otapct;
var blockAjax = false;
var apList = null; var apList = null;
var selectedSSID = ""; var selectedSSID = "";
@@ -46,7 +47,7 @@ function stopRefreshAPInterval(){
function startCheckStatusInterval(){ function startCheckStatusInterval(){
StatusIntervalActive = true; StatusIntervalActive = true;
checkStatusInterval = setTimeout(checkStatus, 950); checkStatusInterval = setTimeout(checkStatus, 3000);
} }
function startRefreshAPInterval(){ function startRefreshAPInterval(){
@@ -407,6 +408,8 @@ function refreshAPHTML(data){
function checkStatus(){ function checkStatus(){
RepeatCheckStatusInterval(); RepeatCheckStatusInterval();
if (!enableStatusTimer) return; if (!enableStatusTimer) return;
if (blockAjax) return;
blockAjax = true;
$.getJSON( "/status.json", function( data ) { $.getJSON( "/status.json", function( data ) {
if(data.hasOwnProperty('ssid') && data['ssid'] != ""){ if(data.hasOwnProperty('ssid') && data['ssid'] != ""){
if(data["ssid"] === selectedSSID){ if(data["ssid"] === selectedSSID){
@@ -419,7 +422,7 @@ function checkStatus(){
$("#netmask").text(data["netmask"]); $("#netmask").text(data["netmask"]);
$("#gw").text(data["gw"]); $("#gw").text(data["gw"]);
$("#wifi-status").slideDown( "fast", function() {}); $("#wifi-status").slideDown( "fast", function() {});
$(".footer").html("connected to SSID "+text(data["ssid"])+" with IP "+text(data["ip"])); $("span#foot-wifi").html(", SSID: "+data["ssid"]+", IP: "+data["ip"]);
//unlock the wait screen if needed //unlock the wait screen if needed
$( "#ok-connect" ).prop("disabled",false); $( "#ok-connect" ).prop("disabled",false);
@@ -440,6 +443,7 @@ function checkStatus(){
$("#ip").text('0.0.0.0'); $("#ip").text('0.0.0.0');
$("#netmask").text('0.0.0.0'); $("#netmask").text('0.0.0.0');
$("#gw").text('0.0.0.0'); $("#gw").text('0.0.0.0');
$("span#foot-wifi").html("");
//don't show any connection //don't show any connection
$("#wifi-status").slideUp( "fast", function() {}); $("#wifi-status").slideUp( "fast", function() {});
@@ -465,7 +469,7 @@ function checkStatus(){
$("#netmask").text(data["netmask"]); $("#netmask").text(data["netmask"]);
$("#gw").text(data["gw"]); $("#gw").text(data["gw"]);
$("#wifi-status").slideDown( "fast", function() {}); $("#wifi-status").slideDown( "fast", function() {});
$(".footer").html("connected to SSID "+data["ssid"]+" with IP "+data["ip"]); $("span#foot-wifi").html(", SSID: "+data["ssid"]+", IP: "+data["ip"]);
} }
enableAPTimer = false; enableAPTimer = false;
if (!recovery) enableStatusTimer = false; if (!recovery) enableStatusTimer = false;
@@ -475,22 +479,24 @@ function checkStatus(){
//that's a manual disconnect //that's a manual disconnect
if($("#wifi-status").is(":visible")){ if($("#wifi-status").is(":visible")){
$("#wifi-status").slideUp( "fast", function() {}); $("#wifi-status").slideUp( "fast", function() {});
$("span#foot-wifi").html("");
} }
enableAPTimer = true; enableAPTimer = true;
enableStatusTimer = true; enableStatusTimer = true;
} }
if(data.hasOwnProperty('project_name') && data['project_name'] != ''){ if(data.hasOwnProperty('project_name') && data['project_name'] != ''){
pname = data['project_name']; pname = data['project_name'];
$("#mode").html(pname+" mode running "+ver);
} }
if(data.hasOwnProperty('version') && data['version'] != ''){ if(data.hasOwnProperty('version') && data['version'] != ''){
ver = data['version']; ver = data['version'];
$("span#foot-fw").html("fw: "+ver+", mode: "+pname);
} }
if(data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){ if(data.hasOwnProperty('ota_pct') && data['ota_pct'] != 0){
otapct = data['ota_pct']; otapct = data['ota_pct'];
$('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct); $('.progress-bar').css('width', otapct+'%').attr('aria-valuenow', otapct);
$('.progress-bar').html(otapct+'%'); $('.progress-bar').html(otapct+'%');
} }
blockAjax = false;
}) })
.fail(function() { .fail(function() {
//don't do anything, the server might be down while esp32 recalibrates radio //don't do anything, the server might be down while esp32 recalibrates radio

View File

@@ -303,6 +303,6 @@
</div> </div>
</div> </div>
<footer class="footer"></footer> <footer class="footer"><span id="foot-fw"></span><span id="foot-wifi"></span></footer>
</body> </body>
</html> </html>

View File

@@ -303,10 +303,6 @@ input, textarea {
width: 60%; width: 60%;
} }
#mode {
float: right;
}
.footer { .footer {
position: fixed; position: fixed;
left: 0; left: 0;