diff --git a/html/wifi.html b/html/wifi.html index cfd19fd..0325a00 100755 --- a/html/wifi.html +++ b/html/wifi.html @@ -39,7 +39,7 @@ @@ -51,12 +51,12 @@

Connection WIFI

La connexion WIFI n'est pas obligatoire mais elle vous permet d'effectuer des mises à jour et d'activer le contrôle à distance.

- +

Status Loading...

- +
@@ -72,34 +72,13 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + @@ -116,14 +95,8 @@
- - - - - - - - + +
Etat-
Adresse IP-
Etat-
Adresse IP-
@@ -162,12 +135,7 @@ - - - - - - + @@ -196,7 +164,7 @@
- +
@@ -232,24 +200,8 @@ }) .catch(error => console.error(`Error loading ${file}:`, error)); }); - - }); - -function load_ethernet_info() { - $.ajax({ - url: 'launcher.php?type=internet', - dataType: 'json', - method: 'GET', - success: function(response) { - const eth = response.ethernet; - document.getElementById('info-eth-status').textContent = eth.connection || '-'; - document.getElementById('info-eth-ip').textContent = eth.IP || '-'; - } - }); -} - function getSignalBadge(signal) { const val = parseInt(signal, 10); if (isNaN(val)) return ''; @@ -275,7 +227,6 @@ function get_internet(){ const wifi = response.wifi; const eth = response.ethernet; - // WiFi info document.getElementById('info-ssid').textContent = wifi.ssid || '-'; document.getElementById('info-signal').innerHTML = wifi.signal ? getSignalBadge(wifi.signal) : '-'; document.getElementById('info-ip').textContent = wifi.IP || '-'; @@ -284,9 +235,7 @@ function get_internet(){ document.getElementById('info-freq').textContent = wifi.frequency ? wifi.frequency + ' MHz' : '-'; document.getElementById('info-security').textContent = wifi.security || '-'; - // Ethernet info - const ethStatus = eth.connection || '-'; - document.getElementById('info-eth-status').textContent = ethStatus; + document.getElementById('info-eth-status').textContent = eth.connection || '-'; document.getElementById('info-eth-ip').textContent = eth.IP || '-'; document.getElementById('connection-info-loading').style.display = 'none'; @@ -299,81 +248,45 @@ function get_internet(){ }); } +function wifi_connect(SSID, PASS){ + console.log("Connecting to wifi"); + if (typeof PASS === 'undefined') { + var myModal = new bootstrap.Modal(document.getElementById('myModal')); + document.getElementById('myModalLabel').innerHTML = "Enter password for "+SSID; + document.getElementById('myModalBody').innerHTML = ""; + document.getElementById('myModalFooter').innerHTML = ""; + myModal.show(); + } else { + var myModal = bootstrap.Modal.getInstance(document.getElementById('myModal')); + if (myModal) { myModal.hide(); } - function wifi_connect(SSID, PASS){ - console.log("Connecting to wifi"); - console.log(SSID); - console.log(PASS); - if (typeof PASS === 'undefined') { - console.log("Need to add password"); - //open bootstrap modal to ask for password - var myModal = new bootstrap.Modal(document.getElementById('myModal')); - //modifiy modal title - document.getElementById('myModalLabel').innerHTML = "Enter password for "+SSID; - //add input field to modal body - document.getElementById('myModalBody').innerHTML = ""; - //add button to modal footer - document.getElementById('myModalFooter').innerHTML = ""; - myModal.show(); - } else { - console.log("Will try to connect to "+SSID+" with password "+PASS); - console.log("Start PHP script:"); - - // Close modal - var myModal = bootstrap.Modal.getInstance(document.getElementById('myModal')); - if (myModal) { - myModal.hide(); - } - - $.ajax({ - url: 'launcher.php?type=wifi_connect&SSID='+SSID+'&pass='+PASS, - dataType: 'json', // Changed to JSON - method: 'GET', - success: function(response) { - console.log(response); - - // Show connection status message - showConnectionStatus(response); - }, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); - alert('Error: Could not start connection process'); - } - }); - + $.ajax({ + url: 'launcher.php?type=wifi_connect&SSID='+SSID+'&pass='+PASS, + dataType: 'json', + method: 'GET', + success: function(response) { + console.log(response); + showConnectionStatus(response); + }, + error: function(xhr, status, error) { + console.error('AJAX request failed:', status, error); + alert('Error: Could not start connection process'); } - } + }); + } +} - function showConnectionStatus(response) { - // Get user language (default to French) +function showConnectionStatus(response) { const lang = localStorage.getItem('language') || 'fr'; const instructions = response.instructions[lang] || response.instructions['fr']; - // Create overlay with instructions const overlay = document.createElement('div'); overlay.id = 'connection-status-overlay'; - overlay.style.cssText = ` - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - background: rgba(0, 0, 0, 0.9); - z-index: 9999; - display: flex; - align-items: center; - justify-content: center; - color: white; - `; - + overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.9);z-index:9999;display:flex;align-items:center;justify-content:center;color:white;'; overlay.innerHTML = `
-
- Loading... -
- +
Loading...

${instructions.title}

- - - - +
-

- ${lang === 'fr' ? 'Reconnexion à' : 'Reconnecting to'}: - ${response.ssid} -

-

- ${lang === 'fr' ? 'Nom du capteur' : 'Sensor name'}: - ${response.deviceName} -

+

${lang === 'fr' ? 'Reconnexion à' : 'Reconnecting to'}: ${response.ssid}

+

${lang === 'fr' ? 'Nom du capteur' : 'Sensor name'}: ${response.deviceName}

- -
- - ${lang === 'fr' ? 'Cette fenêtre va se fermer automatiquement...' : 'This window will close automatically...'} - -
-
- `; - +
${lang === 'fr' ? 'Cette fenêtre va se fermer automatiquement...' : 'This window will close automatically...'}
+ `; document.body.appendChild(overlay); + setTimeout(() => { const o = document.getElementById('connection-status-overlay'); if (o) o.remove(); }, 30000); +} - // Auto-close after 30 seconds (gives time to read) - setTimeout(() => { - if (document.getElementById('connection-status-overlay')) { - document.getElementById('connection-status-overlay').remove(); - } - }, 30000); - } - - function wifi_forget(){ +function wifi_forget(){ if (!confirm('Oublier le réseau WiFi actuel et passer en mode hotspot ?')) return; - $.ajax({ url: 'launcher.php?type=wifi_forget', dataType: 'json', @@ -432,36 +321,19 @@ function get_internet(){ alert('Error: Could not forget WiFi network'); } }); - } +} - function showForgetStatus(response) { +function showForgetStatus(response) { const lang = localStorage.getItem('language') || 'fr'; const instructions = response.instructions[lang] || response.instructions['fr']; const overlay = document.createElement('div'); overlay.id = 'connection-status-overlay'; - overlay.style.cssText = ` - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - background: rgba(0, 0, 0, 0.9); - z-index: 9999; - display: flex; - align-items: center; - justify-content: center; - color: white; - `; - + overlay.style.cssText = 'position:fixed;top:0;left:0;width:100%;height:100%;background:rgba(0,0,0,0.9);z-index:9999;display:flex;align-items:center;justify-content:center;color:white;'; overlay.innerHTML = `
-
- Loading... -
- +
Loading...

${instructions.title}

- - - - -
-

- ${lang === 'fr' ? 'Hotspot' : 'Hotspot'}: - ${response.deviceName} -

-
-
- `; - + +

Hotspot: ${response.deviceName}

+ `; document.body.appendChild(overlay); + setTimeout(() => { const o = document.getElementById('connection-status-overlay'); if (o) o.remove(); }, 30000); +} - setTimeout(() => { - if (document.getElementById('connection-status-overlay')) { - document.getElementById('connection-status-overlay').remove(); - } - }, 30000); - } - - function wifi_scan(){ +function wifi_scan(){ console.log("Scanning Wifi"); document.getElementById('wifi-scan-empty').innerHTML = '
Scan en cours...'; @@ -524,24 +380,19 @@ function get_internet(){ response.forEach(network => { const row = document.createElement("tr"); - // SSID const ssidCell = document.createElement("td"); - const truncatedSSID = network.SSID.length > 25 ? network.SSID.substring(0, 25) + '...' : network.SSID; - ssidCell.textContent = truncatedSSID; + ssidCell.textContent = network.SSID.length > 25 ? network.SSID.substring(0, 25) + '...' : network.SSID; row.appendChild(ssidCell); - // Signal with badge const signalCell = document.createElement("td"); signalCell.innerHTML = getSignalBadge(network.SIGNAL); row.appendChild(signalCell); - // Security const securityCell = document.createElement("td"); securityCell.textContent = network.SECURITY || '--'; securityCell.classList.add('text-muted'); row.appendChild(securityCell); - // Connect button const buttonCell = document.createElement("td"); buttonCell.classList.add('text-end'); const button = document.createElement("button"); @@ -559,72 +410,75 @@ function get_internet(){ document.getElementById('wifi-scan-empty').innerHTML = 'Erreur lors du scan'; } }); - } +} - - window.onload = function() { - $.ajax({ - url: 'launcher.php?type=get_config_sqlite', - dataType: 'json', - method: 'GET', - success: function(data) { - console.log("Getting SQLite config table (wifi page):"); - console.log(data); + fetch('../config.json') + .then(response => response.json()) + .then(data => { + console.log("Getting config file (onload)"); + const deviceID = data.deviceID.trim().toUpperCase(); + const deviceName = data.deviceName; - // WiFi connection status — toggle cards - const WIFI_statusElement = document.getElementById("wifi-status"); - console.log("WIFI is: " + data.WIFI_status); + function updateSidebarDeviceName(deviceName) { + const elements = document.querySelectorAll('.sideBar_sensorName'); + if (elements.length > 0) { + elements.forEach((element) => { + element.innerText = deviceName; + }); + } + } - if (data.WIFI_status === "connected") { - WIFI_statusElement.textContent = "Connected"; - WIFI_statusElement.className = "badge text-bg-success"; - document.getElementById('btn-forget-wifi').style.display = 'inline-block'; - document.getElementById('card-connection-info').style.display = ''; - document.getElementById('card-hotspot-info').style.display = 'none'; - document.getElementById('card-wifi-scan').style.display = 'none'; - // Auto-load connection details - get_internet(); - } else if (data.WIFI_status === "hotspot") { - WIFI_statusElement.textContent = "Hotspot"; - WIFI_statusElement.className = "badge text-bg-warning"; - document.getElementById('btn-forget-wifi').style.display = 'none'; - document.getElementById('card-connection-info').style.display = 'none'; - document.getElementById('card-hotspot-info').style.display = ''; - document.getElementById('card-wifi-scan').style.display = ''; - // Auto-load cached scan results in hotspot mode - wifi_scan(); - } else { - WIFI_statusElement.textContent = "Unknown"; - WIFI_statusElement.className = "badge text-bg-secondary"; - document.getElementById('btn-forget-wifi').style.display = 'none'; - document.getElementById('card-connection-info').style.display = 'none'; - document.getElementById('card-hotspot-info').style.display = 'none'; - document.getElementById('card-wifi-scan').style.display = ''; - } + if (deviceName) { + updateSidebarDeviceName(deviceName); + setTimeout(() => updateSidebarDeviceName(deviceName), 100); + setTimeout(() => updateSidebarDeviceName(deviceName), 500); + document.title = deviceName; + } - // Always load ethernet info - load_ethernet_info(); - }, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); + const WIFI_statusElement = document.getElementById("wifi-status"); + + if (data.WIFI_status === "connected") { + WIFI_statusElement.textContent = "Connected"; + WIFI_statusElement.className = "badge text-bg-success"; + document.getElementById('btn-forget-wifi').style.display = 'inline-block'; + document.getElementById('card-connection-info').style.display = ''; + document.getElementById('card-hotspot-info').style.display = 'none'; + document.getElementById('card-wifi-scan').style.display = 'none'; + get_internet(); + } else if (data.WIFI_status === "hotspot") { + WIFI_statusElement.textContent = "Hotspot"; + WIFI_statusElement.className = "badge text-bg-warning"; + document.getElementById('btn-forget-wifi').style.display = 'none'; + document.getElementById('card-connection-info').style.display = 'none'; + document.getElementById('card-hotspot-info').style.display = ''; + document.getElementById('card-wifi-scan').style.display = ''; + wifi_scan(); + } else { + WIFI_statusElement.textContent = "Unknown"; + WIFI_statusElement.className = "badge text-bg-secondary"; + document.getElementById('btn-forget-wifi').style.display = 'none'; + document.getElementById('card-connection-info').style.display = 'none'; + document.getElementById('card-hotspot-info').style.display = 'none'; + document.getElementById('card-wifi-scan').style.display = ''; + } + + $.ajax({ + url: 'launcher.php?type=RTC_time', + dataType: 'text', + method: 'GET', + success: function(response) { + const RTC_Element = document.getElementById("RTC_time"); + RTC_Element.textContent = response; + }, + error: function(xhr, status, error) { + console.error('AJAX request failed:', status, error); + } + }); + + }) + .catch(error => console.error('Error loading config.json:', error)); } - }); - - // Load RTC time - $.ajax({ - url: 'launcher.php?type=RTC_time', - dataType: 'text', - method: 'GET', - success: function(response) { - const RTC_Element = document.getElementById("RTC_time"); - if (RTC_Element) RTC_Element.textContent = response; - }, - error: function(xhr, status, error) { - console.error('AJAX request failed:', status, error); - } - }); - }