Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

73
Vistas
reaccionar mostrando 2 mismo resultado

Estoy tratando de enviar una notificación cuando mi sensor alcanza el umbral. pero en lugar de 1 aviso, recibo 2 del mismo aviso.

 const TempGraph = () => { const [data, setData] = useState([]); // sound , temp, humidity , light , motion . const [thresholddata,setThresholdData] = useState([]); var result = []; // var i = 0; //const thresholds = '35'; function addZero(i) { if (i < 10) {i = "0" + i} return i; } useEffect(() => { const interval = setInterval(() => asyncFetch(),5000) //5000ms = 5sec return () => clearInterval(interval) // clear the interval everytime }, []); /* fetch specific sensor type */ const asyncFetch = async() => { await fetch('api') .then((response) => response.json()) .then((json) => setData(json)) .catch((error) => { console.log('fetch data failed', error); }); //fetching threshold data await fetch('api') .then((response) => response.json()) .then((json)=>setThresholdData(json)) .catch((error) => { console.log('fetch threshold data failed',error); }); }; if(data.length != 0){ /* Loop through threshold table to get the same type id */ for(var x =0;x<thresholddata.length;x++){ // console.log(thresholddata[i]) if(thresholddata[x].typeid == data[data.length-1].typeid && thresholddata[x].sensorid == data[data.length-1].sensorid){ result = thresholddata[x]; console.log(result) } } /* notification when the data value is over the threshold */ if(result.upperthreshold < data[data.length-1].value){ openNotificationWithIcon('warning',data[data.length-1].location); } } /* graph here */ }

Usé un bucle for para recorrer todos los datos y asegurarme de que la identificación de ellos sea la misma. y cuando el valor de los sensores supere el umbral, pasará a la notificación. pero la variable de resultado guardó 2 mismo valor.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda