Ajout bouton Get Data (IMSI) sur la page modem 4G
- Sépare le bouton SIM en deux : Get Data (ICCID) et Get Data (IMSI) - Ajout fonction getImsiInfo() avec commande AT+CIMI - Parse la réponse pour extraire le numéro IMSI (15 chiffres) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -97,7 +97,7 @@
|
||||
|
||||
<div class="card-body">
|
||||
<p class="card-text">SIM card information.</p>
|
||||
<button class="btn btn-primary" onclick="getSimInfo('ttyAMA2', 1)">Get Data</button>
|
||||
<button class="btn btn-primary me-1" onclick="getSimInfo('ttyAMA2', 1)">Get Data (ICCID)</button>
|
||||
<div id="loading_ttyAMA2_AT_CCID_" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
||||
<div id="sim_info_alert"></div>
|
||||
<div class="collapse mt-2" id="sim_info_logs">
|
||||
@@ -105,6 +105,15 @@
|
||||
<small><code id="response_ttyAMA2_AT_CCID_"></code></small>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<button class="btn btn-primary me-1" onclick="getImsiInfo('ttyAMA2', 1)">Get Data (IMSI)</button>
|
||||
<div id="loading_ttyAMA2_AT_CIMI" class="spinner-border spinner-border-sm" style="display: none;" role="status"></div>
|
||||
<div id="imsi_info_alert"></div>
|
||||
<div class="collapse mt-2" id="imsi_info_logs">
|
||||
<div class="card card-body bg-light">
|
||||
<small><code id="response_ttyAMA2_AT_CIMI"></code></small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -792,6 +801,79 @@ function getSimInfo(port, timeout) {
|
||||
});
|
||||
}
|
||||
|
||||
function getImsiInfo(port, timeout) {
|
||||
console.log("Getting IMSI from port " + port);
|
||||
|
||||
$("#loading_ttyAMA2_AT_CIMI").show();
|
||||
$("#imsi_info_alert").empty();
|
||||
$("#response_ttyAMA2_AT_CIMI").empty();
|
||||
|
||||
$.ajax({
|
||||
url: 'launcher.php?type=sara&port=' + port + '&command=' + encodeURIComponent('AT+CIMI') + '&timeout=' + timeout,
|
||||
dataType: 'text',
|
||||
method: 'GET',
|
||||
success: function(response) {
|
||||
console.log("IMSI response:", response);
|
||||
$("#loading_ttyAMA2_AT_CIMI").hide();
|
||||
|
||||
// Store raw logs
|
||||
const formattedLogs = response.replace(/\n/g, "<br>");
|
||||
$("#response_ttyAMA2_AT_CIMI").html(formattedLogs);
|
||||
|
||||
// Parse response to extract IMSI (15-digit number)
|
||||
let alertHtml = '';
|
||||
const imsiMatch = response.match(/(\d{15})/);
|
||||
|
||||
if (response.includes('OK') && imsiMatch) {
|
||||
const imsiNumber = imsiMatch[1];
|
||||
alertHtml = `
|
||||
<div class="alert alert-success py-2 mb-0 mt-2 d-flex justify-content-between align-items-center" role="alert">
|
||||
<div>
|
||||
<strong>IMSI read successfully</strong><br>
|
||||
<small>IMSI: ${imsiNumber}</small>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#imsi_info_logs" aria-expanded="false" aria-controls="imsi_info_logs">
|
||||
<small>+</small>
|
||||
</button>
|
||||
</div>`;
|
||||
} else if (response.includes('ERROR') || response.trim() === '' || !response.includes('OK')) {
|
||||
alertHtml = `
|
||||
<div class="alert alert-danger py-2 mb-0 mt-2 d-flex justify-content-between align-items-center" role="alert">
|
||||
<div>
|
||||
<strong>IMSI not available</strong><br>
|
||||
<small>No SIM card or read error</small>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#imsi_info_logs" aria-expanded="false" aria-controls="imsi_info_logs">
|
||||
<small>+</small>
|
||||
</button>
|
||||
</div>`;
|
||||
} else {
|
||||
alertHtml = `
|
||||
<div class="alert alert-warning py-2 mb-0 mt-2 d-flex justify-content-between align-items-center" role="alert">
|
||||
<div>
|
||||
<strong>SIM card detected</strong><br>
|
||||
<small>Unable to read IMSI</small>
|
||||
</div>
|
||||
<button class="btn btn-sm btn-outline-secondary" type="button" data-bs-toggle="collapse" data-bs-target="#imsi_info_logs" aria-expanded="false" aria-controls="imsi_info_logs">
|
||||
<small>+</small>
|
||||
</button>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
$("#imsi_info_alert").html(alertHtml);
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
console.error('AJAX request failed:', status, error);
|
||||
$("#loading_ttyAMA2_AT_CIMI").hide();
|
||||
$("#imsi_info_alert").html(`
|
||||
<div class="alert alert-danger py-2 mb-0 mt-2" role="alert">
|
||||
<strong>Communication error</strong><br>
|
||||
<small>${error}</small>
|
||||
</div>`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Cache for operators data
|
||||
let operatorsData = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user