3
function that takes the data from a url:
const getDadosAsync = () => new Promise((resolve, reject) => {
let url = 'http://' + host + '/dados';
xhttp.onreadystatechange = () => {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var data = xhttp.responseText;
resolve(data);
}
}
xhttp.open("GET", url, true);
xhttp.send();
});
The date value and something like: test,123change,IMPEXPROS,Armento:172.20.1.1,172.20.1.2,172.20.1.3,172.20.1.4,172.20.1.5,172.20.1.6,255.255.255.255.0,192.168.1,192.168.1.140,255.255.255.255.0,192.168.1.121:
and take the data in this function:
const texto1 = async () =>{
let dados = await getDadosAsync();
let arrParams = dados.split(':');
let nomes = arrParams[0].split(',');
let ips = arrParams[1].split(',');
let arrDados = [];
arrDados.push({
ssidAP: nomes[0],
senhaAP: nomes[1],
ssidSTA: nomes[2],
senhaSTA: nomes[3],
ipLocal: ips[0],
ipmodulo1: ips[1],
ipmodulo2: ips[2],
ipmodulo3: ips[3],
ipmodulo4: ips[4],
ipmodulo5: ips[5],
mascaraAP: ips[6],
gatewaySTA: ips[7],
localSTA: ips[8],
mascaraSTA: ips[9],
servidorSTA: ips[10],
});
let a = setSSIDAP();
let b = setSSIDSTA();
if (a == "null" && b == "null"){
return "null";
}
if(b == "null" && a != "null"){
return a + ","+ arrDados.ssidSTA + "," + arrDados.senhaSTA;
}
if(a == "null" && b != "null"){
return arrDados.ssidAP + "," + arrDados.senhaAP + "," + b;
}
if (a != "null" && b != "null"){
return a + b;
}
}
edit1: I receive the data of this function as follows:
const sendConf = async () => {
let users = setUsers();
if (users){
//let url = decodeURI("http://" + host + "/config?a=" + localreles + "&b=" + apwifi + "&c=" + ips +"&dd=null:&d=" + users.usuarios + "&e=" + users.senhas + "&f=" + users.tags + "&g=" + users.horarios);
let url = decodeURI("http://"+host+"/config?a=null:&b="+texto1()+":&c="+texto2()+":&d=null:&e=" + users.usuarios + "&f=" + users.senhas + "&g=" + users.tags + "&h=" + users.horarios);
xhttp.onreadystatechange = () => {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var data = xhttp.responseText;
console.log(url);
alert(url);
}
}
await xhttp.open("GET", url, true);
await xhttp.send();
}
}
and the return of this function text1() is returning [Object Promise], why not the data? I tested call text1(). then() and returned the same thing.
Thanks! It worked out!
– Vitor Pereira