diff --git a/html/saraR4.html b/html/saraR4.html index cf9fb0f..5954459 100755 --- a/html/saraR4.html +++ b/html/saraR4.html @@ -118,14 +118,18 @@ -
+

Signal strength

- + -
- +
+
+
+ +
+
@@ -787,6 +791,152 @@ function getNetworkInfo(port, timeout) { }); } +function getSignalInfo(port, timeout) { + console.log("Getting signal info from port " + port); + + $("#loading_ttyAMA2_AT_CSQ").show(); + $("#signal_info_alert").empty(); + $("#response_ttyAMA2_AT_CSQ").empty(); + + $.ajax({ + url: 'launcher.php?type=sara&port=' + port + '&command=' + encodeURIComponent('AT+CSQ') + '&timeout=' + timeout, + dataType: 'text', + method: 'GET', + success: function(response) { + console.log("CSQ response:", response); + $("#loading_ttyAMA2_AT_CSQ").hide(); + + // Store raw logs + const formattedLogs = response.replace(/\n/g, "
"); + $("#response_ttyAMA2_AT_CSQ").html(formattedLogs); + + // Parse response: +CSQ: , + let alertHtml = ''; + const csqMatch = response.match(/\+CSQ:\s*(\d+),(\d+)/); + + if (response.includes('OK') && csqMatch) { + const signalPower = parseInt(csqMatch[1]); + const qual = parseInt(csqMatch[2]); + + // Determine signal quality and color + let signalDesc, signalColor, signalIcon, alertClass; + + if (signalPower === 99) { + signalDesc = 'No signal'; + signalColor = '#333333'; + signalIcon = '⚫'; + alertClass = 'alert-dark'; + } else if (signalPower === 0) { + signalDesc = 'Very poor'; + signalColor = '#dc3545'; + signalIcon = '🔴'; + alertClass = 'alert-danger'; + } else if (signalPower <= 9) { + signalDesc = 'Poor'; + signalColor = '#fd7e14'; + signalIcon = '🟠'; + alertClass = 'alert-warning'; + } else if (signalPower <= 14) { + signalDesc = 'Fair'; + signalColor = '#ffc107'; + signalIcon = '🟡'; + alertClass = 'alert-warning'; + } else if (signalPower <= 19) { + signalDesc = 'Good'; + signalColor = '#20c997'; + signalIcon = '🟢'; + alertClass = 'alert-success'; + } else if (signalPower <= 25) { + signalDesc = 'Very good'; + signalColor = '#198754'; + signalIcon = '🟢'; + alertClass = 'alert-success'; + } else if (signalPower <= 30) { + signalDesc = 'Excellent'; + signalColor = '#0d6efd'; + signalIcon = '🔵'; + alertClass = 'alert-primary'; + } else { + signalDesc = 'Maximum'; + signalColor = '#6f42c1'; + signalIcon = '🟣'; + alertClass = 'alert-primary'; + } + + // Calculate approximate dBm (for RSSI: -113 + 2*signalPower) + let rssiDbm = signalPower !== 99 ? (-113 + 2 * signalPower) + ' dBm' : 'N/A'; + + // Signal bars visualization (1-5 bars based on signal power) + let bars = 0; + if (signalPower !== 99) { + if (signalPower >= 25) bars = 5; + else if (signalPower >= 19) bars = 4; + else if (signalPower >= 14) bars = 3; + else if (signalPower >= 9) bars = 2; + else if (signalPower >= 1) bars = 1; + } + + const barsHtml = ` + + ${[1,2,3,4,5].map(i => + `` + ).join('')} + `; + + alertHtml = ` + `; + } else if (response.includes('ERROR') || response.trim() === '' || !response.includes('OK')) { + alertHtml = ` + `; + } else { + alertHtml = ` + `; + } + + $("#signal_info_alert").html(alertHtml); + }, + error: function(xhr, status, error) { + console.error('AJAX request failed:', status, error); + $("#loading_ttyAMA2_AT_CSQ").hide(); + $("#signal_info_alert").html(` + `); + } + }); +} + function getData_saraR4(port, command, timeout){ console.log("Data from SaraR4"); console.log("Port: " + port );