enable/disable timers depending on connection status

This commit is contained in:
Christian Herzog
2019-09-18 19:37:45 +02:00
parent f2dca3e564
commit 37f8ef3203

View File

@@ -1,4 +1,5 @@
var recovery = 0; var recovery = 0;
var enableTimers = true;
var commandHeader = 'squeezelite -b 500:2000 -d all=info '; var commandHeader = 'squeezelite -b 500:2000 -d all=info ';
// First, checks if it isn't implemented yet. // First, checks if it isn't implemented yet.
@@ -194,11 +195,13 @@ $(document).ready(function(){
$("#otadiv").hide(); $("#otadiv").hide();
} }
//first time the page loads: attempt get the connection status and start the wifi scan //first time the page loads: attempt to get the connection status and start the wifi scan
refreshAP(); refreshAP();
getConfig();
//start timers
startCheckStatusInterval(); startCheckStatusInterval();
startRefreshAPInterval(); startRefreshAPInterval();
getConfig();
}); });
function performConnect(conntype){ function performConnect(conntype){
@@ -263,6 +266,7 @@ function rssiToIcon(rssi){
} }
function refreshAP(){ function refreshAP(){
if (!enableTimers) return;
$.getJSON( "/ap.json", function( data ) { $.getJSON( "/ap.json", function( data ) {
if(data.length > 0){ if(data.length > 0){
//sort by signal strength //sort by signal strength
@@ -274,8 +278,6 @@ function refreshAP(){
refreshAPHTML(apList); refreshAPHTML(apList);
} }
}); });
//TODO daduke
// RepeatRefreshAPInterval();
} }
function refreshAPHTML(data){ function refreshAPHTML(data){
@@ -289,6 +291,7 @@ function refreshAPHTML(data){
} }
function checkStatus(){ function checkStatus(){
if (!enableTimers) return;
$.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){
@@ -310,6 +313,8 @@ function checkStatus(){
$( "#connect-success" ).append("<p>Your IP address now is: " + text(data["ip"]) + "</p>"); $( "#connect-success" ).append("<p>Your IP address now is: " + text(data["ip"]) + "</p>");
$( "#connect-success" ).show(); $( "#connect-success" ).show();
$( "#connect-fail" ).hide(); $( "#connect-fail" ).hide();
enableTimers = false;
} }
else if(data["urc"] === 1){ else if(data["urc"] === 1){
//failed attempt //failed attempt
@@ -329,6 +334,8 @@ function checkStatus(){
$( "#loading" ).hide(); $( "#loading" ).hide();
$( "#connect-fail" ).show(); $( "#connect-fail" ).show();
$( "#connect-success" ).hide(); $( "#connect-success" ).hide();
enableTimers = true;
} }
} }
else if(data.hasOwnProperty('urc') && data['urc'] === 0){ else if(data.hasOwnProperty('urc') && data['urc'] === 0){
@@ -341,10 +348,7 @@ function checkStatus(){
$("#gw").text(data["gw"]); $("#gw").text(data["gw"]);
$("#wifi-status").slideDown( "fast", function() {}); $("#wifi-status").slideDown( "fast", function() {});
} }
//TODO daduke enableTimers = false;
console.log("stopping timers..");
stopCheckStatusInterval();
stopRefreshAPInterval
} }
} }
else if(data.hasOwnProperty('urc') && data['urc'] === 2){ else if(data.hasOwnProperty('urc') && data['urc'] === 2){
@@ -352,6 +356,7 @@ stopRefreshAPInterval
if($("#wifi-status").is(":visible")){ if($("#wifi-status").is(":visible")){
$("#wifi-status").slideUp( "fast", function() {}); $("#wifi-status").slideUp( "fast", function() {});
} }
enableTimers = true;
} }
}) })
.fail(function() { .fail(function() {