From 0f3cfc59cbca8ea058a6aa53cf9038c5024a1132 Mon Sep 17 00:00:00 2001 From: Kizarm Date: Fri, 5 Jul 2024 19:16:42 +0200 Subject: [PATCH] correct localSettings --- chata/index.html | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/chata/index.html b/chata/index.html index 2b4e947..0739d1c 100644 --- a/chata/index.html +++ b/chata/index.html @@ -54,15 +54,19 @@ var client; function ManagePwd () { const pass = localStorage.getItem('mqtt_password'); - if (!pass) localStorage.setItem('mqtt_password', document.getElementById('pass').value); - else document.getElementById('pass').value = pass; + if (pass) document.getElementById('pass').value = pass; }; + function SetPwd () { + const pass = localStorage.getItem('mqtt_password'); + if (!pass || pass.length === 0) { + localStorage.setItem('mqtt_password', document.getElementById('pass').value); + } + } ManagePwd (); function Connection() { if (!mqtt) { - TextOut.value = 'MQTT not supported !!!\n'; - return; + TextOut.value = 'MQTT not supported !!!\n'; return; } options.password = document.getElementById('pass').value; // console.log (options); @@ -72,15 +76,16 @@ ConnBtn.innerHTML = 'Connect'; Main.btn.disabled = true; Refr.btn.disabled = true; - TextOut.value = "Disconnected\n" + TextOut.value = "Disconnected\n"; } else { - client = mqtt.connect(url, options) + client = mqtt.connect(url, options); client.on('connect', function () { Connected = true; TextOut.value += 'Connected to ' + url + '\n'; ConnBtn.innerHTML = 'Disconnect'; Main.btn.disabled = false; Refr.btn.disabled = false; + SetPwd (); // Subscribe to a topic client.subscribe(InpTops + '#', function (err) { if (!err) {